0&&n.push({type:`text`,value:`
`}),n}function Yo(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function Xo(e,t){let n=Wo(e,t),r=n.one(e,void 0),i=ko(n),a=Array.isArray(r)?{type:`root`,children:r}:r||{type:`root`,children:[]};return i&&(`children`in a,a.children.push({type:`text`,value:`
-`},i)),a}function Zo(e,t){return e&&`run`in e?async function(n,r){let i=Xo(n,{file:r,...t});await e.run(i,r)}:function(n,r){return Xo(n,{file:r,...e||t})}}function Qo(e){if(e)throw e}var $o=n(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});ft.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var rs={basename:is,dirname:as,extname:os,join:ss,sep:`/`};function is(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);us(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function as(e){if(us(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function os(e){us(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function ss(...e){let t=-1,n;for(;++t0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function ls(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function us(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var ds={cwd:fs};function fs(){return`/`}function ps(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function ms(e){if(typeof e==`string`)e=new URL(e);else if(!ps(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return hs(e)}function hs(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n0){let[r,...a]=t,o=n[i][1];es(o)&&es(r)&&(r=(0,Cs.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function Es(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function Ds(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function Os(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function ks(e){if(!es(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function As(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function js(e){return Ms(e)?e:new _s(e)}function Ms(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function Ns(e){return typeof e==`string`||Ps(e)}function Ps(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var Fs=[],Is={allowDangerousHtml:!0},Ls=/^(https?|ircs?|mailto|xmpp)$/i,Rs=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function zs(e){let t=Bs(e),n=Vs(e);return Hs(t.runSync(t.parse(n),n),e)}function Bs(e){let t=e.rehypePlugins||Fs,n=e.remarkPlugins||Fs,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Is}:Is;return Ts().use(Fa).use(n).use(Zo,r).use(t)}function Vs(e){let t=e.children||``,n=new _s;return typeof t==`string`?n.value=t:``+t,n}function Hs(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||Us;for(let e of Rs)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return t.className&&(e={type:`element`,tagName:`div`,properties:{className:t.className},children:e.type===`root`?e.children:[e]}),Vo(e,l),_n(e,{Fragment:z.Fragment,components:i,ignoreInvalidStyle:!0,jsx:z.jsx,jsxs:z.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in Rn)if(Object.hasOwn(Rn,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=Rn[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function Us(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Ls.test(e.slice(0,t))?e:``}$s.peek=Qs;function Ws(){this.buffer()}function Gs(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function Ks(){this.buffer()}function qs(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function Js(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Qn(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Ys(e){this.exit(e)}function Xs(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Qn(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Zs(e){this.exit(e)}function Qs(){return`[`}function $s(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function ec(){return{enter:{gfmFootnoteCallString:Ws,gfmFootnoteCall:Gs,gfmFootnoteDefinitionLabelString:Ks,gfmFootnoteDefinition:qs},exit:{gfmFootnoteCallString:Js,gfmFootnoteCall:Ys,gfmFootnoteDefinitionLabelString:Xs,gfmFootnoteDefinition:Zs}}}ic.peek=ac;function tc(){return{canContainEols:[`delete`],enter:{strikethrough:nc},exit:{strikethrough:rc}}}function nc(e){this.enter({type:`delete`,children:[]},e)}function rc(e){this.exit(e)}function ic(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function ac(){return`~`}function oc(){return{enter:{table:sc,tableData:dc,tableHeader:dc,tableRow:lc},exit:{codeText:fc,table:cc,tableData:uc,tableHeader:uc,tableRow:uc}}}function sc(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[]},e),this.data.inTable=!0}function cc(e){this.exit(e),this.data.inTable=void 0}function lc(e){this.enter({type:`tableRow`,children:[]},e)}function uc(e){this.exit(e)}function dc(e){this.enter({type:`tableCell`,children:[]},e)}function fc(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,pc));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function pc(e,t){return t===`|`?t:e}function mc(){return{exit:{taskListCheckValueChecked:hc,taskListCheckValueUnchecked:hc,paragraph:gc}}}function hc(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function gc(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i999||s===93&&!o||s===null||s===91||Z(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(Qn(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return Z(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function Sc(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||Z(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=Qn(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return Z(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),$(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function Cc(e,t,n){return e.check(wr,t,e.attempt(_c,t,n))}function wc(e){e.exit(`gfmFootnoteDefinition`)}function Tc(e,t,n){let r=this;return $(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function Ec(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=gr(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var Dc=class{constructor(){this.map=[]}add(e,t,n){Oc(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function Oc(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):X(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):Q(t)?$(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||Z(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,Q(t)?$(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return Q(t)?$(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||X(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return Q(t)?$(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||X(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||X(n)?(e.exit(`tableRow`),t(n)):Q(n)?$(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||Z(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function Mc(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new Dc;for(;++nn[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},Fc(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function Pc(e,t,n,r,i){let a=[],o=Fc(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function Fc(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var Ic={name:`tasklistCheck`,tokenize:Rc};function Lc(){return{text:{91:Ic}}}function Rc(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return Z(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return X(r)?t(r):Q(r)?e.check({tokenize:zc},t,n)(r):n(r)}}function zc(e,t,n){return $(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function Bc(){let e=this.data(),t=e.micromarkExtensions||=[],n=e.fromMarkdownExtensions||=[];t.push(vc(),Ec(),Ac(),Lc()),n.push(ec(),tc(),oc(),mc())}var Vc=`fileManager.readmeCollapsed`;function Hc({folderId:e}){let{t}=o(),[n,r]=(0,R.useState)(()=>localStorage.getItem(Vc)===`1`);(0,R.useEffect)(()=>{localStorage.setItem(Vc,n?`1`:`0`)},[n]);let{data:i,isLoading:s,error:c}=l({queryKey:[`folder-readme`,e],queryFn:()=>a.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return s||c||!i?null:n?(0,z.jsxs)(`div`,{className:`mb-2 lg:mb-0 order-first lg:order-none lg:w-10 lg:flex-shrink-0 lg:h-full`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`flex lg:hidden w-full items-center gap-2 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,z.jsx)(Re,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,z.jsx)(st,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`hidden lg:flex h-full w-10 flex-col items-center gap-2 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,z.jsx)(st,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,z.jsxs)(`div`,{className:`mb-4 lg:mb-0 order-first lg:order-none lg:w-80 xl:w-96 lg:flex-shrink-0 lg:h-full flex flex-col bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,z.jsx)(Re,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex-shrink-0`,children:t(`fileManager.readme.truncated`)})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(!0),title:t(`fileManager.readme.hide`),"aria-label":t(`fileManager.readme.hide`),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark/40 transition-colors flex-shrink-0`,children:(0,z.jsx)(ot,{className:`w-4 h-4`})})]}),(0,z.jsx)(`div`,{className:`px-4 py-3 border-t border-bambu-dark-tertiary flex-1 overflow-y-auto max-h-96 lg:max-h-none text-sm text-bambu-gray-light leading-relaxed space-y-2`,children:(0,z.jsx)(zs,{remarkPlugins:[Bc],components:{h1:({children:e})=>(0,z.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,z.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,z.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,z.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,z.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,z.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,z.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,z.jsx)(`code`,{className:`px-1 py-0.5 bg-bambu-dark rounded text-xs font-mono text-bambu-green`,children:e}),pre:({children:e})=>(0,z.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,z.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,z.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,z.jsx)(`div`,{className:`overflow-x-auto`,children:(0,z.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,z.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,z.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,z.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function Uc({open:e,onClose:t,onPickTag:n}){let{t:r}=o(),i=c(),{showToast:s}=v(),[d,f]=(0,R.useState)(!1),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(``),[_,y]=(0,R.useState)(null),{data:b=[],isLoading:x}=l({queryKey:pt,queryFn:a.getLibraryTags,enabled:e}),S=()=>{i.invalidateQueries({queryKey:pt}),i.invalidateQueries({queryKey:[`library-files`]})},C=u({mutationFn:async()=>{let e=h.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return p?a.updateLibraryTag(p.id,e):a.createLibraryTag(e)},onSuccess:()=>{s(r(p?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),f(!1),m(null),g(``),S()},onError:e=>{s(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),w=u({mutationFn:e=>a.deleteLibraryTag(e),onSuccess:()=>{s(r(`fileManager.tags.deleted`),`success`),y(null),S()},onError:e=>{s(e.message||r(`fileManager.tags.deleteFailed`),`error`)}}),T=()=>{m(null),g(``),f(!0)},E=e=>{m(e),g(e.name),f(!0)},D=(0,R.useCallback)(()=>{C.isPending||(f(!1),m(null),g(``))},[C.isPending]);(0,R.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(C.isPending||w.isPending||(d?D():_||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,d,_,C.isPending,w.isPending,D,t]);let O=e=>{e.preventDefault(),C.mutate()};if(!e)return null;let k=`library-tags-modal-title`,A=`library-tag-editor-title`;return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{C.isPending||w.isPending||t()}}),(0,z.jsxs)(`div`,{className:`relative w-full max-w-4xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":k,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`h2`,{id:k,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(xe,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(P,{onClick:T,children:[(0,z.jsx)(Oe,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]})]}),(0,z.jsx)(`div`,{className:`overflow-y-auto`,children:x?(0,z.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,z.jsx)(j,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):b.length===0?(0,z.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,z.jsx)(`thead`,{children:(0,z.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,z.jsx)(`tbody`,{children:b.map(e=>(0,z.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 ${n?`cursor-pointer`:``}`,onClick:()=>{n&&(n(e.id),t())},children:[(0,z.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,z.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,z.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>E(e),title:r(`common.edit`),"aria-label":r(`fileManager.tags.editAria`,{name:e.name}),children:(0,z.jsx)(ue,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>y(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,z.jsx)(de,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),d&&(0,z.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:D}),(0,z.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":A,children:[(0,z.jsx)(`h3`,{id:A,className:`text-lg font-semibold text-white mb-4`,children:r(p?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,z.jsxs)(`form`,{onSubmit:O,children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,z.jsx)(`input`,{id:`library-tag-name`,type:`text`,maxLength:64,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:r(`fileManager.tags.createPlaceholder`),value:h,onChange:e=>g(e.target.value),autoFocus:!0}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:D,children:r(`common.cancel`)}),(0,z.jsxs)(P,{type:`submit`,disabled:C.isPending||!h.trim(),children:[C.isPending&&(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),_&&(0,z.jsx)(ke,{title:r(`fileManager.tags.confirmDelete`,{name:_.name}),message:_.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:_.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:w.isPending,onConfirm:()=>w.mutate(_.id),onCancel:()=>y(null)})]})}function Wc({file:e,canEdit:t,onClose:n}){let{t:r}=o(),{showToast:i}=v(),s=c(),{data:d}=l({queryKey:[`library-file`,e.id],queryFn:()=>a.getLibraryFile(e.id)}),[f,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(``),[g,_]=(0,R.useState)([]),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(null),C=(0,R.useRef)(null),w=(0,R.useRef)(null);(0,R.useEffect)(()=>{!d||w.current===d.id||(w.current=d.id,p(d.notes??``),h(d.external_url??``),_(d.photos??[]))},[d]),(0,R.useEffect)(()=>{if(x!==null)return;let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[x,n]);let T=()=>{s.invalidateQueries({queryKey:[`library-files`]}),s.invalidateQueries({queryKey:[`library-file`,e.id]})},E=u({mutationFn:()=>a.updateLibraryFile(e.id,{notes:f,external_url:m.trim()}),onSuccess:()=>{T(),i(r(`fileManager.details.saved`),`success`),n()},onError:()=>{i(r(`fileManager.details.saveFailed`),`error`)}}),D=!!d&&(f!==(d.notes??``)||m.trim()!==(d.external_url??``)),O=async t=>{let n=t.target.files?.[0];if(n){b(!0);try{_((await a.uploadLibraryFilePhoto(e.id,n)).photos),T()}catch{i(r(`fileManager.details.uploadFailed`),`error`)}finally{b(!1),C.current&&(C.current.value=``)}}},k=async t=>{try{let n=(await a.deleteLibraryFilePhoto(e.id,t)).photos??[];_(n),n.length===0&&S(null),T()}catch{i(r(`fileManager.details.deleteFailed`),`error`)}},A=e=>{e.preventDefault(),!(!t||!D)&&E.mutate()},ee=m.trim(),M=[{label:r(`fileManager.details.size`),value:oe(e.file_size)},{label:r(`fileManager.details.type`),value:e.file_type.toUpperCase()}];if(d?.print_name&&M.push({label:r(`fileManager.details.printName`),value:d.print_name}),d?.print_time_seconds&&M.push({label:r(`fileManager.details.printTime`),value:ce(d.print_time_seconds)}),d?.filament_used_grams&&M.push({label:r(`fileManager.details.filament`),value:`${d.filament_used_grams.toFixed(1)} g`}),d?.sliced_for_model&&M.push({label:r(`fileManager.details.slicedFor`),value:d.sliced_for_model}),d?.source_url){let e=/^https?:\/\//i.test(d.source_url);M.push({label:r(`fileManager.details.source`),value:e?(0,z.jsxs)(`a`,{href:d.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1 min-w-0`,children:[(0,z.jsx)(`span`,{className:`truncate`,children:d.source_url}),(0,z.jsx)(fe,{className:`w-3 h-3 flex-shrink-0`})]}):(0,z.jsx)(`span`,{className:`truncate`,children:d.source_url})})}return M.push({label:r(`fileManager.details.created`),value:se(e.created_at)}),M.push({label:r(`fileManager.details.modified`),value:se(e.fs_modified_at??d?.updated_at??e.created_at)}),(0,z.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.title`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:e.filename,children:e.filename}),(0,z.jsx)(`span`,{className:`flex-shrink-0 text-xs px-1.5 py-0.5 rounded font-medium bg-bambu-dark-tertiary text-bambu-gray`,children:e.file_type.toUpperCase()})]})]}),(0,z.jsx)(`button`,{type:`button`,onClick:n,className:`text-bambu-gray hover:text-white transition-colors flex-shrink-0`,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`form`,{onSubmit:A,className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,z.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-sm`,children:M.map(e=>(0,z.jsxs)(`div`,{className:`contents`,children:[(0,z.jsx)(`dt`,{className:`text-bambu-gray whitespace-nowrap`,children:e.label}),(0,z.jsx)(`dd`,{className:`text-white min-w-0 truncate`,children:e.value})]},e.label))}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(ne,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.notes`)]}),(0,z.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),rows:3,disabled:!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none disabled:opacity-60`,placeholder:r(`fileManager.details.notesPlaceholder`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(Pe,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.externalLink`)]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`input`,{type:`url`,value:m,onChange:e=>h(e.target.value),disabled:!t,className:`flex-1 min-w-0 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-60`,placeholder:r(`fileManager.details.externalLinkPlaceholder`)}),ee&&(0,z.jsx)(`a`,{href:ee,target:`_blank`,rel:`noopener noreferrer`,className:`p-2 rounded-lg text-bambu-gray hover:text-bambu-green hover:bg-bambu-dark transition-colors`,title:r(`fileManager.details.openLink`),"aria-label":r(`fileManager.details.openLink`),children:(0,z.jsx)(fe,{className:`w-4 h-4`})})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(be,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.photos`)]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[g.map((n,i)=>(0,z.jsxs)(`div`,{className:`relative group`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>S(i),className:`block w-20 h-20 rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,z.jsx)(`img`,{src:a.getLibraryFilePhotoUrl(e.id,n),alt:r(`fileManager.details.photos`),className:`w-full h-full object-cover`})}),t&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>k(n),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:r(`fileManager.details.deletePhoto`),"aria-label":r(`fileManager.details.deletePhoto`),children:(0,z.jsx)(de,{className:`w-3 h-3 text-white`})})]},n)),t&&(0,z.jsxs)(`label`,{className:`w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors`,title:r(`fileManager.details.addPhoto`),children:[(0,z.jsx)(`input`,{ref:C,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:O,className:`hidden`,disabled:y,"aria-label":r(`fileManager.details.addPhoto`)}),y?(0,z.jsx)(j,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,z.jsx)(Oe,{className:`w-6 h-6 text-bambu-gray`})]}),g.length===0&&!t&&(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.noPhotos`)})]})]}),(0,z.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,className:`flex-1`,children:r(`common.close`)}),t&&(0,z.jsxs)(P,{type:`submit`,variant:`primary`,className:`flex-1`,disabled:!D||E.isPending,children:[E.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(Te,{className:`w-4 h-4`}),r(`fileManager.details.save`)]})]})]})]}),x!==null&&g.length>0&&(0,z.jsx)(We,{archiveName:e.filename,photos:g,initialIndex:x,getPhotoUrl:t=>a.getLibraryFilePhotoUrl(e.id,t),onClose:()=>S(null),onDelete:t?k:void 0})]})}var Gc=90;function Kc({onClose:e}){let{t}=o(),n=c(),{showToast:r}=v(),[i,s]=(0,R.useState)(Gc),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(i);(0,R.useEffect)(()=>{let e=window.setTimeout(()=>m(i),300);return()=>window.clearTimeout(e)},[i]);let h=l({queryKey:[`library-purge-preview`,p,d],queryFn:()=>a.previewLibraryPurge(p,d),enabled:p>=1}),g=u({mutationFn:()=>a.executeLibraryPurge(i,d),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,R.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!g.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,g.isPending]);let _=h.data,y=_?.count??0,b=_?.total_bytes??0,x=y>0&&!g.isPending;return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,z.jsx)(de,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,z.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:g.isPending,children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>s(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,z.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,z.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,z.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,z.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,z.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:h.isLoading||h.isFetching?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):h.isError?(0,z.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:h.error?.message??t(`libraryPurge.previewFailed`)}):(0,z.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,z.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:y,size:oe(b)})}),_?.sample_filenames&&_.sample_filenames.length>0&&(0,z.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[_.sample_filenames.map(e=>(0,z.jsx)(`li`,{className:`truncate`,children:e},e)),y>_.sample_filenames.length&&(0,z.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:y-_.sample_filenames.length})})]})]})}),(0,z.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,z.jsx)(re,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,z.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,z.jsx)(P,{variant:`secondary`,onClick:e,disabled:g.isPending,children:t(`common.cancel`)}),(0,z.jsx)(P,{variant:`danger`,disabled:!x,onClick:()=>g.mutate(),children:g.isPending?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(j,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:y})})]})]})})}var qc=(0,R.lazy)(()=>I(()=>import(`./PdfPreviewModal-HVSkaROI.js`).then(e=>({default:e.PdfPreviewModal})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]))),Jc=(0,R.lazy)(()=>I(()=>import(`./SpreadsheetPreviewModal-sKEz1Isz.js`).then(e=>({default:e.SpreadsheetPreviewModal})),__vite__mapDeps([29,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,30,26,27,28]))),Yc=(0,R.lazy)(()=>I(()=>import(`./ImagePreviewModal-CTLU6Jnd.js`).then(e=>({default:e.ImagePreviewModal})),__vite__mapDeps([31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28])));function Xc(e){return e===`csv`||e===`xlsx`||e===`ods`}function Zc(e){return e===`step`||e===`stp`}var Qc=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`tiff`,`tif`]),$c=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`]);function el(e){return Qc.has(e.toLowerCase())}function tl(e){return $c.has(e.toLowerCase())}function nl({fileType:e,className:t}){return(0,z.jsx)(e===`pdf`?Re:Xc(e)?C:el(e)?Fe:S,{className:t})}function rl(e){return{results:e,files:e.flatMap(e=>e.data??[])}}function il(e){let t=e.file_type;return Ze(e)||t===`3mf`||t===`stl`||Zc(t)||t===`pdf`||Xc(t)||tl(t)}var al={onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation()};function ol(e){return Ze(e)||e.file_type===`3mf`||e.file_type===`stl`||Zc(e.file_type)}function sl(e){return e===`pdf`?(0,z.jsx)(Re,{className:`w-4 h-4`}):Xc(e)?(0,z.jsx)(C,{className:`w-4 h-4`}):(0,z.jsx)(Fe,{className:`w-4 h-4`})}function cl(e){return e===`stl`||e===`pdf`}function ll(e){return e===`3mf`?`bg-bambu-green/20 text-bambu-green`:e===`gcode`||e===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:e===`stl`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`:Zc(e)?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:e===`pdf`?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:Xc(e)?`bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400`:`bg-bambu-gray/20 text-bambu-gray`}function ul(e,t){let n=[...e],r=t.query?.trim().toLowerCase();r&&(n=n.filter(e=>e.filename.toLowerCase().includes(r)||e.print_name&&e.print_name.toLowerCase().includes(r))),t.filterType!==`all`&&(n=n.filter(e=>e.file_type===t.filterType));let i=t.filterUsername.trim().toLowerCase();return i&&(n=n.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(i))),n.sort((e,n)=>{let r=0;switch(t.sortField){case`name`:r=(e.print_name||e.filename).localeCompare(n.print_name||n.filename);break;case`date`:r=(le(e.fs_modified_at??e.created_at)?.getTime()??0)-(le(n.fs_modified_at??n.created_at)?.getTime()??0);break;case`size`:r=e.file_size-n.file_size;break;case`type`:r=e.file_type.localeCompare(n.file_type);break;case`prints`:r=e.print_count-n.print_count;break}return t.sortDirection===`asc`?r:-r}),n}var dl=e=>e?`grid-cols-[24px_minmax(240px,1fr)_120px_100px_100px_100px_minmax(96px,200px)_220px]`:`grid-cols-[24px_minmax(240px,1fr)_100px_100px_100px_minmax(96px,200px)_220px]`,fl=`min-w-min`;function pl({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,R.useState)(``);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,z.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,z.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!a.trim()||r,children:r?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function ml({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,R.useState)(``),[o,s]=(0,R.useState)(``),[c,l]=(0,R.useState)(!0),[u,d]=(0,R.useState)(!1);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(it,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,z.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,z.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,z.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var hl=`<>:"/\\|?*`;function gl(e){for(let t of e)if(hl.includes(t)||t.charCodeAt(0)<32)return t;return null}function _l({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,R.useState)(s),u=e===`file`?gl(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,z.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,z.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,z.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,z.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,z.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function vl({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,R.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t,canWrite:r.can_write!==!1}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0,canWrite:!0},...l(e)];return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,z.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n||!e.canWrite,title:e.canWrite?void 0:o(`fileManager.folderNotWritable`),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n||!e.canWrite?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,z.jsx)(Ie,{className:`w-4 h-4`}),e.name,e.id===n&&(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,z.jsx)(P,{onClick:()=>i(s),disabled:a,children:a?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function yl({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[o,s]=(0,R.useState)(`project`),[c,u]=(0,R.useState)(e.project_id||e.archive_id||null);(0,R.useState)(()=>{e.archive_id&&s(`archive`)});let{data:d}=l({queryKey:[`projects`],queryFn:()=>a.getProjects(),select:t=>F([...t].sort((e,t)=>e.name.localeCompare(t.name)),e.project_id)}),{data:f}=l({queryKey:[`archives-for-link`],queryFn:()=>a.getArchives(void 0,void 0,100)}),p=()=>{n(o===`project`?{project_id:c,archive_id:0}:{project_id:0,archive_id:c})},h=()=>{n({project_id:0,archive_id:0})},g=e.project_id||e.archive_id;return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(A,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,z.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,z.jsx)(ae,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(`button`,{onClick:()=>{s(`project`),u(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${o===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(m,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,z.jsxs)(`button`,{onClick:()=>{s(`archive`),u(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${o===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(he,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,z.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:o===`project`?d&&d.length>0?d.map(e=>(0,z.jsxs)(`button`,{onClick:()=>u(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${c===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,z.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):f&&f.length>0?f.map(e=>(0,z.jsxs)(`button`,{onClick:()=>u(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${c===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,z.jsx)(S,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,z.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[g&&(0,z.jsxs)(P,{variant:`danger`,onClick:h,disabled:r,children:[(0,z.jsx)(ie,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,z.jsxs)(`div`,{className:`flex gap-2 ${g?``:`ml-auto`}`,children:[(0,z.jsx)(P,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,z.jsx)(P,{onClick:p,disabled:!c||r,children:r?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function bl({folder:e,onDelete:t,onLink:n,onRename:r,onToggleShared:i,hasPermission:a,revealOnHover:o=!1,tabIndex:s,t:c}){let[l,u]=(0,R.useState)(null),d=(0,R.useRef)(null),f=(0,R.useRef)(null),p=()=>{u(null),d.current?.contains(document.activeElement)&&f.current?.focus()},m=e.children.length>0,h=e.project_id||e.archive_id,g=e.is_external,_=e.can_delete??(a(`library:delete_all`)||a(`library:delete_own`)&&e.file_count===0&&!m&&!g&&!h),v=_?void 0:a(`library:delete_own`)&&!g&&!h?c(`fileManager.onlyOwnFoldersDeletable`):c(`fileManager.noPermissionDeleteFolder`),y=e.can_rename??a(`library:update_all`),b=a(`library:update_all`),S=[{label:c(`common.rename`),icon:(0,z.jsx)(ue,{className:`w-3.5 h-3.5`}),onClick:()=>r(e),disabled:!y,title:y?void 0:c(`fileManager.noPermissionRenameFolder`)},{label:c(h?`fileManager.changeLink`:`fileManager.linkTo`),icon:(0,z.jsx)(A,{className:`w-3.5 h-3.5`}),onClick:()=>n(e),disabled:!b,title:b?void 0:c(`fileManager.noPermissionLinkFolder`)},...i&&b?[{label:e.shared?c(`fileManager.unshareFolder`):c(`fileManager.shareFolder`),icon:(0,z.jsx)(pe,{className:`w-3.5 h-3.5`}),onClick:()=>i(e),title:c(`fileManager.shareFolderHint`)}]:[],{label:c(`common.delete`),icon:(0,z.jsx)(de,{className:`w-3.5 h-3.5`}),onClick:()=>t(e.id),danger:!0,disabled:!_,title:v}];return(0,z.jsxs)(`div`,{ref:d,className:`relative flex-shrink-0 flex items-center transition-opacity ${o&&!l?`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`:``}`,"data-folder-actions":!0,onClick:e=>e.stopPropagation(),onKeyDown:e=>{l&&(e.key===`ArrowUp`||e.key===`ArrowDown`)&&p()},children:[(0,z.jsx)(`button`,{ref:f,type:`button`,tabIndex:s,onClick:e=>{if(l){p();return}let t=e.currentTarget.getBoundingClientRect();u({x:t.left,y:t.bottom+4})},className:`p-1 rounded hover:bg-bambu-dark-tertiary`,title:c(`common.actions`),children:(0,z.jsx)(x,{className:`w-3.5 h-3.5 text-bambu-gray`})}),l&&(0,z.jsx)(T,{x:l.x,y:l.y,items:S,onClose:p,anchorRef:f})]})}function xl({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,onToggleShared:o,depth:s=0,wrapNames:c=!1,defaultExpanded:l=!0,showModified:u=!1,hasPermission:d,t:f}){let[p,h]=(0,R.useState)(l),g=e.children.length>0,_=e.project_id||e.archive_id,v=e.is_external;return(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+s*12}px`},onClick:()=>n(e.id),children:[g?(0,z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h(!p)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,z.jsx)(_e,{className:`w-3.5 h-3.5 transition-transform ${p?`rotate-90`:``}`})}):(0,z.jsx)(`div`,{className:`w-4.5`}),v?(0,z.jsx)(it,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,z.jsx)(Ie,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`span`,{className:`block text-sm ${c?`break-all`:`truncate`}`,title:e.name,children:e.name}),u&&e.latest_activity_at&&(0,z.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:f(`fileManager.lastActivity`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:se(e.latest_activity_at)})]})]}),_&&(0,z.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,z.jsx)(A,{className:`w-3 h-3`}),e.project_name?(0,z.jsx)(m,{className:`w-3 h-3`}):(0,z.jsx)(he,{className:`w-3 h-3`})]}),e.shared&&(0,z.jsx)(`span`,{title:f(`fileManager.sharedFolder`),children:(0,z.jsx)(pe,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})}),v&&e.external_readonly&&(0,z.jsx)(`span`,{title:f(`fileManager.readOnly`),children:(0,z.jsx)(M,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,z.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!_&&!v&&(0,z.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:f(`fileManager.linkToProjectOrArchive`),children:(0,z.jsx)(A,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,z.jsx)(bl,{folder:e,onDelete:r,onLink:i,onRename:a,onToggleShared:o,hasPermission:d,revealOnHover:!c,t:f})]}),g&&p&&(0,z.jsx)(`div`,{children:e.children.map(e=>(0,z.jsx)(xl,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,onToggleShared:o,depth:s+1,wrapNames:c,defaultExpanded:l,showModified:u,hasPermission:d,t:f},e.id))})]})}function Sl({file:e,isSelected:t,onSelect:n,onDelete:r,onDownload:i,onPrint:o,onSlice:s,onOpenInSlicer:c,onRunPipeline:l,useSlicerApi:u,desktopSlicer:d,canSlice:f,onPreview:m,onRename:h,onDetails:g,onGenerateThumbnail:v,onTagClick:b,thumbnailVersion:S,hasPermission:C,canModify:w,authEnabled:E,showModified:D,t:O}){let[k,A]=(0,R.useState)(null),ee=C(`library:read`),j=w(`library`,`update`,e.created_by_id),M=w(`library`,`delete`,e.created_by_id),N=[];if(o&&Ze(e)&&N.push({label:O(`common.print`),icon:(0,z.jsx)(me,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>o(e),disabled:!C(`queue:create`),title:C(`queue:create`)?void 0:O(`fileManager.noPermissionAddToQueue`)}),Qe(e,!!u,d)&&(u?s:c)&&N.push({label:O(`slice.action`),icon:u?(0,z.jsx)(y,{className:`w-4 h-4`}):(0,z.jsx)(fe,{className:`w-4 h-4`}),onClick:()=>{u?s?.(e):c?.(e)},disabled:!f,title:f?void 0:O(u?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`)}),l&&u&&Qe(e,!0,d)&&N.push({label:O(`library.runWithPipeline.actionLabel`),icon:(0,z.jsx)(te,{className:`w-4 h-4`}),onClick:()=>l(e),disabled:!C(`pipelines:run`),title:C(`pipelines:run`)?void 0:O(`library.runWithPipeline.noPermission`)}),m&&il(e)){let t=ol(e);N.push({label:O(t?`fileManager.preview3d`:`fileManager.preview.open`),icon:t?(0,z.jsx)(p,{className:`w-4 h-4`}):sl(e.file_type),onClick:()=>m(e),disabled:!ee,title:ee?void 0:O(`fileManager.noPermissionPreview`)})}return N.push({label:O(`common.download`),icon:(0,z.jsx)(Le,{className:`w-4 h-4`}),onClick:()=>i(e.id),disabled:!C(`library:read`),title:C(`library:read`)?void 0:O(`fileManager.noPermissionDownload`)}),h&&N.push({label:O(`common.rename`),icon:(0,z.jsx)(ue,{className:`w-4 h-4`}),onClick:()=>h(e),disabled:!j,title:j?void 0:O(`fileManager.noPermissionRenameFile`)}),g&&N.push({label:O(`fileManager.details.title`),icon:(0,z.jsx)(_,{className:`w-4 h-4`}),onClick:()=>g(e),disabled:!ee,title:ee?void 0:O(`fileManager.noPermissionPreview`)}),e.external_url&&N.push({label:O(`fileManager.details.openLink`),icon:(0,z.jsx)(Me,{className:`w-4 h-4`}),onClick:()=>window.open(e.external_url,`_blank`,`noopener,noreferrer`)}),v&&cl(e.file_type)&&N.push({label:O(`fileManager.generateThumbnail`),icon:(0,z.jsx)(Fe,{className:`w-4 h-4`}),onClick:()=>v(e),disabled:!j,title:j?void 0:O(`fileManager.noPermissionGenerateThumbnail`)}),N.push({label:O(`common.delete`),icon:(0,z.jsx)(de,{className:`w-4 h-4`}),onClick:()=>r(e.id),danger:!0,disabled:!M,title:M?void 0:O(`fileManager.noPermissionDeleteFile`)}),(0,z.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>n(e.id),onDoubleClick:()=>m?.(e),children:[(0,z.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden rounded-t-lg`,children:[e.thumbnail_path?(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(e.id)}${S?(a.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${S}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,z.jsx)(nl,{fileType:e.file_type,className:`w-12 h-12 text-bambu-gray/30`}),(0,z.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:Zc(e.file_type)?`bg-amber-500/90 text-white`:e.file_type===`pdf`?`bg-red-500/90 text-white`:Xc(e.file_type)?`bg-teal-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,z.jsxs)(`div`,{className:`p-3`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{children:oe(e.file_size)}),e.print_time_seconds&&(0,z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(ve,{className:`w-3 h-3`}),ce(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,z.jsx)(me,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,z.jsx)(je,{className:`w-3 h-3`}),O(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,z.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:O(`fileManager.printedCount`,{count:e.print_count})}),(e.external_url||e.has_notes||(e.photo_count??0)>0)&&(0,z.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-xs text-bambu-gray`,...al,children:[e.external_url&&(0,z.jsx)(`a`,{href:e.external_url,target:`_blank`,rel:`noopener noreferrer`,className:`p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.openLink`),"aria-label":O(`fileManager.details.openLink`),children:(0,z.jsx)(Me,{className:`w-3.5 h-3.5`})}),e.has_notes&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>g?.(e),className:`p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.hasNotes`),"aria-label":O(`fileManager.details.hasNotes`),children:(0,z.jsx)(ne,{className:`w-3.5 h-3.5`})}),(e.photo_count??0)>0&&(0,z.jsxs)(`button`,{type:`button`,onClick:()=>g?.(e),className:`flex items-center gap-0.5 p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.photoCount`,{count:e.photo_count}),"aria-label":O(`fileManager.details.photoCount`,{count:e.photo_count}),children:[(0,z.jsx)(be,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.photo_count})]})]}),E&&e.created_by_username&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,z.jsx)(ye,{className:`w-3 h-3`}),e.created_by_username]}),D&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:O(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3`}),se(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,...al,children:e.tags.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>b?.(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,z.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`,...al,children:[(0,z.jsx)(`button`,{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();A({x:t.left,y:t.bottom+4})},className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,z.jsx)(x,{className:`w-4 h-4 text-bambu-gray`})}),k&&(0,z.jsx)(T,{x:k.x,y:k.y,items:N,onClose:()=>A(null)})]}),(0,z.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:t&&(0,z.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function Cl({file:e,onPrint:t,onSlice:n,onOpenInSlicer:r,onRunPipeline:i,useSlicerApi:a,desktopSlicer:o,canSlice:s,onPreview:c,onDetails:l,onDownload:u,onRename:d,onGenerateThumbnail:f,thumbnailPending:m,onDelete:h,hasPermission:g,canModify:v,tabIndex:b,t:x}){let S=v(`library`,`update`,e.created_by_id),C=v(`library`,`delete`,e.created_by_id);return(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,"data-file-actions":!0,...al,children:[Ze(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`queue:create`)&&t(e),className:`p-1.5 rounded transition-colors ${g(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`queue:create`)?x(`common.print`):x(`fileManager.noPermissionAddToQueue`),disabled:!g(`queue:create`),children:(0,z.jsx)(me,{className:`w-4 h-4`})}),Qe(e,a,o)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>{s&&(a?n:r)(e)},className:`p-1.5 rounded transition-colors ${s?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(s?`slice.action`:a?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`),disabled:!s,children:a?(0,z.jsx)(y,{className:`w-4 h-4`}):(0,z.jsx)(fe,{className:`w-4 h-4`})}),a&&Qe(e,!0,o)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`pipelines:run`)&&i(e),className:`p-1.5 rounded transition-colors ${g(`pipelines:run`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`pipelines:run`)?x(`library.runWithPipeline.actionLabel`):x(`library.runWithPipeline.noPermission`),disabled:!g(`pipelines:run`),children:(0,z.jsx)(te,{className:`w-4 h-4`})}),ol(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&c(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.preview3d`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:(0,z.jsx)(p,{className:`w-4 h-4`})}),!ol(e)&&il(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&c(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.preview.open`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:sl(e.file_type)}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&u(e.id),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`common.download`):x(`fileManager.noPermissionDownload`),disabled:!g(`library:read`),children:(0,z.jsx)(Le,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&l(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.details.title`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:(0,z.jsx)(_,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>S&&d(e),className:`p-1.5 rounded transition-colors ${S?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(S?`common.rename`:`fileManager.noPermissionRenameFile`),disabled:!S,children:(0,z.jsx)(ue,{className:`w-4 h-4`})}),cl(e.file_type)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>S&&f(e),className:`p-1.5 rounded transition-colors ${S?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(S?`fileManager.generateThumbnail`:`fileManager.noPermissionGenerateThumbnail`),disabled:m||!S,children:(0,z.jsx)(Fe,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>C&&h(e.id),className:`p-1.5 rounded transition-colors ${C?`hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(C?`common.delete`:`fileManager.noPermissionDeleteFile`),disabled:!C,children:(0,z.jsx)(de,{className:`w-4 h-4`})})]})}function wl({file:e,isSelected:t,isFocused:n,showModified:r,thumbnailVersion:i,onSelect:o,onOpen:s,actionProps:c,t:l}){let u=a.getLibraryFileThumbnailUrl(e.id);return(0,z.jsxs)(`div`,{"data-file-id":e.id,onClick:()=>o(e),onDoubleClick:()=>s(e),className:`group flex items-center gap-3 px-3 py-2 cursor-pointer transition-colors ${t?`bg-bambu-green/10`:`hover:bg-bambu-dark`} ${n?`ring-1 ring-inset ring-bambu-green/60`:``}`,title:e.print_name||e.filename,children:[(0,z.jsx)(`div`,{className:`w-4 h-4 rounded border-2 flex-shrink-0 flex items-center justify-center ${t?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:t&&(0,z.jsx)(`div`,{className:`w-1.5 h-1.5 bg-white rounded-sm`})}),(0,z.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,z.jsx)(`img`,{src:`${u}${i?(u.includes(`?`)?`&`:`?`)+`v=${i}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,z.jsx)(nl,{fileType:e.file_type,className:`w-5 h-5 text-bambu-gray/50`})}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`div`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{className:`px-1.5 py-px rounded font-medium ${ll(e.file_type)}`,children:e.file_type.toUpperCase()}),(0,z.jsx)(`span`,{children:oe(e.file_size)}),e.print_count>0&&(0,z.jsxs)(`span`,{children:[e.print_count,`x`]}),r&&(0,z.jsxs)(`span`,{className:`flex items-center gap-1 truncate`,title:l(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),se(e.fs_modified_at??e.created_at)]})]})]}),(0,z.jsx)(`div`,{className:`flex-shrink-0 transition-opacity ${n||t?``:`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:(0,z.jsx)(Cl,{file:e,...c,tabIndex:n?0:-1})})]})}function Tl(){let{t:e}=o(),t=c(),{showToast:n}=v(),{hasPermission:r,hasAnyPermission:i,canModify:s,authEnabled:f}=ze(),[p]=De(),m=Ee(),h=p.get(`folder`),[g,_]=(0,R.useState)(h?parseInt(h,10):null),[y,x]=(0,R.useState)(`internal`),[C,T]=(0,R.useState)([]),[te,ie]=(0,R.useState)(!1),[ce,le]=(0,R.useState)(!1),[ue,fe]=(0,R.useState)(!1),[F,I]=(0,R.useState)(!1),[he,ve]=(0,R.useState)([]),[Te,Pe]=(0,R.useState)(!1),[Le,Re]=(0,R.useState)(!1),[Be,Ve]=(0,R.useState)(!1),[We,qe]=(0,R.useState)([]),[Je,Ye]=(0,R.useState)(null),[ot,st]=(0,R.useState)(null),[ct,ut]=(0,R.useState)(null),[dt,pt]=(0,R.useState)(null),[ht,gt]=(0,R.useState)(!1),[_t,vt]=(0,R.useState)(null),[yt,bt]=(0,R.useState)(null),[xt,St]=(0,R.useState)(null),[Ct,wt]=(0,R.useState)({}),[Tt,B]=(0,R.useState)(null),[Et,Dt]=(0,R.useState)(null),[V,H]=(0,R.useState)(null),[Ot,U]=(0,R.useState)(null),[W,kt]=(0,R.useState)(null),[G,At]=(0,R.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),jt=(0,R.useRef)(null),[K,Mt]=(0,R.useState)(null),[Nt,Pt]=(0,R.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[Ft,It]=(0,R.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[Lt,Rt]=(0,R.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[zt,Bt]=(0,R.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[Vt,Ht]=(0,R.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[Ut,Wt]=(0,R.useState)(!1),Gt=(0,R.useRef)(null);(0,R.useEffect)(()=>{if(!Ut)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Gt.current)return;let t=Gt.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;Ht(Math.min(500,Math.max(200,n)))},t=()=>{Wt(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(Vt))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[Ut,Vt]);let[Kt,qt]=(0,R.useState)(``),[Jt,Yt]=(0,R.useState)(`all`),[Xt,Zt]=(0,R.useState)(``),[Qt,$t]=(0,R.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[en,tn]=(0,R.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[nn,rn]=(0,R.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`);(0,R.useEffect)(()=>{let e=p.get(`folder`);e&&_(parseInt(e,10))},[p]);let{data:an}=l({queryKey:[`settings`],queryFn:()=>a.getSettings()}),on=Ke(an?.open_in_slicer,an?.preferred_slicer),sn=(0,R.useCallback)(async t=>{try{let{token:e}=await a.createLibrarySlicerToken(t.id),n=a.getLibrarySlicerDownloadUrl(t.id,e,t.filename);Ge(`${window.location.origin}${n}`,on)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=a.getLibraryFileDownloadUrl(t.id);Ge(`${window.location.origin}${r}`,on)}},[on,n,e]),cn=(0,R.useCallback)(()=>an?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[an?.use_slicer_api,r,i]),{data:ln,isLoading:un}=l({queryKey:[`library-folders`],queryFn:()=>a.getLibraryFolders()}),q=(0,R.useMemo)(()=>{if(!ln)return ln;let e=t=>[...t].sort((e,t)=>{let n=0;if(Lt===`name`)n=e.name.localeCompare(t.name);else{let r=e.latest_activity_at?new Date(e.latest_activity_at).getTime():null,i=t.latest_activity_at?new Date(t.latest_activity_at).getTime():null;if(r===null&&i===null)n=e.name.localeCompare(t.name);else if(r===null)return 1;else if(i===null)return-1;else n=r-i}return zt===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(ln)},[ln,Lt,zt]),{data:dn}=l({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await a.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),fn=g!==null&&Kt.trim().length>0,pn=(0,R.useMemo)(()=>[...We].sort((e,t)=>e-t),[We]),{data:mn=[]}=l({queryKey:[`library-tags`],queryFn:a.getLibraryTags}),hn=(0,R.useMemo)(()=>{let e=new Map;for(let t of mn)e.set(t.id,t.name);return e},[mn]);(0,R.useEffect)(()=>{mn.length!==0&&qe(e=>{let t=e.filter(e=>hn.has(e));return t.length===e.length?e:t})},[mn.length,hn]);let gn=(0,R.useCallback)(e=>{qe(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),_n=Kt.trim().length>0||We.length>0,vn=G===`columns`&&g===null&&!_n,{data:yn,isLoading:bn}=l({queryKey:[`library-files`,g,y,fn,pn,vn],queryFn:()=>a.getLibraryFiles(g,vn,void 0,g===null?y:void 0,fn,pn)}),{data:xn}=l({queryKey:[`library-stats`],queryFn:()=>a.getLibraryStats()}),{data:Sn}=l({queryKey:[`users`,`slim`],queryFn:()=>a.getUsersSlim()}),Cn=(0,R.useMemo)(()=>{if(!yn)return[];let e=new Set(yn.map(e=>e.file_type));return Array.from(e).sort()},[yn]),J=(0,R.useMemo)(()=>ul(yn??[],{query:Kt,filterType:Jt,filterUsername:Xt,sortField:Qt,sortDirection:en}),[yn,Kt,Jt,Xt,Qt,en]),wn=(0,R.useMemo)(()=>{if(!xn||!an)return!1;let e=(an.library_disk_warning_gb||5)*1024*1024*1024;return xn.disk_free_bytesa.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),ie(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),En=u({mutationFn:async e=>{let t=await a.createExternalFolder(e);return await a.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),le(!1),_(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Dn=u({mutationFn:e=>a.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),On=u({mutationFn:e=>a.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),g===ot?.id&&_(null),st(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{st(null),n(e.message,`error`)}}),kn=u({mutationFn:e=>a.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),T(e=>e.filter(e=>e!==ot?.id)),st(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{st(null),n(e.message,`error`)}}),An=u({mutationFn:e=>a.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),T([])},onError:e=>n(e.message,`error`)}),jn=u({mutationFn:e=>a.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),T([]),st(null)},onError:e=>{st(null),n(e.message,`error`)}}),Mn=u({mutationFn:({fileIds:e,folderId:t})=>a.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),T([]),fe(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),Nn=u({mutationFn:({id:e,data:t})=>a.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),Ye(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Pn=u({mutationFn:({id:e,filename:t})=>a.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),St(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{St(null),n(e.message,`error`)}}),Fn=u({mutationFn:({id:e,name:t})=>a.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),St(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{St(null),n(e.message,`error`)}}),In=u({mutationFn:({id:e,shared:t})=>a.updateLibraryFolder(e,{shared:t}),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),n(i.shared?e(`fileManager.toast.folderShared`):e(`fileManager.toast.folderUnshared`),`success`)},onError:e=>n(e.message,`error`)}),Ln=e=>In.mutate({id:e.id,shared:!e.shared}),Rn=u({mutationFn:()=>a.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),wt(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),zn=u({mutationFn:e=>a.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&wt(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),Bn=(0,R.useCallback)(e=>{r(`library:read`)&&(Ze(e)?m(`/gcode-viewer?library_file=${e.id}`):e.file_type===`3mf`||e.file_type===`stl`||Zc(e.file_type)?B(e):e.file_type===`pdf`?Dt(e):Xc(e.file_type)?H(e):tl(e.file_type)&&kt(e))},[r,m]),Vn=(0,R.useCallback)(e=>{T(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Hn=(0,R.useCallback)(()=>{if(J.length>0){let e=J.map(e=>e.id);T(t=>G===`columns`?[...new Set([...t,...e])]:e)}},[J,G]),Un=J.length>0&&J.every(e=>C.includes(e.id)),Wn=(0,R.useCallback)(()=>{T([])},[]),Gn=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},Y=(0,R.useMemo)(()=>{if(!g||!ln)return null;let e=t=>{for(let n of t){if(n.id===g)return n;let t=e(n.children);if(t)return t}return null};return e(ln)},[g,ln]),Kn=Y?.can_write!==!1,qn=r(`library:upload`)&&Kn,Jn=r(`library:upload`)?Kn?void 0:e(`fileManager.folderNotWritable`):void 0,{isDraggingOver:Yn,dragHandlers:Xn}=He({disabled:!qn||F,onFiles:e=>{ve(e),I(!0)}}),Zn=(0,R.useCallback)(e=>{if(!e.thumbnail_path&&s(`library`,`update`,e.created_by_id))return n=>{a.uploadLibraryPreviewThumbnail(e.id,n).then(n=>{n.updated&&(wt(t=>({...t,[e.id]:(t[e.id]||0)+1})),t.invalidateQueries({queryKey:[`library-files`]}))}).catch(()=>{})}},[s,t]),Qn=e=>{a.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},$n=()=>{ot&&(ot.type===`file`?kn.mutate(ot.id):ot.type===`folder`?On.mutate(ot.id):ot.type===`bulk`&&jn.mutate(C))},er=On.isPending||kn.isPending||jn.isPending,tr=e=>{At(e),localStorage.setItem(`library-view-mode`,e)},nr={onPrint:ut,onSlice:pt,onOpenInSlicer:sn,onRunPipeline:bt,useSlicerApi:an?.use_slicer_api??!1,desktopSlicer:on,canSlice:cn(),onPreview:Bn,onDetails:U,onDownload:Qn,onRename:e=>St({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>zn.mutate(e.id),thumbnailPending:zn.isPending,onDelete:e=>st({type:`file`,id:e}),hasPermission:r,canModify:s,t:e},rr=un||bn,ir=(0,R.useMemo)(()=>{if(!q||g===null)return[];let e=[],t=n=>{for(let r of n){if(e.push(r),r.id===g||t(r.children))return!0;e.pop()}return!1};return t(q),e},[q,g]),ar=ir.length>0?!!ir[0].is_external:y===`external`,X=(0,R.useMemo)(()=>{let e=[{key:`root`,folderId:null,items:(q??[]).filter(e=>!!e.is_external===ar),activeId:ir[0]?.id??null}];return ir.forEach((t,n)=>{t.children.length>0&&e.push({key:`folder-${t.id}`,folderId:t.id,items:t.children,activeId:ir[n+1]?.id??null})}),e},[q,ir,ar]),Z=(0,R.useMemo)(()=>G!==`columns`||_n?[]:X.filter(e=>e.folderId!==g).map(e=>({key:e.key,folderId:e.folderId,scope:e.folderId===null?ar?`external`:`internal`:void 0})),[G,_n,X,g,ar]),Q=d({combine:rl,queries:Z.map(e=>({queryKey:[`library-files`,`column`,e.folderId,e.scope??null],queryFn:()=>a.getLibraryFiles(e.folderId,e.folderId===null,void 0,e.scope,!1,[])}))}),or=new Map;Z.forEach((e,t)=>{let n=Q.results[t];or.set(e.key,{files:ul(n?.data??[],{filterType:Jt,filterUsername:Xt,sortField:Qt,sortDirection:en}),loading:!!n?.isPending})});let sr=(0,R.useMemo)(()=>{let e=new Map;for(let t of[...yn??[],...Q.files])e.set(t.id,t);return e},[yn,Q.files]),cr=(0,R.useMemo)(()=>{if(C.length!==1)return null;let e=sr.get(C[0]);return e&&il(e)?e:null},[sr,C]),lr=(0,R.useMemo)(()=>C.map(e=>sr.get(e)).filter(e=>!!e&&Ze(e)),[sr,C]),$=(0,R.useMemo)(()=>{let e=C.map(e=>sr.get(e)).filter(e=>!!e&&e.filename.toLowerCase().endsWith(`.stl`));return e.length===C.length?e:[]},[sr,C]),{data:ur}=l({queryKey:[`variant-group`,ct?.variant_group_id],queryFn:()=>a.getVariantGroup(ct.variant_group_id),enabled:!!ct?.variant_group_id}),dr=(0,R.useMemo)(()=>{if(ct){if(lr.length>1)return lr.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(ur&&ur.members.length>1)return ur.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[ct,lr,ur]),fr=K===null?void 0:Z.map(e=>or.get(e.key)?.files).find(e=>e?.some(e=>e.id===K)),pr=fr??J;(0,R.useEffect)(()=>{G===`columns`&&jt.current?.focus({preventScroll:!0})},[G]),(0,R.useEffect)(()=>{Mt(null)},[g,G]),(0,R.useEffect)(()=>{T([])},[g]),(0,R.useEffect)(()=>{G!==`columns`||g===null||jt.current?.querySelector(`[data-folder-id="${g}"]`)?.scrollIntoView?.({block:`nearest`})},[g,G]),(0,R.useEffect)(()=>{G!==`columns`||K===null||jt.current?.querySelector(`[data-file-id="${K}"]`)?.scrollIntoView?.({block:`nearest`})},[K,G]);let mr=()=>{let e=jt.current;if(e){if(K!==null)e.querySelector(`[data-file-id="${K}"] [data-file-actions] button:not([disabled])`)?.focus();else if(g!==null){let t=e.querySelector(`[data-folder-id="${g}"] [data-folder-actions] button`);t?.focus(),t?.click()}}},hr=e=>{if(e.ctrlKey||e.metaKey||e.altKey)return;let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.tagName===`SELECT`||t.isContentEditable)return;if(t.closest(`[data-folder-actions]`)){if(e.key===`Escape`){e.preventDefault(),jt.current?.focus({preventScroll:!0});return}if(e.key!==`ArrowUp`&&e.key!==`ArrowDown`)return;jt.current?.focus({preventScroll:!0})}let n=t.closest(`[data-file-actions]`);if(n){if(e.key===`Enter`||e.key===` `)return;if(e.key===`ArrowLeft`||e.key===`ArrowRight`){e.preventDefault();let r=Array.from(n.querySelectorAll(`button:not([disabled])`));r[r.indexOf(t)+(e.key===`ArrowRight`?1:-1)]?.focus();return}if(e.key===`Escape`){e.preventDefault(),jt.current?.focus({preventScroll:!0});return}(e.key===`ArrowUp`||e.key===`ArrowDown`)&&jt.current?.focus({preventScroll:!0})}if(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey){e.preventDefault(),mr();return}let r=K!==null,i=ir[ir.length-1];switch(e.key){case`ArrowDown`:case`ArrowUp`:{e.preventDefault();let t=e.key===`ArrowDown`?1:-1;if(r||_n){let e=pr.findIndex(e=>e.id===K),n=pr[e+t];n?Mt(n.id):t===-1&&e===0&&fr&&Mt(null)}else if(g===null)t===1&&X[0].items.length>0&&_(X[0].items[0].id);else{let e=X[ir.length-1],n=e?e.items.findIndex(e=>e.id===g):-1,r=n===-1?void 0:e.items[n+t];if(r)_(r.id);else if(t===1&&n!==-1){let t=e?or.get(e.key)?.files:void 0;t?.length&&Mt(t[0].id)}}break}case`ArrowRight`:if(e.preventDefault(),r)break;!_n&&i&&i.children.length>0?_(i.children[0].id):J.length>0&&Mt(J[0].id);break;case`ArrowLeft`:if(e.preventDefault(),r){Mt(null);break}if(_n)break;ir.length>1?_(ir[ir.length-2].id):ir.length===1?(x(ir[0].is_external?`external`:`internal`),_(null)):g!==null&&_(null);break;case`Enter`:{if(e.preventDefault(),!r){!_n&&i&&i.children.length>0?_(i.children[0].id):J.length>0&&Mt(J[0].id);break}let t=pr.find(e=>e.id===K);t&&Bn(t);break}case` `:if(e.preventDefault(),!r)break;K!==null&&Vn(K);break}};return(0,z.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-screen flex flex-col relative`,...Xn,children:[Yn&&(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,z.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,z.jsx)(Ne,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(Ie,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,z.jsx)(`button`,{onClick:()=>tr(`grid`),className:`p-1.5 rounded transition-colors ${G===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,z.jsx)(k,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{onClick:()=>tr(`list`),className:`p-1.5 rounded transition-colors ${G===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,z.jsx)(ee,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{onClick:()=>tr(`columns`),className:`p-1.5 rounded transition-colors ${G===`columns`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.columnsView`),children:(0,z.jsx)(b,{className:`w-4 h-4`})})]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Rn.mutate(),disabled:Rn.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[Rn.isPending?(0,z.jsx)(j,{className:`w-4 h-4 mr-2 animate-spin`}):(0,z.jsx)(Fe,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>le(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,z.jsx)(it,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>ie(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionCreateFolder`),children:[(0,z.jsx)(rt,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Re(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,z.jsx)(xe,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Pe(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,z.jsx)(de,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,z.jsxs)(Se,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,z.jsx)(de,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof dn==`number`&&dn>0&&(0,z.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:dn})]}),(0,z.jsxs)(P,{onClick:()=>I(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionUpload`),children:[(0,z.jsx)(Ne,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),wn&&xn&&an&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,z.jsx)(re,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1`,children:[(0,z.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,z.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:oe(xn.disk_free_bytes),total:oe(xn.disk_total_bytes),threshold:an.library_disk_warning_gb})})]})]}),xn&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(w,{className:`w-4 h-4 text-bambu-green`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:xn.total_files})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(Ie,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:xn.total_folders})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(O,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:oe(xn.total_size_bytes)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,z.jsx)(`span`,{className:`font-medium ${wn?`text-amber-500`:`text-white`}`,children:oe(xn.disk_free_bytes)})]})]}),(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,z.jsx)(`div`,{className:`lg:hidden`,children:(0,z.jsxs)(`select`,{value:g===null?`__top:${y}`:String(g),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(_(null),x(t.slice(6))):_(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),ln?.some(e=>e.is_external)&&(0,z.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),q&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(q).map(e=>(0,z.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,z.jsxs)(`div`,{ref:Gt,"data-testid":`folder-sidebar`,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${Vt}px`},children:[(0,z.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${Ut?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),Wt(!0)},onDoubleClick:()=>{Ht(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,z.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${Ut?`opacity-100`:``}`,children:[(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,z.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,z.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsxs)(`select`,{value:Lt,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;Rt(t),localStorage.setItem(`library-folder-sort-field`,t)},className:`text-xs px-1 py-0.5 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray focus:outline-none focus:border-bambu-green`,title:e(`fileManager.folderSort`),"aria-label":e(`fileManager.folderSort`),children:[(0,z.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,z.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,z.jsx)(`button`,{onClick:()=>{let e=zt===`asc`?`desc`:`asc`;Bt(e),localStorage.setItem(`library-folder-sort-direction`,e)},className:`text-bambu-gray hover:text-white hover:bg-bambu-dark p-1 rounded transition-colors`,title:e(zt===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(zt===`asc`?`fileManager.ascending`:`fileManager.descending`),children:zt===`asc`?(0,z.jsx)(et,{className:`w-3.5 h-3.5`}):(0,z.jsx)($e,{className:`w-3.5 h-3.5`})}),(0,z.jsx)(`button`,{onClick:()=>{let e=!Ft;It(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Ft?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Ft?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,z.jsx)(`button`,{onClick:()=>{let e=!Nt;Pt(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Nt?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Nt?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${g===null&&y===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{_(null),x(`internal`)},children:[(0,z.jsx)(S,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),ln?.some(e=>e.is_external)&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${g===null&&y===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{_(null),x(`external`)},children:[(0,z.jsx)(it,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,z.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),q?.map(t=>(0,z.jsx)(xl,{folder:t,selectedFolderId:g,onSelect:_,onDelete:e=>st({type:`folder`,id:e}),onLink:Ye,onRename:e=>St({type:`folder`,id:e.id,name:e.name}),onToggleShared:Ln,wrapNames:Nt,defaultExpanded:!Ft,showModified:nn,hasPermission:r,t:e},`${t.id}-${Ft?`c`:`e`}`))]})]}),(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[mn.length>0&&(0,z.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),mn.map(e=>{let t=We.includes(e.id);return(0,z.jsxs)(`button`,{type:`button`,onClick:()=>gn(e.id),className:t?`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/20 text-bambu-green border border-bambu-green/40 hover:bg-bambu-green/30 transition-colors`:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-dark text-bambu-gray border border-bambu-dark-tertiary hover:text-white hover:border-bambu-green/40 transition-colors`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-3 h-3`}),(0,z.jsx)(`span`,{children:e.name}),t&&(0,z.jsx)(ae,{className:`w-3 h-3`})]},e.id)}),We.length>0&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>qe([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),Y?.is_external&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:[(0,z.jsx)(it,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),Y.external_readonly&&(0,z.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,z.jsx)(M,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:Y.external_path||``,children:Y.external_path})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>g&&Dn.mutate(g),disabled:Dn.isPending,title:e(`fileManager.scanFolder`),children:[Dn.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(L,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),yn&&yn.length>0&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,z.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,z.jsx)(N,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,z.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Kt,onChange:e=>qt(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`}),fn&&(0,z.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(E,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,z.jsxs)(`select`,{value:Jt,onChange:e=>Yt(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),Cn.map(e=>(0,z.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),f&&(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:Xt,onChange:e=>Zt(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${Xt?`pr-7`:``}`,style:Xt?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),Xt&&(0,z.jsx)(`button`,{onClick:()=>Zt(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,z.jsx)(ae,{className:`w-3 h-3`})}),(0,z.jsx)(`datalist`,{id:`usernames-list`,children:Sn?.map(e=>(0,z.jsx)(`option`,{value:e.username},e.id))})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(`select`,{value:Qt,onChange:e=>{let t=e.target.value;$t(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,z.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,z.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,z.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,z.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,z.jsx)(`button`,{onClick:()=>tn(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(en===`asc`?`fileManager.ascending`:`fileManager.descending`),children:en===`asc`?(0,z.jsx)(et,{className:`w-4 h-4 text-white`}):(0,z.jsx)($e,{className:`w-4 h-4 text-white`})}),(0,z.jsx)(`button`,{onClick:()=>rn(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${nn?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(nn?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":nn,children:(0,z.jsx)(tt,{className:`w-4 h-4`})})]}),(Kt||Jt!==`all`||Xt)&&(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:J.length,total:yn.length})})]}),(J.length>0||C.length>0)&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[Un?(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Wn,children:[(0,z.jsx)(ge,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Hn,children:[(0,z.jsx)(Ce,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),C.length>0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:C.length})}),(0,z.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,z.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[cr&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>Bn(cr),disabled:!r(`library:read`),title:r(`library:read`)?void 0:e(`fileManager.noPermissionPreview`),children:[(0,z.jsx)(we,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.preview.open`)})]}),lr.length>=1&&(0,z.jsxs)(P,{variant:`primary`,size:`sm`,onClick:()=>ut(lr[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,z.jsx)(me,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:lr.length>1?e(`fileManager.variants.printAlternatives`,{count:lr.length}):e(`common.print`)})]}),lr.length>=2&&!lr.some(e=>e.variant_group_id)&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>An.mutate(lr.map(e=>e.id)),disabled:An.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,z.jsx)(je,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),$.length>=1&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>gt(!0),disabled:!r(`library:upload`),title:e(`fileManager.combine.tooltip`),children:[(0,z.jsx)(nt,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.combine.action`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>fe(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,z.jsx)(at,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>Ve(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.tags.bulkTooltip`):e(`fileManager.tags.noPermission`),children:[(0,z.jsx)(xe,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,z.jsxs)(P,{variant:`danger`,size:`sm`,onClick:()=>{C.length===1?st({type:`file`,id:C[0]}):st({type:`bulk`,id:0,count:C.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,z.jsx)(de,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Wn,children:[(0,z.jsx)(ae,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),rr&&G!==`columns`?(0,z.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,z.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,z.jsx)(j,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):G===`columns`?(0,z.jsx)(`div`,{ref:jt,tabIndex:0,"aria-label":e(`fileManager.columnsView`),onKeyDown:hr,className:`flex-1 min-h-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto outline-none focus-visible:ring-1 focus-visible:ring-bambu-green/50`,"data-testid":`columns-view`,children:(0,z.jsxs)(`div`,{className:`h-full min-h-[16rem] flex divide-x divide-bambu-dark-tertiary`,children:[!_n&&X.map(t=>{let n=or.get(t.key),i=!!(n&&(n.loading||n.files.length>0));return(0,z.jsxs)(`div`,{"data-testid":`columns-level-${t.key}`,className:`${i?`w-[26rem]`:`w-64`} flex-shrink-0 overflow-y-auto py-1`,children:[t.items.map(n=>{let i=g===n.id;return(0,z.jsxs)(`div`,{"data-folder-id":n.id,className:`group flex items-center pr-1.5 transition-colors ${t.activeId===n.id?`bg-bambu-green/20 text-bambu-green`:i?`bg-bambu-green/10 text-white`:`text-white hover:bg-bambu-dark`}`,children:[(0,z.jsxs)(`button`,{type:`button`,tabIndex:-1,onClick:()=>{Mt(null),_(n.id)},className:`flex-1 min-w-0 flex items-center gap-2 pl-3 pr-1 py-2.5 text-left text-sm`,title:n.name,children:[n.is_external?(0,z.jsx)(it,{className:`w-5 h-5 flex-shrink-0 text-purple-600 dark:text-purple-400`}):(0,z.jsx)(Ie,{className:`w-5 h-5 flex-shrink-0 text-bambu-green`}),(0,z.jsx)(`span`,{className:`flex-1 truncate`,children:n.name}),(n.project_id||n.archive_id)&&(0,z.jsx)(A,{className:`w-3.5 h-3.5 flex-shrink-0 text-blue-700 dark:text-blue-400`}),n.shared&&(0,z.jsx)(`span`,{title:e(`fileManager.sharedFolder`),children:(0,z.jsx)(pe,{className:`w-3.5 h-3.5 flex-shrink-0 text-bambu-gray`})}),n.is_external&&n.external_readonly&&(0,z.jsx)(M,{className:`w-3.5 h-3.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),n.file_count>0&&(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:n.file_count}),n.children.length>0&&(0,z.jsx)(_e,{className:`w-4 h-4 flex-shrink-0 text-bambu-gray`})]}),(0,z.jsx)(bl,{folder:n,onDelete:e=>st({type:`folder`,id:e}),onLink:Ye,onRename:e=>St({type:`folder`,id:e.id,name:e.name}),onToggleShared:Ln,hasPermission:r,revealOnHover:!i,tabIndex:i?0:-1,t:e})]},n.id)}),n?.loading&&(0,z.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,"aria-hidden":`true`,children:`…`}),n&&!n.loading&&n.files.map(t=>(0,z.jsx)(wl,{file:t,isSelected:C.includes(t.id),isFocused:K===t.id,showModified:nn,thumbnailVersion:Ct[t.id],onSelect:e=>{Mt(e.id),Vn(e.id)},onOpen:Bn,actionProps:nr,t:e},t.id))]},t.key)}),(0,z.jsx)(`div`,{className:`flex-1 min-w-[28rem] overflow-y-auto py-1`,"data-testid":`columns-files-pane`,children:bn?(0,z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,z.jsx)(j,{className:`w-5 h-5 animate-spin text-bambu-green`})}):J.length===0?(0,z.jsx)(`div`,{className:`h-full flex items-center justify-center px-4 text-sm text-bambu-gray text-center`,children:(yn?.length??0)>0?e(`fileManager.noMatchingFiles`):g===null?vn&&X[0].items.length>0?e(`fileManager.noFilesOutsideFolders`):e(y===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`):e(`fileManager.folderIsEmpty`)}):J.map(t=>(0,z.jsx)(wl,{file:t,isSelected:C.includes(t.id),isFocused:K===t.id,showModified:nn,thumbnailVersion:Ct[t.id],onSelect:e=>{Mt(e.id),Vn(e.id)},onOpen:Bn,actionProps:nr,t:e},t.id))})]})}):yn?.length===0?(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(S,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(g===null?y===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(g===null?y===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,z.jsxs)(P,{onClick:()=>I(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionUpload`),children:[(0,z.jsx)(Oe,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):J.length===0?(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(N,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,z.jsx)(P,{variant:`secondary`,onClick:()=>{qt(``),Yt(`all`)},children:e(`fileManager.clearFilters`)})]}):G===`grid`?(0,z.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,z.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:J.map(t=>(0,z.jsx)(Sl,{file:t,isSelected:C.includes(t.id),t:e,onSelect:Vn,onDelete:e=>st({type:`file`,id:e}),onDownload:Qn,onPrint:ut,onSlice:pt,onOpenInSlicer:sn,desktopSlicer:on,onRunPipeline:bt,useSlicerApi:an?.use_slicer_api??!1,canSlice:cn(),onPreview:Bn,onRename:e=>St({type:`file`,id:e.id,name:e.filename}),onDetails:U,onGenerateThumbnail:e=>zn.mutate(e.id),onTagClick:gn,thumbnailVersion:Ct[t.id],hasPermission:r,canModify:s,authEnabled:f,showModified:nn},t.id))})}):(0,z.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,z.jsxs)(`div`,{"data-testid":`file-list-grid-header`,className:`hidden sm:grid ${dl(f)} ${fl} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,z.jsx)(`div`,{className:`w-6`}),(0,z.jsx)(`div`,{children:e(`common.name`)}),f&&(0,z.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,z.jsx)(`div`,{children:e(`common.type`)}),(0,z.jsx)(`div`,{children:e(`fileManager.size`)}),(0,z.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,z.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,z.jsx)(`div`,{})]}),J.map(t=>(0,z.jsxs)(`div`,{"data-testid":`file-list-grid-row`,className:`grid ${dl(f)} ${fl} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${C.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>Vn(t.id),onDoubleClick:()=>Bn(t),children:[(0,z.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${C.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:C.includes(t.id)&&(0,z.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,z.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(t.id)}${Ct[t.id]?(a.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${Ct[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,z.jsx)(nl,{fileType:t.file_type,className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,z.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,z.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(t.id)}${Ct[t.id]?(a.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${Ct[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,z.jsx)(`span`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),t.external_url&&(0,z.jsx)(`a`,{href:t.external_url,target:`_blank`,rel:`noopener noreferrer`,...al,className:`flex-shrink-0 text-bambu-gray hover:text-bambu-green`,title:e(`fileManager.details.openLink`),"aria-label":e(`fileManager.details.openLink`),children:(0,z.jsx)(Me,{className:`w-3.5 h-3.5`})}),t.has_notes&&(0,z.jsx)(`span`,{className:`flex-shrink-0 text-bambu-gray`,title:e(`fileManager.details.hasNotes`),"aria-label":e(`fileManager.details.hasNotes`),children:(0,z.jsx)(ne,{className:`w-3.5 h-3.5`})}),(t.photo_count??0)>0&&(0,z.jsxs)(`span`,{className:`flex-shrink-0 flex items-center gap-0.5 text-xs text-bambu-gray`,title:e(`fileManager.details.photoCount`,{count:t.photo_count}),children:[(0,z.jsx)(be,{className:`w-3.5 h-3.5`}),t.photo_count]})]}),nn&&(0,z.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:se(t.fs_modified_at??t.created_at)})]})]})]}),f&&(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(ye,{className:`w-3 h-3`}),(0,z.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,z.jsx)(`div`,{children:(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${ll(t.file_type)}`,children:t.file_type.toUpperCase()})}),(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:oe(t.file_size)}),(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,z.jsx)(`div`,{className:`min-w-0`,...al,children:!t.tags||t.tags.length===0?(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>gn(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,z.jsx)(Cl,{file:t,...nr})]},t.id))]})})]}),g!==null&&(0,z.jsx)(Hc,{folderId:g})]})]}),te&&(0,z.jsx)(pl,{parentId:g,onClose:()=>ie(!1),onSave:e=>Tn.mutate(e),isLoading:Tn.isPending,t:e}),ce&&(0,z.jsx)(ml,{onClose:()=>le(!1),onSave:e=>En.mutate(e),isLoading:En.isPending,t:e}),ue&&ln&&(0,z.jsx)(vl,{folders:ln,selectedFiles:C,currentFolderId:g,onClose:()=>fe(!1),onMove:e=>Mn.mutate({fileIds:C,folderId:e}),isLoading:Mn.isPending,t:e}),F&&(0,z.jsx)(Xe,{folderId:g,onClose:()=>{I(!1),ve([])},onUploadComplete:Gn,initialFiles:he.length>0?he:void 0}),Te&&(0,z.jsx)(Kc,{onClose:()=>Pe(!1)}),(0,z.jsx)(Uc,{open:Le,onClose:()=>Re(!1),onPickTag:e=>{We.includes(e)||qe(t=>[...t,e])}}),(0,z.jsx)(mt,{open:Be,fileIds:C,onClose:()=>Ve(!1)}),Je&&(0,z.jsx)(yl,{folder:Je,onClose:()=>Ye(null),onLink:e=>Nn.mutate({id:Je.id,data:e}),isLoading:Nn.isPending,t:e}),ot&&(0,z.jsx)(ke,{title:ot.type===`folder`?e(`fileManager.deleteFolder`):ot.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:ot.count}):e(`fileManager.deleteFile`),message:ot.type===`folder`?e(`fileManager.deleteFolderConfirm`):ot.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:ot.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:er,loadingText:e(`fileManager.deleting`),onConfirm:$n,onCancel:()=>st(null)}),ct&&(!ct.variant_group_id||ur!==void 0)&&(0,z.jsx)(Ae,{mode:`create`,libraryFileId:dr?.[0]?.id??ct.id,variantFiles:dr,archiveName:dr&&dr.length>1?`${dr[0].filename} ${e(`common.plusNMore`,{count:dr.length-1})}`:ct.print_name||ct.filename,onClose:()=>ut(null),onSuccess:()=>{ut(null),T([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),dt&&(0,z.jsx)(D,{source:{kind:`libraryFile`,id:dt.id,filename:dt.filename},onClose:()=>pt(null)}),ht&&$.length>0&&(0,z.jsx)(ft,{files:$,folderId:g,canSlice:!!an?.use_slicer_api&&cn(),onClose:()=>gt(!1),onCombined:(e,t)=>{gt(!1),T([]),t&&vt({id:e.id,filename:e.filename})}}),_t&&(0,z.jsx)(D,{source:{kind:`libraryFile`,id:_t.id,filename:_t.filename},onClose:()=>vt(null),defaultAutoArrange:!0}),yt&&(0,z.jsx)(Ue,{source:{kind:`libraryFile`,id:yt.id,filename:yt.filename},onClose:()=>bt(null)}),Tt&&(0,z.jsx)(lt,{libraryFileId:Tt.id,title:Tt.print_name||Tt.filename,fileType:Tt.file_type,onClose:()=>B(null),onSnapshot:Zc(Tt.file_type)?Zn(Tt):void 0,onSliceWithBambuddy:Qe(Tt,!0,on)&&r(`library:upload`)?()=>{let e=Tt;B(null),pt(e)}:void 0}),(Et||V||W)&&(0,z.jsxs)(R.Suspense,{fallback:null,children:[Et&&(0,z.jsx)(qc,{libraryFileId:Et.id,filename:Et.print_name||Et.filename,fileSize:Et.file_size,onClose:()=>Dt(null),onSnapshot:Zn(Et)}),V&&(0,z.jsx)(Jc,{libraryFileId:V.id,filename:V.print_name||V.filename,fileType:V.file_type,fileSize:V.file_size,onClose:()=>H(null),onSnapshot:Zn(V)}),W&&(0,z.jsx)(Yc,{libraryFileId:W.id,filename:W.print_name||W.filename,fileSize:W.file_size,onClose:()=>kt(null)})]}),Ot&&(0,z.jsx)(Wc,{file:Ot,canEdit:s(`library`,`update`,Ot.created_by_id),onClose:()=>U(null)}),xt&&(0,z.jsx)(_l,{type:xt.type,currentName:xt.name,onClose:()=>St(null),onSave:e=>{xt.type===`file`?Pn.mutate({id:xt.id,filename:e}):Fn.mutate({id:xt.id,name:e})},isLoading:Pn.isPending||Fn.isPending,t:e})]})}export{Tl as FileManagerPage};
\ No newline at end of file
+`},i)),a}function Zo(e,t){return e&&`run`in e?async function(n,r){let i=Xo(n,{file:r,...t});await e.run(i,r)}:function(n,r){return Xo(n,{file:r,...e||t})}}function Qo(e){if(e)throw e}var $o=n(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});ft.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var rs={basename:is,dirname:as,extname:os,join:ss,sep:`/`};function is(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);us(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function as(e){if(us(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function os(e){us(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function ss(...e){let t=-1,n;for(;++t0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function ls(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function us(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var ds={cwd:fs};function fs(){return`/`}function ps(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function ms(e){if(typeof e==`string`)e=new URL(e);else if(!ps(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return hs(e)}function hs(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n0){let[r,...a]=t,o=n[i][1];es(o)&&es(r)&&(r=(0,Cs.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function Es(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function Ds(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function Os(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function ks(e){if(!es(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function As(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function js(e){return Ms(e)?e:new _s(e)}function Ms(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function Ns(e){return typeof e==`string`||Ps(e)}function Ps(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var Fs=[],Is={allowDangerousHtml:!0},Ls=/^(https?|ircs?|mailto|xmpp)$/i,Rs=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function zs(e){let t=Bs(e),n=Vs(e);return Hs(t.runSync(t.parse(n),n),e)}function Bs(e){let t=e.rehypePlugins||Fs,n=e.remarkPlugins||Fs,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Is}:Is;return Ts().use(Fa).use(n).use(Zo,r).use(t)}function Vs(e){let t=e.children||``,n=new _s;return typeof t==`string`?n.value=t:``+t,n}function Hs(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||Us;for(let e of Rs)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return t.className&&(e={type:`element`,tagName:`div`,properties:{className:t.className},children:e.type===`root`?e.children:[e]}),Vo(e,l),_n(e,{Fragment:z.Fragment,components:i,ignoreInvalidStyle:!0,jsx:z.jsx,jsxs:z.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in Rn)if(Object.hasOwn(Rn,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=Rn[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function Us(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Ls.test(e.slice(0,t))?e:``}$s.peek=Qs;function Ws(){this.buffer()}function Gs(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function Ks(){this.buffer()}function qs(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function Js(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Qn(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Ys(e){this.exit(e)}function Xs(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Qn(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Zs(e){this.exit(e)}function Qs(){return`[`}function $s(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function ec(){return{enter:{gfmFootnoteCallString:Ws,gfmFootnoteCall:Gs,gfmFootnoteDefinitionLabelString:Ks,gfmFootnoteDefinition:qs},exit:{gfmFootnoteCallString:Js,gfmFootnoteCall:Ys,gfmFootnoteDefinitionLabelString:Xs,gfmFootnoteDefinition:Zs}}}ic.peek=ac;function tc(){return{canContainEols:[`delete`],enter:{strikethrough:nc},exit:{strikethrough:rc}}}function nc(e){this.enter({type:`delete`,children:[]},e)}function rc(e){this.exit(e)}function ic(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function ac(){return`~`}function oc(){return{enter:{table:sc,tableData:dc,tableHeader:dc,tableRow:lc},exit:{codeText:fc,table:cc,tableData:uc,tableHeader:uc,tableRow:uc}}}function sc(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[]},e),this.data.inTable=!0}function cc(e){this.exit(e),this.data.inTable=void 0}function lc(e){this.enter({type:`tableRow`,children:[]},e)}function uc(e){this.exit(e)}function dc(e){this.enter({type:`tableCell`,children:[]},e)}function fc(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,pc));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function pc(e,t){return t===`|`?t:e}function mc(){return{exit:{taskListCheckValueChecked:hc,taskListCheckValueUnchecked:hc,paragraph:gc}}}function hc(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function gc(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i999||s===93&&!o||s===null||s===91||Z(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(Qn(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return Z(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function Sc(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||Z(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=Qn(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return Z(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),$(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function Cc(e,t,n){return e.check(wr,t,e.attempt(_c,t,n))}function wc(e){e.exit(`gfmFootnoteDefinition`)}function Tc(e,t,n){let r=this;return $(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function Ec(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=gr(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var Dc=class{constructor(){this.map=[]}add(e,t,n){Oc(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function Oc(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):X(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):Q(t)?$(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||Z(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,Q(t)?$(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return Q(t)?$(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||X(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return Q(t)?$(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||X(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||X(n)?(e.exit(`tableRow`),t(n)):Q(n)?$(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||Z(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function Mc(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new Dc;for(;++nn[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},Fc(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function Pc(e,t,n,r,i){let a=[],o=Fc(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function Fc(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var Ic={name:`tasklistCheck`,tokenize:Rc};function Lc(){return{text:{91:Ic}}}function Rc(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return Z(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return X(r)?t(r):Q(r)?e.check({tokenize:zc},t,n)(r):n(r)}}function zc(e,t,n){return $(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function Bc(){let e=this.data(),t=e.micromarkExtensions||=[],n=e.fromMarkdownExtensions||=[];t.push(vc(),Ec(),Ac(),Lc()),n.push(ec(),tc(),oc(),mc())}var Vc=`fileManager.readmeCollapsed`;function Hc({folderId:e}){let{t}=o(),[n,r]=(0,R.useState)(()=>localStorage.getItem(Vc)===`1`);(0,R.useEffect)(()=>{localStorage.setItem(Vc,n?`1`:`0`)},[n]);let{data:i,isLoading:s,error:c}=l({queryKey:[`folder-readme`,e],queryFn:()=>a.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return s||c||!i?null:n?(0,z.jsxs)(`div`,{className:`mb-2 lg:mb-0 order-first lg:order-none lg:w-10 lg:flex-shrink-0 lg:h-full`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`flex lg:hidden w-full items-center gap-2 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,z.jsx)(Re,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,z.jsx)(st,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`hidden lg:flex h-full w-10 flex-col items-center gap-2 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,z.jsx)(st,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,z.jsxs)(`div`,{className:`mb-4 lg:mb-0 order-first lg:order-none lg:w-80 xl:w-96 lg:flex-shrink-0 lg:h-full flex flex-col bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,z.jsx)(Re,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex-shrink-0`,children:t(`fileManager.readme.truncated`)})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(!0),title:t(`fileManager.readme.hide`),"aria-label":t(`fileManager.readme.hide`),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark/40 transition-colors flex-shrink-0`,children:(0,z.jsx)(ot,{className:`w-4 h-4`})})]}),(0,z.jsx)(`div`,{className:`px-4 py-3 border-t border-bambu-dark-tertiary flex-1 overflow-y-auto max-h-96 lg:max-h-none text-sm text-bambu-gray-light leading-relaxed space-y-2`,children:(0,z.jsx)(zs,{remarkPlugins:[Bc],components:{h1:({children:e})=>(0,z.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,z.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,z.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,z.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,z.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,z.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,z.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,z.jsx)(`code`,{className:`px-1 py-0.5 bg-bambu-dark rounded text-xs font-mono text-bambu-green`,children:e}),pre:({children:e})=>(0,z.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,z.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,z.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,z.jsx)(`div`,{className:`overflow-x-auto`,children:(0,z.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,z.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,z.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,z.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function Uc({open:e,onClose:t,onPickTag:n}){let{t:r}=o(),i=c(),{showToast:s}=v(),[d,f]=(0,R.useState)(!1),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(``),[_,y]=(0,R.useState)(null),{data:b=[],isLoading:x}=l({queryKey:pt,queryFn:a.getLibraryTags,enabled:e}),S=()=>{i.invalidateQueries({queryKey:pt}),i.invalidateQueries({queryKey:[`library-files`]})},C=u({mutationFn:async()=>{let e=h.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return p?a.updateLibraryTag(p.id,e):a.createLibraryTag(e)},onSuccess:()=>{s(r(p?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),f(!1),m(null),g(``),S()},onError:e=>{s(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),w=u({mutationFn:e=>a.deleteLibraryTag(e),onSuccess:()=>{s(r(`fileManager.tags.deleted`),`success`),y(null),S()},onError:e=>{s(e.message||r(`fileManager.tags.deleteFailed`),`error`)}}),T=()=>{m(null),g(``),f(!0)},E=e=>{m(e),g(e.name),f(!0)},D=(0,R.useCallback)(()=>{C.isPending||(f(!1),m(null),g(``))},[C.isPending]);(0,R.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(C.isPending||w.isPending||(d?D():_||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,d,_,C.isPending,w.isPending,D,t]);let O=e=>{e.preventDefault(),C.mutate()};if(!e)return null;let k=`library-tags-modal-title`,A=`library-tag-editor-title`;return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{C.isPending||w.isPending||t()}}),(0,z.jsxs)(`div`,{className:`relative w-full max-w-4xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":k,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`h2`,{id:k,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(xe,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(P,{onClick:T,children:[(0,z.jsx)(Oe,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]})]}),(0,z.jsx)(`div`,{className:`overflow-y-auto`,children:x?(0,z.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,z.jsx)(j,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):b.length===0?(0,z.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,z.jsx)(`thead`,{children:(0,z.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,z.jsx)(`tbody`,{children:b.map(e=>(0,z.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 ${n?`cursor-pointer`:``}`,onClick:()=>{n&&(n(e.id),t())},children:[(0,z.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,z.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,z.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>E(e),title:r(`common.edit`),"aria-label":r(`fileManager.tags.editAria`,{name:e.name}),children:(0,z.jsx)(ue,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>y(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,z.jsx)(de,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),d&&(0,z.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:D}),(0,z.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":A,children:[(0,z.jsx)(`h3`,{id:A,className:`text-lg font-semibold text-white mb-4`,children:r(p?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,z.jsxs)(`form`,{onSubmit:O,children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,z.jsx)(`input`,{id:`library-tag-name`,type:`text`,maxLength:64,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:r(`fileManager.tags.createPlaceholder`),value:h,onChange:e=>g(e.target.value),autoFocus:!0}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:D,children:r(`common.cancel`)}),(0,z.jsxs)(P,{type:`submit`,disabled:C.isPending||!h.trim(),children:[C.isPending&&(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),_&&(0,z.jsx)(ke,{title:r(`fileManager.tags.confirmDelete`,{name:_.name}),message:_.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:_.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:w.isPending,onConfirm:()=>w.mutate(_.id),onCancel:()=>y(null)})]})}function Wc({file:e,canEdit:t,onClose:n}){let{t:r}=o(),{showToast:i}=v(),s=c(),{data:d}=l({queryKey:[`library-file`,e.id],queryFn:()=>a.getLibraryFile(e.id)}),[f,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(``),[g,_]=(0,R.useState)([]),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(null),C=(0,R.useRef)(null),w=(0,R.useRef)(null);(0,R.useEffect)(()=>{!d||w.current===d.id||(w.current=d.id,p(d.notes??``),h(d.external_url??``),_(d.photos??[]))},[d]),(0,R.useEffect)(()=>{if(x!==null)return;let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[x,n]);let T=()=>{s.invalidateQueries({queryKey:[`library-files`]}),s.invalidateQueries({queryKey:[`library-file`,e.id]})},E=u({mutationFn:()=>a.updateLibraryFile(e.id,{notes:f,external_url:m.trim()}),onSuccess:()=>{T(),i(r(`fileManager.details.saved`),`success`),n()},onError:()=>{i(r(`fileManager.details.saveFailed`),`error`)}}),D=!!d&&(f!==(d.notes??``)||m.trim()!==(d.external_url??``)),O=async t=>{let n=t.target.files?.[0];if(n){b(!0);try{_((await a.uploadLibraryFilePhoto(e.id,n)).photos),T()}catch{i(r(`fileManager.details.uploadFailed`),`error`)}finally{b(!1),C.current&&(C.current.value=``)}}},k=async t=>{try{let n=(await a.deleteLibraryFilePhoto(e.id,t)).photos??[];_(n),n.length===0&&S(null),T()}catch{i(r(`fileManager.details.deleteFailed`),`error`)}},A=e=>{e.preventDefault(),!(!t||!D)&&E.mutate()},ee=m.trim(),M=[{label:r(`fileManager.details.size`),value:oe(e.file_size)},{label:r(`fileManager.details.type`),value:e.file_type.toUpperCase()}];if(d?.print_name&&M.push({label:r(`fileManager.details.printName`),value:d.print_name}),d?.print_time_seconds&&M.push({label:r(`fileManager.details.printTime`),value:ce(d.print_time_seconds)}),d?.filament_used_grams&&M.push({label:r(`fileManager.details.filament`),value:`${d.filament_used_grams.toFixed(1)} g`}),d?.sliced_for_model&&M.push({label:r(`fileManager.details.slicedFor`),value:d.sliced_for_model}),d?.source_url){let e=/^https?:\/\//i.test(d.source_url);M.push({label:r(`fileManager.details.source`),value:e?(0,z.jsxs)(`a`,{href:d.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1 min-w-0`,children:[(0,z.jsx)(`span`,{className:`truncate`,children:d.source_url}),(0,z.jsx)(fe,{className:`w-3 h-3 flex-shrink-0`})]}):(0,z.jsx)(`span`,{className:`truncate`,children:d.source_url})})}return M.push({label:r(`fileManager.details.created`),value:se(e.created_at)}),M.push({label:r(`fileManager.details.modified`),value:se(e.fs_modified_at??d?.updated_at??e.created_at)}),(0,z.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.title`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:e.filename,children:e.filename}),(0,z.jsx)(`span`,{className:`flex-shrink-0 text-xs px-1.5 py-0.5 rounded font-medium bg-bambu-dark-tertiary text-bambu-gray`,children:e.file_type.toUpperCase()})]})]}),(0,z.jsx)(`button`,{type:`button`,onClick:n,className:`text-bambu-gray hover:text-white transition-colors flex-shrink-0`,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`form`,{onSubmit:A,className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,z.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-sm`,children:M.map(e=>(0,z.jsxs)(`div`,{className:`contents`,children:[(0,z.jsx)(`dt`,{className:`text-bambu-gray whitespace-nowrap`,children:e.label}),(0,z.jsx)(`dd`,{className:`text-white min-w-0 truncate`,children:e.value})]},e.label))}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(ne,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.notes`)]}),(0,z.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),rows:3,disabled:!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none disabled:opacity-60`,placeholder:r(`fileManager.details.notesPlaceholder`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(Pe,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.externalLink`)]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`input`,{type:`url`,value:m,onChange:e=>h(e.target.value),disabled:!t,className:`flex-1 min-w-0 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-60`,placeholder:r(`fileManager.details.externalLinkPlaceholder`)}),ee&&(0,z.jsx)(`a`,{href:ee,target:`_blank`,rel:`noopener noreferrer`,className:`p-2 rounded-lg text-bambu-gray hover:text-bambu-green hover:bg-bambu-dark transition-colors`,title:r(`fileManager.details.openLink`),"aria-label":r(`fileManager.details.openLink`),children:(0,z.jsx)(fe,{className:`w-4 h-4`})})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(be,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.photos`)]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[g.map((n,i)=>(0,z.jsxs)(`div`,{className:`relative group`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>S(i),className:`block w-20 h-20 rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,z.jsx)(`img`,{src:a.getLibraryFilePhotoUrl(e.id,n),alt:r(`fileManager.details.photos`),className:`w-full h-full object-cover`})}),t&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>k(n),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:r(`fileManager.details.deletePhoto`),"aria-label":r(`fileManager.details.deletePhoto`),children:(0,z.jsx)(de,{className:`w-3 h-3 text-white`})})]},n)),t&&(0,z.jsxs)(`label`,{className:`w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors`,title:r(`fileManager.details.addPhoto`),children:[(0,z.jsx)(`input`,{ref:C,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:O,className:`hidden`,disabled:y,"aria-label":r(`fileManager.details.addPhoto`)}),y?(0,z.jsx)(j,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,z.jsx)(Oe,{className:`w-6 h-6 text-bambu-gray`})]}),g.length===0&&!t&&(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.noPhotos`)})]})]}),(0,z.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,className:`flex-1`,children:r(`common.close`)}),t&&(0,z.jsxs)(P,{type:`submit`,variant:`primary`,className:`flex-1`,disabled:!D||E.isPending,children:[E.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(Te,{className:`w-4 h-4`}),r(`fileManager.details.save`)]})]})]})]}),x!==null&&g.length>0&&(0,z.jsx)(We,{archiveName:e.filename,photos:g,initialIndex:x,getPhotoUrl:t=>a.getLibraryFilePhotoUrl(e.id,t),onClose:()=>S(null),onDelete:t?k:void 0})]})}var Gc=90;function Kc({onClose:e}){let{t}=o(),n=c(),{showToast:r}=v(),[i,s]=(0,R.useState)(Gc),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(i);(0,R.useEffect)(()=>{let e=window.setTimeout(()=>m(i),300);return()=>window.clearTimeout(e)},[i]);let h=l({queryKey:[`library-purge-preview`,p,d],queryFn:()=>a.previewLibraryPurge(p,d),enabled:p>=1}),g=u({mutationFn:()=>a.executeLibraryPurge(i,d),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,R.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!g.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,g.isPending]);let _=h.data,y=_?.count??0,b=_?.total_bytes??0,x=y>0&&!g.isPending;return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,z.jsx)(de,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,z.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:g.isPending,children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>s(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,z.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,z.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,z.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,z.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,z.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:h.isLoading||h.isFetching?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):h.isError?(0,z.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:h.error?.message??t(`libraryPurge.previewFailed`)}):(0,z.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,z.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:y,size:oe(b)})}),_?.sample_filenames&&_.sample_filenames.length>0&&(0,z.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[_.sample_filenames.map(e=>(0,z.jsx)(`li`,{className:`truncate`,children:e},e)),y>_.sample_filenames.length&&(0,z.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:y-_.sample_filenames.length})})]})]})}),(0,z.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,z.jsx)(re,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,z.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,z.jsx)(P,{variant:`secondary`,onClick:e,disabled:g.isPending,children:t(`common.cancel`)}),(0,z.jsx)(P,{variant:`danger`,disabled:!x,onClick:()=>g.mutate(),children:g.isPending?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(j,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:y})})]})]})})}var qc=(0,R.lazy)(()=>I(()=>import(`./PdfPreviewModal-DSim_AJc.js`).then(e=>({default:e.PdfPreviewModal})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]))),Jc=(0,R.lazy)(()=>I(()=>import(`./SpreadsheetPreviewModal-DSTZsH_X.js`).then(e=>({default:e.SpreadsheetPreviewModal})),__vite__mapDeps([29,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,30,26,27,28]))),Yc=(0,R.lazy)(()=>I(()=>import(`./ImagePreviewModal-kbbJSk44.js`).then(e=>({default:e.ImagePreviewModal})),__vite__mapDeps([31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28])));function Xc(e){return e===`csv`||e===`xlsx`||e===`ods`}function Zc(e){return e===`step`||e===`stp`}var Qc=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`tiff`,`tif`]),$c=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`]);function el(e){return Qc.has(e.toLowerCase())}function tl(e){return $c.has(e.toLowerCase())}function nl({fileType:e,className:t}){return(0,z.jsx)(e===`pdf`?Re:Xc(e)?C:el(e)?Fe:S,{className:t})}function rl(e){return{results:e,files:e.flatMap(e=>e.data??[])}}function il(e){let t=e.file_type;return Ze(e)||t===`3mf`||t===`stl`||Zc(t)||t===`pdf`||Xc(t)||tl(t)}var al={onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation()};function ol(e){return Ze(e)||e.file_type===`3mf`||e.file_type===`stl`||Zc(e.file_type)}function sl(e){return e===`pdf`?(0,z.jsx)(Re,{className:`w-4 h-4`}):Xc(e)?(0,z.jsx)(C,{className:`w-4 h-4`}):(0,z.jsx)(Fe,{className:`w-4 h-4`})}function cl(e){return e===`stl`||e===`pdf`}function ll(e){return e===`3mf`?`bg-bambu-green/20 text-bambu-green`:e===`gcode`||e===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:e===`stl`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`:Zc(e)?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:e===`pdf`?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:Xc(e)?`bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400`:`bg-bambu-gray/20 text-bambu-gray`}function ul(e,t){let n=[...e],r=t.query?.trim().toLowerCase();r&&(n=n.filter(e=>e.filename.toLowerCase().includes(r)||e.print_name&&e.print_name.toLowerCase().includes(r))),t.filterType!==`all`&&(n=n.filter(e=>e.file_type===t.filterType));let i=t.filterUsername.trim().toLowerCase();return i&&(n=n.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(i))),n.sort((e,n)=>{let r=0;switch(t.sortField){case`name`:r=(e.print_name||e.filename).localeCompare(n.print_name||n.filename);break;case`date`:r=(le(e.fs_modified_at??e.created_at)?.getTime()??0)-(le(n.fs_modified_at??n.created_at)?.getTime()??0);break;case`size`:r=e.file_size-n.file_size;break;case`type`:r=e.file_type.localeCompare(n.file_type);break;case`prints`:r=e.print_count-n.print_count;break}return t.sortDirection===`asc`?r:-r}),n}var dl=e=>e?`grid-cols-[24px_minmax(240px,1fr)_120px_100px_100px_100px_minmax(96px,200px)_220px]`:`grid-cols-[24px_minmax(240px,1fr)_100px_100px_100px_minmax(96px,200px)_220px]`,fl=`min-w-min`;function pl({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,R.useState)(``);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,z.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,z.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!a.trim()||r,children:r?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function ml({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,R.useState)(``),[o,s]=(0,R.useState)(``),[c,l]=(0,R.useState)(!0),[u,d]=(0,R.useState)(!1);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(it,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,z.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,z.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,z.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var hl=`<>:"/\\|?*`;function gl(e){for(let t of e)if(hl.includes(t)||t.charCodeAt(0)<32)return t;return null}function _l({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,R.useState)(s),u=e===`file`?gl(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,z.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,z.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,z.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,z.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,z.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function vl({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,R.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t,canWrite:r.can_write!==!1}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0,canWrite:!0},...l(e)];return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,z.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n||!e.canWrite,title:e.canWrite?void 0:o(`fileManager.folderNotWritable`),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n||!e.canWrite?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,z.jsx)(Ie,{className:`w-4 h-4`}),e.name,e.id===n&&(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,z.jsx)(P,{onClick:()=>i(s),disabled:a,children:a?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function yl({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[o,s]=(0,R.useState)(`project`),[c,u]=(0,R.useState)(e.project_id||e.archive_id||null);(0,R.useState)(()=>{e.archive_id&&s(`archive`)});let{data:d}=l({queryKey:[`projects`],queryFn:()=>a.getProjects(),select:t=>F([...t].sort((e,t)=>e.name.localeCompare(t.name)),e.project_id)}),{data:f}=l({queryKey:[`archives-for-link`],queryFn:()=>a.getArchives(void 0,void 0,100)}),p=()=>{n(o===`project`?{project_id:c,archive_id:0}:{project_id:0,archive_id:c})},h=()=>{n({project_id:0,archive_id:0})},g=e.project_id||e.archive_id;return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(A,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,z.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,z.jsx)(ae,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(`button`,{onClick:()=>{s(`project`),u(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${o===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(m,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,z.jsxs)(`button`,{onClick:()=>{s(`archive`),u(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${o===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(he,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,z.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:o===`project`?d&&d.length>0?d.map(e=>(0,z.jsxs)(`button`,{onClick:()=>u(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${c===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,z.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):f&&f.length>0?f.map(e=>(0,z.jsxs)(`button`,{onClick:()=>u(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${c===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,z.jsx)(S,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,z.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[g&&(0,z.jsxs)(P,{variant:`danger`,onClick:h,disabled:r,children:[(0,z.jsx)(ie,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,z.jsxs)(`div`,{className:`flex gap-2 ${g?``:`ml-auto`}`,children:[(0,z.jsx)(P,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,z.jsx)(P,{onClick:p,disabled:!c||r,children:r?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function bl({folder:e,onDelete:t,onLink:n,onRename:r,onToggleShared:i,hasPermission:a,revealOnHover:o=!1,tabIndex:s,t:c}){let[l,u]=(0,R.useState)(null),d=(0,R.useRef)(null),f=(0,R.useRef)(null),p=()=>{u(null),d.current?.contains(document.activeElement)&&f.current?.focus()},m=e.children.length>0,h=e.project_id||e.archive_id,g=e.is_external,_=e.can_delete??(a(`library:delete_all`)||a(`library:delete_own`)&&e.file_count===0&&!m&&!g&&!h),v=_?void 0:a(`library:delete_own`)&&!g&&!h?c(`fileManager.onlyOwnFoldersDeletable`):c(`fileManager.noPermissionDeleteFolder`),y=e.can_rename??a(`library:update_all`),b=a(`library:update_all`),S=[{label:c(`common.rename`),icon:(0,z.jsx)(ue,{className:`w-3.5 h-3.5`}),onClick:()=>r(e),disabled:!y,title:y?void 0:c(`fileManager.noPermissionRenameFolder`)},{label:c(h?`fileManager.changeLink`:`fileManager.linkTo`),icon:(0,z.jsx)(A,{className:`w-3.5 h-3.5`}),onClick:()=>n(e),disabled:!b,title:b?void 0:c(`fileManager.noPermissionLinkFolder`)},...i&&b?[{label:e.shared?c(`fileManager.unshareFolder`):c(`fileManager.shareFolder`),icon:(0,z.jsx)(pe,{className:`w-3.5 h-3.5`}),onClick:()=>i(e),title:c(`fileManager.shareFolderHint`)}]:[],{label:c(`common.delete`),icon:(0,z.jsx)(de,{className:`w-3.5 h-3.5`}),onClick:()=>t(e.id),danger:!0,disabled:!_,title:v}];return(0,z.jsxs)(`div`,{ref:d,className:`relative flex-shrink-0 flex items-center transition-opacity ${o&&!l?`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`:``}`,"data-folder-actions":!0,onClick:e=>e.stopPropagation(),onKeyDown:e=>{l&&(e.key===`ArrowUp`||e.key===`ArrowDown`)&&p()},children:[(0,z.jsx)(`button`,{ref:f,type:`button`,tabIndex:s,onClick:e=>{if(l){p();return}let t=e.currentTarget.getBoundingClientRect();u({x:t.left,y:t.bottom+4})},className:`p-1 rounded hover:bg-bambu-dark-tertiary`,title:c(`common.actions`),children:(0,z.jsx)(x,{className:`w-3.5 h-3.5 text-bambu-gray`})}),l&&(0,z.jsx)(T,{x:l.x,y:l.y,items:S,onClose:p,anchorRef:f})]})}function xl({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,onToggleShared:o,depth:s=0,wrapNames:c=!1,defaultExpanded:l=!0,showModified:u=!1,hasPermission:d,t:f}){let[p,h]=(0,R.useState)(l),g=e.children.length>0,_=e.project_id||e.archive_id,v=e.is_external;return(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+s*12}px`},onClick:()=>n(e.id),children:[g?(0,z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h(!p)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,z.jsx)(_e,{className:`w-3.5 h-3.5 transition-transform ${p?`rotate-90`:``}`})}):(0,z.jsx)(`div`,{className:`w-4.5`}),v?(0,z.jsx)(it,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,z.jsx)(Ie,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`span`,{className:`block text-sm ${c?`break-all`:`truncate`}`,title:e.name,children:e.name}),u&&e.latest_activity_at&&(0,z.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:f(`fileManager.lastActivity`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:se(e.latest_activity_at)})]})]}),_&&(0,z.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,z.jsx)(A,{className:`w-3 h-3`}),e.project_name?(0,z.jsx)(m,{className:`w-3 h-3`}):(0,z.jsx)(he,{className:`w-3 h-3`})]}),e.shared&&(0,z.jsx)(`span`,{title:f(`fileManager.sharedFolder`),children:(0,z.jsx)(pe,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})}),v&&e.external_readonly&&(0,z.jsx)(`span`,{title:f(`fileManager.readOnly`),children:(0,z.jsx)(M,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,z.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!_&&!v&&(0,z.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:f(`fileManager.linkToProjectOrArchive`),children:(0,z.jsx)(A,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,z.jsx)(bl,{folder:e,onDelete:r,onLink:i,onRename:a,onToggleShared:o,hasPermission:d,revealOnHover:!c,t:f})]}),g&&p&&(0,z.jsx)(`div`,{children:e.children.map(e=>(0,z.jsx)(xl,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,onToggleShared:o,depth:s+1,wrapNames:c,defaultExpanded:l,showModified:u,hasPermission:d,t:f},e.id))})]})}function Sl({file:e,isSelected:t,onSelect:n,onDelete:r,onDownload:i,onPrint:o,onSlice:s,onOpenInSlicer:c,onRunPipeline:l,useSlicerApi:u,desktopSlicer:d,canSlice:f,onPreview:m,onRename:h,onDetails:g,onGenerateThumbnail:v,onTagClick:b,thumbnailVersion:S,hasPermission:C,canModify:w,authEnabled:E,showModified:D,t:O}){let[k,A]=(0,R.useState)(null),ee=C(`library:read`),j=w(`library`,`update`,e.created_by_id),M=w(`library`,`delete`,e.created_by_id),N=[];if(o&&Ze(e)&&N.push({label:O(`common.print`),icon:(0,z.jsx)(me,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>o(e),disabled:!C(`queue:create`),title:C(`queue:create`)?void 0:O(`fileManager.noPermissionAddToQueue`)}),Qe(e,!!u,d)&&(u?s:c)&&N.push({label:O(`slice.action`),icon:u?(0,z.jsx)(y,{className:`w-4 h-4`}):(0,z.jsx)(fe,{className:`w-4 h-4`}),onClick:()=>{u?s?.(e):c?.(e)},disabled:!f,title:f?void 0:O(u?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`)}),l&&u&&Qe(e,!0,d)&&N.push({label:O(`library.runWithPipeline.actionLabel`),icon:(0,z.jsx)(te,{className:`w-4 h-4`}),onClick:()=>l(e),disabled:!C(`pipelines:run`),title:C(`pipelines:run`)?void 0:O(`library.runWithPipeline.noPermission`)}),m&&il(e)){let t=ol(e);N.push({label:O(t?`fileManager.preview3d`:`fileManager.preview.open`),icon:t?(0,z.jsx)(p,{className:`w-4 h-4`}):sl(e.file_type),onClick:()=>m(e),disabled:!ee,title:ee?void 0:O(`fileManager.noPermissionPreview`)})}return N.push({label:O(`common.download`),icon:(0,z.jsx)(Le,{className:`w-4 h-4`}),onClick:()=>i(e.id),disabled:!C(`library:read`),title:C(`library:read`)?void 0:O(`fileManager.noPermissionDownload`)}),h&&N.push({label:O(`common.rename`),icon:(0,z.jsx)(ue,{className:`w-4 h-4`}),onClick:()=>h(e),disabled:!j,title:j?void 0:O(`fileManager.noPermissionRenameFile`)}),g&&N.push({label:O(`fileManager.details.title`),icon:(0,z.jsx)(_,{className:`w-4 h-4`}),onClick:()=>g(e),disabled:!ee,title:ee?void 0:O(`fileManager.noPermissionPreview`)}),e.external_url&&N.push({label:O(`fileManager.details.openLink`),icon:(0,z.jsx)(Me,{className:`w-4 h-4`}),onClick:()=>window.open(e.external_url,`_blank`,`noopener,noreferrer`)}),v&&cl(e.file_type)&&N.push({label:O(`fileManager.generateThumbnail`),icon:(0,z.jsx)(Fe,{className:`w-4 h-4`}),onClick:()=>v(e),disabled:!j,title:j?void 0:O(`fileManager.noPermissionGenerateThumbnail`)}),N.push({label:O(`common.delete`),icon:(0,z.jsx)(de,{className:`w-4 h-4`}),onClick:()=>r(e.id),danger:!0,disabled:!M,title:M?void 0:O(`fileManager.noPermissionDeleteFile`)}),(0,z.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>n(e.id),onDoubleClick:()=>m?.(e),children:[(0,z.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden rounded-t-lg`,children:[e.thumbnail_path?(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(e.id)}${S?(a.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${S}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,z.jsx)(nl,{fileType:e.file_type,className:`w-12 h-12 text-bambu-gray/30`}),(0,z.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:Zc(e.file_type)?`bg-amber-500/90 text-white`:e.file_type===`pdf`?`bg-red-500/90 text-white`:Xc(e.file_type)?`bg-teal-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,z.jsxs)(`div`,{className:`p-3`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{children:oe(e.file_size)}),e.print_time_seconds&&(0,z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(ve,{className:`w-3 h-3`}),ce(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,z.jsx)(me,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,z.jsx)(je,{className:`w-3 h-3`}),O(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,z.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:O(`fileManager.printedCount`,{count:e.print_count})}),(e.external_url||e.has_notes||(e.photo_count??0)>0)&&(0,z.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-xs text-bambu-gray`,...al,children:[e.external_url&&(0,z.jsx)(`a`,{href:e.external_url,target:`_blank`,rel:`noopener noreferrer`,className:`p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.openLink`),"aria-label":O(`fileManager.details.openLink`),children:(0,z.jsx)(Me,{className:`w-3.5 h-3.5`})}),e.has_notes&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>g?.(e),className:`p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.hasNotes`),"aria-label":O(`fileManager.details.hasNotes`),children:(0,z.jsx)(ne,{className:`w-3.5 h-3.5`})}),(e.photo_count??0)>0&&(0,z.jsxs)(`button`,{type:`button`,onClick:()=>g?.(e),className:`flex items-center gap-0.5 p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.photoCount`,{count:e.photo_count}),"aria-label":O(`fileManager.details.photoCount`,{count:e.photo_count}),children:[(0,z.jsx)(be,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.photo_count})]})]}),E&&e.created_by_username&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,z.jsx)(ye,{className:`w-3 h-3`}),e.created_by_username]}),D&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:O(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3`}),se(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,...al,children:e.tags.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>b?.(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,z.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`,...al,children:[(0,z.jsx)(`button`,{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();A({x:t.left,y:t.bottom+4})},className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,z.jsx)(x,{className:`w-4 h-4 text-bambu-gray`})}),k&&(0,z.jsx)(T,{x:k.x,y:k.y,items:N,onClose:()=>A(null)})]}),(0,z.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:t&&(0,z.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function Cl({file:e,onPrint:t,onSlice:n,onOpenInSlicer:r,onRunPipeline:i,useSlicerApi:a,desktopSlicer:o,canSlice:s,onPreview:c,onDetails:l,onDownload:u,onRename:d,onGenerateThumbnail:f,thumbnailPending:m,onDelete:h,hasPermission:g,canModify:v,tabIndex:b,t:x}){let S=v(`library`,`update`,e.created_by_id),C=v(`library`,`delete`,e.created_by_id);return(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,"data-file-actions":!0,...al,children:[Ze(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`queue:create`)&&t(e),className:`p-1.5 rounded transition-colors ${g(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`queue:create`)?x(`common.print`):x(`fileManager.noPermissionAddToQueue`),disabled:!g(`queue:create`),children:(0,z.jsx)(me,{className:`w-4 h-4`})}),Qe(e,a,o)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>{s&&(a?n:r)(e)},className:`p-1.5 rounded transition-colors ${s?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(s?`slice.action`:a?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`),disabled:!s,children:a?(0,z.jsx)(y,{className:`w-4 h-4`}):(0,z.jsx)(fe,{className:`w-4 h-4`})}),a&&Qe(e,!0,o)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`pipelines:run`)&&i(e),className:`p-1.5 rounded transition-colors ${g(`pipelines:run`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`pipelines:run`)?x(`library.runWithPipeline.actionLabel`):x(`library.runWithPipeline.noPermission`),disabled:!g(`pipelines:run`),children:(0,z.jsx)(te,{className:`w-4 h-4`})}),ol(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&c(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.preview3d`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:(0,z.jsx)(p,{className:`w-4 h-4`})}),!ol(e)&&il(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&c(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.preview.open`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:sl(e.file_type)}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&u(e.id),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`common.download`):x(`fileManager.noPermissionDownload`),disabled:!g(`library:read`),children:(0,z.jsx)(Le,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&l(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.details.title`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:(0,z.jsx)(_,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>S&&d(e),className:`p-1.5 rounded transition-colors ${S?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(S?`common.rename`:`fileManager.noPermissionRenameFile`),disabled:!S,children:(0,z.jsx)(ue,{className:`w-4 h-4`})}),cl(e.file_type)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>S&&f(e),className:`p-1.5 rounded transition-colors ${S?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(S?`fileManager.generateThumbnail`:`fileManager.noPermissionGenerateThumbnail`),disabled:m||!S,children:(0,z.jsx)(Fe,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>C&&h(e.id),className:`p-1.5 rounded transition-colors ${C?`hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(C?`common.delete`:`fileManager.noPermissionDeleteFile`),disabled:!C,children:(0,z.jsx)(de,{className:`w-4 h-4`})})]})}function wl({file:e,isSelected:t,isFocused:n,showModified:r,thumbnailVersion:i,onSelect:o,onOpen:s,actionProps:c,t:l}){let u=a.getLibraryFileThumbnailUrl(e.id);return(0,z.jsxs)(`div`,{"data-file-id":e.id,onClick:()=>o(e),onDoubleClick:()=>s(e),className:`group flex items-center gap-3 px-3 py-2 cursor-pointer transition-colors ${t?`bg-bambu-green/10`:`hover:bg-bambu-dark`} ${n?`ring-1 ring-inset ring-bambu-green/60`:``}`,title:e.print_name||e.filename,children:[(0,z.jsx)(`div`,{className:`w-4 h-4 rounded border-2 flex-shrink-0 flex items-center justify-center ${t?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:t&&(0,z.jsx)(`div`,{className:`w-1.5 h-1.5 bg-white rounded-sm`})}),(0,z.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,z.jsx)(`img`,{src:`${u}${i?(u.includes(`?`)?`&`:`?`)+`v=${i}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,z.jsx)(nl,{fileType:e.file_type,className:`w-5 h-5 text-bambu-gray/50`})}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`div`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{className:`px-1.5 py-px rounded font-medium ${ll(e.file_type)}`,children:e.file_type.toUpperCase()}),(0,z.jsx)(`span`,{children:oe(e.file_size)}),e.print_count>0&&(0,z.jsxs)(`span`,{children:[e.print_count,`x`]}),r&&(0,z.jsxs)(`span`,{className:`flex items-center gap-1 truncate`,title:l(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),se(e.fs_modified_at??e.created_at)]})]})]}),(0,z.jsx)(`div`,{className:`flex-shrink-0 transition-opacity ${n||t?``:`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:(0,z.jsx)(Cl,{file:e,...c,tabIndex:n?0:-1})})]})}function Tl(){let{t:e}=o(),t=c(),{showToast:n}=v(),{hasPermission:r,hasAnyPermission:i,canModify:s,authEnabled:f}=ze(),[p]=De(),m=Ee(),h=p.get(`folder`),[g,_]=(0,R.useState)(h?parseInt(h,10):null),[y,x]=(0,R.useState)(`internal`),[C,T]=(0,R.useState)([]),[te,ie]=(0,R.useState)(!1),[ce,le]=(0,R.useState)(!1),[ue,fe]=(0,R.useState)(!1),[F,I]=(0,R.useState)(!1),[he,ve]=(0,R.useState)([]),[Te,Pe]=(0,R.useState)(!1),[Le,Re]=(0,R.useState)(!1),[Be,Ve]=(0,R.useState)(!1),[We,qe]=(0,R.useState)([]),[Je,Ye]=(0,R.useState)(null),[ot,st]=(0,R.useState)(null),[ct,ut]=(0,R.useState)(null),[dt,pt]=(0,R.useState)(null),[ht,gt]=(0,R.useState)(!1),[_t,vt]=(0,R.useState)(null),[yt,bt]=(0,R.useState)(null),[xt,St]=(0,R.useState)(null),[Ct,wt]=(0,R.useState)({}),[Tt,B]=(0,R.useState)(null),[Et,Dt]=(0,R.useState)(null),[V,H]=(0,R.useState)(null),[Ot,U]=(0,R.useState)(null),[W,kt]=(0,R.useState)(null),[G,At]=(0,R.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),jt=(0,R.useRef)(null),[K,Mt]=(0,R.useState)(null),[Nt,Pt]=(0,R.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[Ft,It]=(0,R.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[Lt,Rt]=(0,R.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[zt,Bt]=(0,R.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[Vt,Ht]=(0,R.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[Ut,Wt]=(0,R.useState)(!1),Gt=(0,R.useRef)(null);(0,R.useEffect)(()=>{if(!Ut)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Gt.current)return;let t=Gt.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;Ht(Math.min(500,Math.max(200,n)))},t=()=>{Wt(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(Vt))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[Ut,Vt]);let[Kt,qt]=(0,R.useState)(``),[Jt,Yt]=(0,R.useState)(`all`),[Xt,Zt]=(0,R.useState)(``),[Qt,$t]=(0,R.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[en,tn]=(0,R.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[nn,rn]=(0,R.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`);(0,R.useEffect)(()=>{let e=p.get(`folder`);e&&_(parseInt(e,10))},[p]);let{data:an}=l({queryKey:[`settings`],queryFn:()=>a.getSettings()}),on=Ke(an?.open_in_slicer,an?.preferred_slicer),sn=(0,R.useCallback)(async t=>{try{let{token:e}=await a.createLibrarySlicerToken(t.id),n=a.getLibrarySlicerDownloadUrl(t.id,e,t.filename);Ge(`${window.location.origin}${n}`,on)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=a.getLibraryFileDownloadUrl(t.id);Ge(`${window.location.origin}${r}`,on)}},[on,n,e]),cn=(0,R.useCallback)(()=>an?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[an?.use_slicer_api,r,i]),{data:ln,isLoading:un}=l({queryKey:[`library-folders`],queryFn:()=>a.getLibraryFolders()}),q=(0,R.useMemo)(()=>{if(!ln)return ln;let e=t=>[...t].sort((e,t)=>{let n=0;if(Lt===`name`)n=e.name.localeCompare(t.name);else{let r=e.latest_activity_at?new Date(e.latest_activity_at).getTime():null,i=t.latest_activity_at?new Date(t.latest_activity_at).getTime():null;if(r===null&&i===null)n=e.name.localeCompare(t.name);else if(r===null)return 1;else if(i===null)return-1;else n=r-i}return zt===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(ln)},[ln,Lt,zt]),{data:dn}=l({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await a.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),fn=g!==null&&Kt.trim().length>0,pn=(0,R.useMemo)(()=>[...We].sort((e,t)=>e-t),[We]),{data:mn=[]}=l({queryKey:[`library-tags`],queryFn:a.getLibraryTags}),hn=(0,R.useMemo)(()=>{let e=new Map;for(let t of mn)e.set(t.id,t.name);return e},[mn]);(0,R.useEffect)(()=>{mn.length!==0&&qe(e=>{let t=e.filter(e=>hn.has(e));return t.length===e.length?e:t})},[mn.length,hn]);let gn=(0,R.useCallback)(e=>{qe(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),_n=Kt.trim().length>0||We.length>0,vn=G===`columns`&&g===null&&!_n,{data:yn,isLoading:bn}=l({queryKey:[`library-files`,g,y,fn,pn,vn],queryFn:()=>a.getLibraryFiles(g,vn,void 0,g===null?y:void 0,fn,pn)}),{data:xn}=l({queryKey:[`library-stats`],queryFn:()=>a.getLibraryStats()}),{data:Sn}=l({queryKey:[`users`,`slim`],queryFn:()=>a.getUsersSlim()}),Cn=(0,R.useMemo)(()=>{if(!yn)return[];let e=new Set(yn.map(e=>e.file_type));return Array.from(e).sort()},[yn]),J=(0,R.useMemo)(()=>ul(yn??[],{query:Kt,filterType:Jt,filterUsername:Xt,sortField:Qt,sortDirection:en}),[yn,Kt,Jt,Xt,Qt,en]),wn=(0,R.useMemo)(()=>{if(!xn||!an)return!1;let e=(an.library_disk_warning_gb||5)*1024*1024*1024;return xn.disk_free_bytesa.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),ie(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),En=u({mutationFn:async e=>{let t=await a.createExternalFolder(e);return await a.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),le(!1),_(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Dn=u({mutationFn:e=>a.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),On=u({mutationFn:e=>a.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),g===ot?.id&&_(null),st(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{st(null),n(e.message,`error`)}}),kn=u({mutationFn:e=>a.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),T(e=>e.filter(e=>e!==ot?.id)),st(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{st(null),n(e.message,`error`)}}),An=u({mutationFn:e=>a.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),T([])},onError:e=>n(e.message,`error`)}),jn=u({mutationFn:e=>a.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),T([]),st(null)},onError:e=>{st(null),n(e.message,`error`)}}),Mn=u({mutationFn:({fileIds:e,folderId:t})=>a.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),T([]),fe(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),Nn=u({mutationFn:({id:e,data:t})=>a.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),Ye(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Pn=u({mutationFn:({id:e,filename:t})=>a.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),St(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{St(null),n(e.message,`error`)}}),Fn=u({mutationFn:({id:e,name:t})=>a.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),St(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{St(null),n(e.message,`error`)}}),In=u({mutationFn:({id:e,shared:t})=>a.updateLibraryFolder(e,{shared:t}),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),n(i.shared?e(`fileManager.toast.folderShared`):e(`fileManager.toast.folderUnshared`),`success`)},onError:e=>n(e.message,`error`)}),Ln=e=>In.mutate({id:e.id,shared:!e.shared}),Rn=u({mutationFn:()=>a.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),wt(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),zn=u({mutationFn:e=>a.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&wt(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),Bn=(0,R.useCallback)(e=>{r(`library:read`)&&(Ze(e)?m(`/gcode-viewer?library_file=${e.id}`):e.file_type===`3mf`||e.file_type===`stl`||Zc(e.file_type)?B(e):e.file_type===`pdf`?Dt(e):Xc(e.file_type)?H(e):tl(e.file_type)&&kt(e))},[r,m]),Vn=(0,R.useCallback)(e=>{T(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Hn=(0,R.useCallback)(()=>{if(J.length>0){let e=J.map(e=>e.id);T(t=>G===`columns`?[...new Set([...t,...e])]:e)}},[J,G]),Un=J.length>0&&J.every(e=>C.includes(e.id)),Wn=(0,R.useCallback)(()=>{T([])},[]),Gn=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},Y=(0,R.useMemo)(()=>{if(!g||!ln)return null;let e=t=>{for(let n of t){if(n.id===g)return n;let t=e(n.children);if(t)return t}return null};return e(ln)},[g,ln]),Kn=Y?.can_write!==!1,qn=r(`library:upload`)&&Kn,Jn=r(`library:upload`)?Kn?void 0:e(`fileManager.folderNotWritable`):void 0,{isDraggingOver:Yn,dragHandlers:Xn}=He({disabled:!qn||F,onFiles:e=>{ve(e),I(!0)}}),Zn=(0,R.useCallback)(e=>{if(!e.thumbnail_path&&s(`library`,`update`,e.created_by_id))return n=>{a.uploadLibraryPreviewThumbnail(e.id,n).then(n=>{n.updated&&(wt(t=>({...t,[e.id]:(t[e.id]||0)+1})),t.invalidateQueries({queryKey:[`library-files`]}))}).catch(()=>{})}},[s,t]),Qn=e=>{a.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},$n=()=>{ot&&(ot.type===`file`?kn.mutate(ot.id):ot.type===`folder`?On.mutate(ot.id):ot.type===`bulk`&&jn.mutate(C))},er=On.isPending||kn.isPending||jn.isPending,tr=e=>{At(e),localStorage.setItem(`library-view-mode`,e)},nr={onPrint:ut,onSlice:pt,onOpenInSlicer:sn,onRunPipeline:bt,useSlicerApi:an?.use_slicer_api??!1,desktopSlicer:on,canSlice:cn(),onPreview:Bn,onDetails:U,onDownload:Qn,onRename:e=>St({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>zn.mutate(e.id),thumbnailPending:zn.isPending,onDelete:e=>st({type:`file`,id:e}),hasPermission:r,canModify:s,t:e},rr=un||bn,ir=(0,R.useMemo)(()=>{if(!q||g===null)return[];let e=[],t=n=>{for(let r of n){if(e.push(r),r.id===g||t(r.children))return!0;e.pop()}return!1};return t(q),e},[q,g]),ar=ir.length>0?!!ir[0].is_external:y===`external`,X=(0,R.useMemo)(()=>{let e=[{key:`root`,folderId:null,items:(q??[]).filter(e=>!!e.is_external===ar),activeId:ir[0]?.id??null}];return ir.forEach((t,n)=>{t.children.length>0&&e.push({key:`folder-${t.id}`,folderId:t.id,items:t.children,activeId:ir[n+1]?.id??null})}),e},[q,ir,ar]),Z=(0,R.useMemo)(()=>G!==`columns`||_n?[]:X.filter(e=>e.folderId!==g).map(e=>({key:e.key,folderId:e.folderId,scope:e.folderId===null?ar?`external`:`internal`:void 0})),[G,_n,X,g,ar]),Q=d({combine:rl,queries:Z.map(e=>({queryKey:[`library-files`,`column`,e.folderId,e.scope??null],queryFn:()=>a.getLibraryFiles(e.folderId,e.folderId===null,void 0,e.scope,!1,[])}))}),or=new Map;Z.forEach((e,t)=>{let n=Q.results[t];or.set(e.key,{files:ul(n?.data??[],{filterType:Jt,filterUsername:Xt,sortField:Qt,sortDirection:en}),loading:!!n?.isPending})});let sr=(0,R.useMemo)(()=>{let e=new Map;for(let t of[...yn??[],...Q.files])e.set(t.id,t);return e},[yn,Q.files]),cr=(0,R.useMemo)(()=>{if(C.length!==1)return null;let e=sr.get(C[0]);return e&&il(e)?e:null},[sr,C]),lr=(0,R.useMemo)(()=>C.map(e=>sr.get(e)).filter(e=>!!e&&Ze(e)),[sr,C]),$=(0,R.useMemo)(()=>{let e=C.map(e=>sr.get(e)).filter(e=>!!e&&e.filename.toLowerCase().endsWith(`.stl`));return e.length===C.length?e:[]},[sr,C]),{data:ur}=l({queryKey:[`variant-group`,ct?.variant_group_id],queryFn:()=>a.getVariantGroup(ct.variant_group_id),enabled:!!ct?.variant_group_id}),dr=(0,R.useMemo)(()=>{if(ct){if(lr.length>1)return lr.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(ur&&ur.members.length>1)return ur.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[ct,lr,ur]),fr=K===null?void 0:Z.map(e=>or.get(e.key)?.files).find(e=>e?.some(e=>e.id===K)),pr=fr??J;(0,R.useEffect)(()=>{G===`columns`&&jt.current?.focus({preventScroll:!0})},[G]),(0,R.useEffect)(()=>{Mt(null)},[g,G]),(0,R.useEffect)(()=>{T([])},[g]),(0,R.useEffect)(()=>{G!==`columns`||g===null||jt.current?.querySelector(`[data-folder-id="${g}"]`)?.scrollIntoView?.({block:`nearest`})},[g,G]),(0,R.useEffect)(()=>{G!==`columns`||K===null||jt.current?.querySelector(`[data-file-id="${K}"]`)?.scrollIntoView?.({block:`nearest`})},[K,G]);let mr=()=>{let e=jt.current;if(e){if(K!==null)e.querySelector(`[data-file-id="${K}"] [data-file-actions] button:not([disabled])`)?.focus();else if(g!==null){let t=e.querySelector(`[data-folder-id="${g}"] [data-folder-actions] button`);t?.focus(),t?.click()}}},hr=e=>{if(e.ctrlKey||e.metaKey||e.altKey)return;let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.tagName===`SELECT`||t.isContentEditable)return;if(t.closest(`[data-folder-actions]`)){if(e.key===`Escape`){e.preventDefault(),jt.current?.focus({preventScroll:!0});return}if(e.key!==`ArrowUp`&&e.key!==`ArrowDown`)return;jt.current?.focus({preventScroll:!0})}let n=t.closest(`[data-file-actions]`);if(n){if(e.key===`Enter`||e.key===` `)return;if(e.key===`ArrowLeft`||e.key===`ArrowRight`){e.preventDefault();let r=Array.from(n.querySelectorAll(`button:not([disabled])`));r[r.indexOf(t)+(e.key===`ArrowRight`?1:-1)]?.focus();return}if(e.key===`Escape`){e.preventDefault(),jt.current?.focus({preventScroll:!0});return}(e.key===`ArrowUp`||e.key===`ArrowDown`)&&jt.current?.focus({preventScroll:!0})}if(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey){e.preventDefault(),mr();return}let r=K!==null,i=ir[ir.length-1];switch(e.key){case`ArrowDown`:case`ArrowUp`:{e.preventDefault();let t=e.key===`ArrowDown`?1:-1;if(r||_n){let e=pr.findIndex(e=>e.id===K),n=pr[e+t];n?Mt(n.id):t===-1&&e===0&&fr&&Mt(null)}else if(g===null)t===1&&X[0].items.length>0&&_(X[0].items[0].id);else{let e=X[ir.length-1],n=e?e.items.findIndex(e=>e.id===g):-1,r=n===-1?void 0:e.items[n+t];if(r)_(r.id);else if(t===1&&n!==-1){let t=e?or.get(e.key)?.files:void 0;t?.length&&Mt(t[0].id)}}break}case`ArrowRight`:if(e.preventDefault(),r)break;!_n&&i&&i.children.length>0?_(i.children[0].id):J.length>0&&Mt(J[0].id);break;case`ArrowLeft`:if(e.preventDefault(),r){Mt(null);break}if(_n)break;ir.length>1?_(ir[ir.length-2].id):ir.length===1?(x(ir[0].is_external?`external`:`internal`),_(null)):g!==null&&_(null);break;case`Enter`:{if(e.preventDefault(),!r){!_n&&i&&i.children.length>0?_(i.children[0].id):J.length>0&&Mt(J[0].id);break}let t=pr.find(e=>e.id===K);t&&Bn(t);break}case` `:if(e.preventDefault(),!r)break;K!==null&&Vn(K);break}};return(0,z.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-screen flex flex-col relative`,...Xn,children:[Yn&&(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,z.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,z.jsx)(Ne,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(Ie,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,z.jsx)(`button`,{onClick:()=>tr(`grid`),className:`p-1.5 rounded transition-colors ${G===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,z.jsx)(k,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{onClick:()=>tr(`list`),className:`p-1.5 rounded transition-colors ${G===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,z.jsx)(ee,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{onClick:()=>tr(`columns`),className:`p-1.5 rounded transition-colors ${G===`columns`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.columnsView`),children:(0,z.jsx)(b,{className:`w-4 h-4`})})]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Rn.mutate(),disabled:Rn.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[Rn.isPending?(0,z.jsx)(j,{className:`w-4 h-4 mr-2 animate-spin`}):(0,z.jsx)(Fe,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>le(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,z.jsx)(it,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>ie(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionCreateFolder`),children:[(0,z.jsx)(rt,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Re(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,z.jsx)(xe,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Pe(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,z.jsx)(de,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,z.jsxs)(Se,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,z.jsx)(de,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof dn==`number`&&dn>0&&(0,z.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:dn})]}),(0,z.jsxs)(P,{onClick:()=>I(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionUpload`),children:[(0,z.jsx)(Ne,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),wn&&xn&&an&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,z.jsx)(re,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1`,children:[(0,z.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,z.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:oe(xn.disk_free_bytes),total:oe(xn.disk_total_bytes),threshold:an.library_disk_warning_gb})})]})]}),xn&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(w,{className:`w-4 h-4 text-bambu-green`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:xn.total_files})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(Ie,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:xn.total_folders})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(O,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:oe(xn.total_size_bytes)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,z.jsx)(`span`,{className:`font-medium ${wn?`text-amber-500`:`text-white`}`,children:oe(xn.disk_free_bytes)})]})]}),(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,z.jsx)(`div`,{className:`lg:hidden`,children:(0,z.jsxs)(`select`,{value:g===null?`__top:${y}`:String(g),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(_(null),x(t.slice(6))):_(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),ln?.some(e=>e.is_external)&&(0,z.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),q&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(q).map(e=>(0,z.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,z.jsxs)(`div`,{ref:Gt,"data-testid":`folder-sidebar`,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${Vt}px`},children:[(0,z.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${Ut?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),Wt(!0)},onDoubleClick:()=>{Ht(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,z.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${Ut?`opacity-100`:``}`,children:[(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,z.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,z.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsxs)(`select`,{value:Lt,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;Rt(t),localStorage.setItem(`library-folder-sort-field`,t)},className:`text-xs px-1 py-0.5 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray focus:outline-none focus:border-bambu-green`,title:e(`fileManager.folderSort`),"aria-label":e(`fileManager.folderSort`),children:[(0,z.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,z.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,z.jsx)(`button`,{onClick:()=>{let e=zt===`asc`?`desc`:`asc`;Bt(e),localStorage.setItem(`library-folder-sort-direction`,e)},className:`text-bambu-gray hover:text-white hover:bg-bambu-dark p-1 rounded transition-colors`,title:e(zt===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(zt===`asc`?`fileManager.ascending`:`fileManager.descending`),children:zt===`asc`?(0,z.jsx)(et,{className:`w-3.5 h-3.5`}):(0,z.jsx)($e,{className:`w-3.5 h-3.5`})}),(0,z.jsx)(`button`,{onClick:()=>{let e=!Ft;It(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Ft?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Ft?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,z.jsx)(`button`,{onClick:()=>{let e=!Nt;Pt(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Nt?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Nt?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${g===null&&y===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{_(null),x(`internal`)},children:[(0,z.jsx)(S,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),ln?.some(e=>e.is_external)&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${g===null&&y===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{_(null),x(`external`)},children:[(0,z.jsx)(it,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,z.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),q?.map(t=>(0,z.jsx)(xl,{folder:t,selectedFolderId:g,onSelect:_,onDelete:e=>st({type:`folder`,id:e}),onLink:Ye,onRename:e=>St({type:`folder`,id:e.id,name:e.name}),onToggleShared:Ln,wrapNames:Nt,defaultExpanded:!Ft,showModified:nn,hasPermission:r,t:e},`${t.id}-${Ft?`c`:`e`}`))]})]}),(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[mn.length>0&&(0,z.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),mn.map(e=>{let t=We.includes(e.id);return(0,z.jsxs)(`button`,{type:`button`,onClick:()=>gn(e.id),className:t?`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/20 text-bambu-green border border-bambu-green/40 hover:bg-bambu-green/30 transition-colors`:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-dark text-bambu-gray border border-bambu-dark-tertiary hover:text-white hover:border-bambu-green/40 transition-colors`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-3 h-3`}),(0,z.jsx)(`span`,{children:e.name}),t&&(0,z.jsx)(ae,{className:`w-3 h-3`})]},e.id)}),We.length>0&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>qe([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),Y?.is_external&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:[(0,z.jsx)(it,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),Y.external_readonly&&(0,z.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,z.jsx)(M,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:Y.external_path||``,children:Y.external_path})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>g&&Dn.mutate(g),disabled:Dn.isPending,title:e(`fileManager.scanFolder`),children:[Dn.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(L,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),yn&&yn.length>0&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,z.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,z.jsx)(N,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,z.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Kt,onChange:e=>qt(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`}),fn&&(0,z.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(E,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,z.jsxs)(`select`,{value:Jt,onChange:e=>Yt(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),Cn.map(e=>(0,z.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),f&&(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:Xt,onChange:e=>Zt(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${Xt?`pr-7`:``}`,style:Xt?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),Xt&&(0,z.jsx)(`button`,{onClick:()=>Zt(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,z.jsx)(ae,{className:`w-3 h-3`})}),(0,z.jsx)(`datalist`,{id:`usernames-list`,children:Sn?.map(e=>(0,z.jsx)(`option`,{value:e.username},e.id))})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(`select`,{value:Qt,onChange:e=>{let t=e.target.value;$t(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,z.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,z.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,z.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,z.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,z.jsx)(`button`,{onClick:()=>tn(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(en===`asc`?`fileManager.ascending`:`fileManager.descending`),children:en===`asc`?(0,z.jsx)(et,{className:`w-4 h-4 text-white`}):(0,z.jsx)($e,{className:`w-4 h-4 text-white`})}),(0,z.jsx)(`button`,{onClick:()=>rn(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${nn?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(nn?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":nn,children:(0,z.jsx)(tt,{className:`w-4 h-4`})})]}),(Kt||Jt!==`all`||Xt)&&(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:J.length,total:yn.length})})]}),(J.length>0||C.length>0)&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[Un?(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Wn,children:[(0,z.jsx)(ge,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Hn,children:[(0,z.jsx)(Ce,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),C.length>0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:C.length})}),(0,z.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,z.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[cr&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>Bn(cr),disabled:!r(`library:read`),title:r(`library:read`)?void 0:e(`fileManager.noPermissionPreview`),children:[(0,z.jsx)(we,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.preview.open`)})]}),lr.length>=1&&(0,z.jsxs)(P,{variant:`primary`,size:`sm`,onClick:()=>ut(lr[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,z.jsx)(me,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:lr.length>1?e(`fileManager.variants.printAlternatives`,{count:lr.length}):e(`common.print`)})]}),lr.length>=2&&!lr.some(e=>e.variant_group_id)&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>An.mutate(lr.map(e=>e.id)),disabled:An.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,z.jsx)(je,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),$.length>=1&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>gt(!0),disabled:!r(`library:upload`),title:e(`fileManager.combine.tooltip`),children:[(0,z.jsx)(nt,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.combine.action`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>fe(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,z.jsx)(at,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>Ve(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.tags.bulkTooltip`):e(`fileManager.tags.noPermission`),children:[(0,z.jsx)(xe,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,z.jsxs)(P,{variant:`danger`,size:`sm`,onClick:()=>{C.length===1?st({type:`file`,id:C[0]}):st({type:`bulk`,id:0,count:C.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,z.jsx)(de,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Wn,children:[(0,z.jsx)(ae,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),rr&&G!==`columns`?(0,z.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,z.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,z.jsx)(j,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):G===`columns`?(0,z.jsx)(`div`,{ref:jt,tabIndex:0,"aria-label":e(`fileManager.columnsView`),onKeyDown:hr,className:`flex-1 min-h-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto outline-none focus-visible:ring-1 focus-visible:ring-bambu-green/50`,"data-testid":`columns-view`,children:(0,z.jsxs)(`div`,{className:`h-full min-h-[16rem] flex divide-x divide-bambu-dark-tertiary`,children:[!_n&&X.map(t=>{let n=or.get(t.key),i=!!(n&&(n.loading||n.files.length>0));return(0,z.jsxs)(`div`,{"data-testid":`columns-level-${t.key}`,className:`${i?`w-[26rem]`:`w-64`} flex-shrink-0 overflow-y-auto py-1`,children:[t.items.map(n=>{let i=g===n.id;return(0,z.jsxs)(`div`,{"data-folder-id":n.id,className:`group flex items-center pr-1.5 transition-colors ${t.activeId===n.id?`bg-bambu-green/20 text-bambu-green`:i?`bg-bambu-green/10 text-white`:`text-white hover:bg-bambu-dark`}`,children:[(0,z.jsxs)(`button`,{type:`button`,tabIndex:-1,onClick:()=>{Mt(null),_(n.id)},className:`flex-1 min-w-0 flex items-center gap-2 pl-3 pr-1 py-2.5 text-left text-sm`,title:n.name,children:[n.is_external?(0,z.jsx)(it,{className:`w-5 h-5 flex-shrink-0 text-purple-600 dark:text-purple-400`}):(0,z.jsx)(Ie,{className:`w-5 h-5 flex-shrink-0 text-bambu-green`}),(0,z.jsx)(`span`,{className:`flex-1 truncate`,children:n.name}),(n.project_id||n.archive_id)&&(0,z.jsx)(A,{className:`w-3.5 h-3.5 flex-shrink-0 text-blue-700 dark:text-blue-400`}),n.shared&&(0,z.jsx)(`span`,{title:e(`fileManager.sharedFolder`),children:(0,z.jsx)(pe,{className:`w-3.5 h-3.5 flex-shrink-0 text-bambu-gray`})}),n.is_external&&n.external_readonly&&(0,z.jsx)(M,{className:`w-3.5 h-3.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),n.file_count>0&&(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:n.file_count}),n.children.length>0&&(0,z.jsx)(_e,{className:`w-4 h-4 flex-shrink-0 text-bambu-gray`})]}),(0,z.jsx)(bl,{folder:n,onDelete:e=>st({type:`folder`,id:e}),onLink:Ye,onRename:e=>St({type:`folder`,id:e.id,name:e.name}),onToggleShared:Ln,hasPermission:r,revealOnHover:!i,tabIndex:i?0:-1,t:e})]},n.id)}),n?.loading&&(0,z.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,"aria-hidden":`true`,children:`…`}),n&&!n.loading&&n.files.map(t=>(0,z.jsx)(wl,{file:t,isSelected:C.includes(t.id),isFocused:K===t.id,showModified:nn,thumbnailVersion:Ct[t.id],onSelect:e=>{Mt(e.id),Vn(e.id)},onOpen:Bn,actionProps:nr,t:e},t.id))]},t.key)}),(0,z.jsx)(`div`,{className:`flex-1 min-w-[28rem] overflow-y-auto py-1`,"data-testid":`columns-files-pane`,children:bn?(0,z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,z.jsx)(j,{className:`w-5 h-5 animate-spin text-bambu-green`})}):J.length===0?(0,z.jsx)(`div`,{className:`h-full flex items-center justify-center px-4 text-sm text-bambu-gray text-center`,children:(yn?.length??0)>0?e(`fileManager.noMatchingFiles`):g===null?vn&&X[0].items.length>0?e(`fileManager.noFilesOutsideFolders`):e(y===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`):e(`fileManager.folderIsEmpty`)}):J.map(t=>(0,z.jsx)(wl,{file:t,isSelected:C.includes(t.id),isFocused:K===t.id,showModified:nn,thumbnailVersion:Ct[t.id],onSelect:e=>{Mt(e.id),Vn(e.id)},onOpen:Bn,actionProps:nr,t:e},t.id))})]})}):yn?.length===0?(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(S,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(g===null?y===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(g===null?y===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,z.jsxs)(P,{onClick:()=>I(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionUpload`),children:[(0,z.jsx)(Oe,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):J.length===0?(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(N,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,z.jsx)(P,{variant:`secondary`,onClick:()=>{qt(``),Yt(`all`)},children:e(`fileManager.clearFilters`)})]}):G===`grid`?(0,z.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,z.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:J.map(t=>(0,z.jsx)(Sl,{file:t,isSelected:C.includes(t.id),t:e,onSelect:Vn,onDelete:e=>st({type:`file`,id:e}),onDownload:Qn,onPrint:ut,onSlice:pt,onOpenInSlicer:sn,desktopSlicer:on,onRunPipeline:bt,useSlicerApi:an?.use_slicer_api??!1,canSlice:cn(),onPreview:Bn,onRename:e=>St({type:`file`,id:e.id,name:e.filename}),onDetails:U,onGenerateThumbnail:e=>zn.mutate(e.id),onTagClick:gn,thumbnailVersion:Ct[t.id],hasPermission:r,canModify:s,authEnabled:f,showModified:nn},t.id))})}):(0,z.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,z.jsxs)(`div`,{"data-testid":`file-list-grid-header`,className:`hidden sm:grid ${dl(f)} ${fl} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,z.jsx)(`div`,{className:`w-6`}),(0,z.jsx)(`div`,{children:e(`common.name`)}),f&&(0,z.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,z.jsx)(`div`,{children:e(`common.type`)}),(0,z.jsx)(`div`,{children:e(`fileManager.size`)}),(0,z.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,z.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,z.jsx)(`div`,{})]}),J.map(t=>(0,z.jsxs)(`div`,{"data-testid":`file-list-grid-row`,className:`grid ${dl(f)} ${fl} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${C.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>Vn(t.id),onDoubleClick:()=>Bn(t),children:[(0,z.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${C.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:C.includes(t.id)&&(0,z.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,z.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(t.id)}${Ct[t.id]?(a.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${Ct[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,z.jsx)(nl,{fileType:t.file_type,className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,z.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,z.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(t.id)}${Ct[t.id]?(a.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${Ct[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,z.jsx)(`span`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),t.external_url&&(0,z.jsx)(`a`,{href:t.external_url,target:`_blank`,rel:`noopener noreferrer`,...al,className:`flex-shrink-0 text-bambu-gray hover:text-bambu-green`,title:e(`fileManager.details.openLink`),"aria-label":e(`fileManager.details.openLink`),children:(0,z.jsx)(Me,{className:`w-3.5 h-3.5`})}),t.has_notes&&(0,z.jsx)(`span`,{className:`flex-shrink-0 text-bambu-gray`,title:e(`fileManager.details.hasNotes`),"aria-label":e(`fileManager.details.hasNotes`),children:(0,z.jsx)(ne,{className:`w-3.5 h-3.5`})}),(t.photo_count??0)>0&&(0,z.jsxs)(`span`,{className:`flex-shrink-0 flex items-center gap-0.5 text-xs text-bambu-gray`,title:e(`fileManager.details.photoCount`,{count:t.photo_count}),children:[(0,z.jsx)(be,{className:`w-3.5 h-3.5`}),t.photo_count]})]}),nn&&(0,z.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:se(t.fs_modified_at??t.created_at)})]})]})]}),f&&(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(ye,{className:`w-3 h-3`}),(0,z.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,z.jsx)(`div`,{children:(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${ll(t.file_type)}`,children:t.file_type.toUpperCase()})}),(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:oe(t.file_size)}),(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,z.jsx)(`div`,{className:`min-w-0`,...al,children:!t.tags||t.tags.length===0?(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>gn(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,z.jsx)(Cl,{file:t,...nr})]},t.id))]})})]}),g!==null&&(0,z.jsx)(Hc,{folderId:g})]})]}),te&&(0,z.jsx)(pl,{parentId:g,onClose:()=>ie(!1),onSave:e=>Tn.mutate(e),isLoading:Tn.isPending,t:e}),ce&&(0,z.jsx)(ml,{onClose:()=>le(!1),onSave:e=>En.mutate(e),isLoading:En.isPending,t:e}),ue&&ln&&(0,z.jsx)(vl,{folders:ln,selectedFiles:C,currentFolderId:g,onClose:()=>fe(!1),onMove:e=>Mn.mutate({fileIds:C,folderId:e}),isLoading:Mn.isPending,t:e}),F&&(0,z.jsx)(Xe,{folderId:g,onClose:()=>{I(!1),ve([])},onUploadComplete:Gn,initialFiles:he.length>0?he:void 0}),Te&&(0,z.jsx)(Kc,{onClose:()=>Pe(!1)}),(0,z.jsx)(Uc,{open:Le,onClose:()=>Re(!1),onPickTag:e=>{We.includes(e)||qe(t=>[...t,e])}}),(0,z.jsx)(mt,{open:Be,fileIds:C,onClose:()=>Ve(!1)}),Je&&(0,z.jsx)(yl,{folder:Je,onClose:()=>Ye(null),onLink:e=>Nn.mutate({id:Je.id,data:e}),isLoading:Nn.isPending,t:e}),ot&&(0,z.jsx)(ke,{title:ot.type===`folder`?e(`fileManager.deleteFolder`):ot.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:ot.count}):e(`fileManager.deleteFile`),message:ot.type===`folder`?e(`fileManager.deleteFolderConfirm`):ot.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:ot.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:er,loadingText:e(`fileManager.deleting`),onConfirm:$n,onCancel:()=>st(null)}),ct&&(!ct.variant_group_id||ur!==void 0)&&(0,z.jsx)(Ae,{mode:`create`,libraryFileId:dr?.[0]?.id??ct.id,variantFiles:dr,archiveName:dr&&dr.length>1?`${dr[0].filename} ${e(`common.plusNMore`,{count:dr.length-1})}`:ct.print_name||ct.filename,onClose:()=>ut(null),onSuccess:()=>{ut(null),T([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),dt&&(0,z.jsx)(D,{source:{kind:`libraryFile`,id:dt.id,filename:dt.filename},onClose:()=>pt(null)}),ht&&$.length>0&&(0,z.jsx)(ft,{files:$,folderId:g,canSlice:!!an?.use_slicer_api&&cn(),onClose:()=>gt(!1),onCombined:(e,t)=>{gt(!1),T([]),t&&vt({id:e.id,filename:e.filename})}}),_t&&(0,z.jsx)(D,{source:{kind:`libraryFile`,id:_t.id,filename:_t.filename},onClose:()=>vt(null),defaultAutoArrange:!0}),yt&&(0,z.jsx)(Ue,{source:{kind:`libraryFile`,id:yt.id,filename:yt.filename},onClose:()=>bt(null)}),Tt&&(0,z.jsx)(lt,{libraryFileId:Tt.id,title:Tt.print_name||Tt.filename,fileType:Tt.file_type,onClose:()=>B(null),onSnapshot:Zc(Tt.file_type)?Zn(Tt):void 0,onSliceWithBambuddy:Qe(Tt,!0,on)&&r(`library:upload`)?()=>{let e=Tt;B(null),pt(e)}:void 0}),(Et||V||W)&&(0,z.jsxs)(R.Suspense,{fallback:null,children:[Et&&(0,z.jsx)(qc,{libraryFileId:Et.id,filename:Et.print_name||Et.filename,fileSize:Et.file_size,onClose:()=>Dt(null),onSnapshot:Zn(Et)}),V&&(0,z.jsx)(Jc,{libraryFileId:V.id,filename:V.print_name||V.filename,fileType:V.file_type,fileSize:V.file_size,onClose:()=>H(null),onSnapshot:Zn(V)}),W&&(0,z.jsx)(Yc,{libraryFileId:W.id,filename:W.print_name||W.filename,fileSize:W.file_size,onClose:()=>kt(null)})]}),Ot&&(0,z.jsx)(Wc,{file:Ot,canEdit:s(`library`,`update`,Ot.created_by_id),onClose:()=>U(null)}),xt&&(0,z.jsx)(_l,{type:xt.type,currentName:xt.name,onClose:()=>St(null),onSave:e=>{xt.type===`file`?Pn.mutate({id:xt.id,filename:e}):Fn.mutate({id:xt.id,name:e})},isLoading:Pn.isPending||Fn.isPending,t:e})]})}export{Tl as FileManagerPage};
\ No newline at end of file
diff --git a/static/assets/FileUploadModal-GYUY0fS6.js b/static/assets/FileUploadModal-DfKGV0qu.js
similarity index 99%
rename from static/assets/FileUploadModal-GYUY0fS6.js
rename to static/assets/FileUploadModal-DfKGV0qu.js
index 9e798f141..306a390f7 100644
--- a/static/assets/FileUploadModal-GYUY0fS6.js
+++ b/static/assets/FileUploadModal-DfKGV0qu.js
@@ -1,2 +1,2 @@
-import{i as e,r as t,t as n}from"./chunk-aKtaBQYM.js";import{C as r,D as i,a,l as o,w as s}from"./client-BdOyoZJz.js";import{n as c}from"./info-DcT0QU8O.js";import{r as l}from"./ToastContext-VFOrCCoA.js";import{n as u}from"./ContextMenu-B4uGJkKW.js";import{t as d}from"./loader-circle-CB4leTZa.js";import{t as f}from"./x-Dctff5l9.js";import{n as p,t as m}from"./zoom-out-C85W_TC5.js";import{t as h}from"./Button-pwVKPiYn.js";import{Gt as g,Jt as _,Ln as v,kt as y,un as b}from"./index-Bw-_P2Fg.js";import{A as x,C as S,D as C,E as w,O as T,S as E,T as D,_ as O,a as k,b as A,c as j,d as M,f as N,g as P,h as F,k as I,l as L,m as R,n as z,o as B,p as V,r as H,s as U,t as ee,u as W,v as G,w as K,x as q,y as J}from"./OrbitControls-Bbqf07B-.js";var Y=e(i(),1);function X(e,t=!1){let n=e[0].index!==null,r=new Set(Object.keys(e[0].attributes)),i=new Set(Object.keys(e[0].morphAttributes)),a={},o={},s=e[0].morphTargetsRelative,c=new j,l=0;for(let u=0;u>5&31)/31,a=(e>>10&31)/31)}for(let c=1;c<=3;c++){let l=n+c*12,u=e*3*3+(c-1)*3;p[u]=t.getFloat32(l,!0),p[u+1]=t.getFloat32(l+4,!0),p[u+2]=t.getFloat32(l+8,!0),m[u]=d,m[u+1]=f,m[u+2]=g,o&&(h.setRGB(r,i,a,C),s[u]=h.r,s[u+1]=h.g,s[u+2]=h.b)}}return f.setAttribute(`position`,new U(p,3)),f.setAttribute(`normal`,new U(m,3)),o&&(f.setAttribute(`color`,new U(s,3)),f.hasColors=!0,f.alpha=d),f}function i(e){let t=new j,n=/solid([\s\S]*?)endsolid/g,r=/facet([\s\S]*?)endfacet/g,i=/solid\s(.+)/,a=0,o=RegExp(`vertex[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),s=RegExp(`normal[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),c=[],l=[],u=[],d=new x,f,p=0,m=0,h=0;for(;(f=n.exec(e))!==null;){m=h;let e=f[0],n=(f=i.exec(e))===null?``:f[1];for(u.push(n);(f=r.exec(e))!==null;){let e=0,t=0,n=f[0];for(;(f=s.exec(n))!==null;)d.x=parseFloat(f[1]),d.y=parseFloat(f[2]),d.z=parseFloat(f[3]),t++;for(;(f=o.exec(n))!==null;)c.push(parseFloat(f[1]),parseFloat(f[2]),parseFloat(f[3])),l.push(d.x,d.y,d.z),e++,h++;t!==1&&console.error(`THREE.STLLoader: Something isn't right with the normal of face number `+a),e!==3&&console.error(`THREE.STLLoader: Something isn't right with the vertices of face number `+a),a++}let g=m,_=h-m;t.userData.groupNames=u,t.addGroup(g,_,p),p++}return t.setAttribute(`position`,new N(c,3)),t.setAttribute(`normal`,new N(l,3)),t}function a(e){return typeof e==`string`?e:new TextDecoder().decode(e)}function o(e){if(typeof e==`string`){let t=new Uint8Array(e.length);for(let n=0;n{t.isMesh&&(e.add(t.geometry),e.add(t.material))});for(let t of e)t.dispose()}};function Z(e){return new q({color:0,emissive:16777215,emissiveIntensity:e})}var ie=e(n(((e,n)=>{(function(t){typeof e==`object`&&n!==void 0?n.exports=t():typeof define==`function`&&define.amd?define([],t):(typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this).JSZip=t()})(function(){return function e(n,r,i){function a(s,c){if(!r[s]){if(!n[s]){var l=typeof t==`function`&&t;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=r[s]={exports:{}};n[s][0].call(d.exports,function(e){var t=n[s][1][e];return a(t||e)},d,d.exports,e,n,r,i)}return r[s].exports}for(var o=typeof t==`function`&&t,s=0;s>2,s=(3&t)<<4|n>>4,c=1>6:64,l=2
>4,n=(15&o)<<4|(s=a.indexOf(e.charAt(l++)))>>2,r=(3&s)<<6|(c=a.indexOf(e.charAt(l++))),f[u++]=t,s!==64&&(f[u++]=n),c!==64&&(f[u++]=r);return f}},{"./support":30,"./utils":32}],2:[function(e,t,n){var r=e(`./external`),i=e(`./stream/DataWorker`),a=e(`./stream/Crc32Probe`),o=e(`./stream/DataLengthProbe`);function s(e,t,n,r,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=n,this.compression=r,this.compressedContent=i}s.prototype={getContentWorker:function(){var e=new i(r.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new o(`data_length`)),t=this;return e.on(`end`,function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw Error(`Bug : uncompressed data size mismatch`)}),e},getCompressedWorker:function(){return new i(r.Promise.resolve(this.compressedContent)).withStreamInfo(`compressedSize`,this.compressedSize).withStreamInfo(`uncompressedSize`,this.uncompressedSize).withStreamInfo(`crc32`,this.crc32).withStreamInfo(`compression`,this.compression)}},s.createWorkerFrom=function(e,t,n){return e.pipe(new a).pipe(new o(`uncompressedSize`)).pipe(t.compressWorker(n)).pipe(new o(`compressedSize`)).withStreamInfo(`compression`,t)},t.exports=s},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,n){var r=e(`./stream/GenericWorker`);n.STORE={magic:`\0\0`,compressWorker:function(){return new r(`STORE compression`)},uncompressWorker:function(){return new r(`STORE decompression`)}},n.DEFLATE=e(`./flate`)},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,n){var r=e(`./utils`),i=function(){for(var e,t=[],n=0;n<256;n++){e=n;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[n]=e}return t}();t.exports=function(e,t){return e!==void 0&&e.length?r.getTypeOf(e)===`string`?function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t.charCodeAt(s))];return-1^e}(0|t,e,e.length,0):function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t[s])];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,n){n.base64=!1,n.binary=!1,n.dir=!1,n.createFolders=!0,n.date=null,n.compression=null,n.compressionOptions=null,n.comment=null,n.unixPermissions=null,n.dosPermissions=null},{}],6:[function(e,t,n){var r=null;r=typeof Promise<`u`?Promise:e(`lie`),t.exports={Promise:r}},{lie:37}],7:[function(e,t,n){var r=typeof Uint8Array<`u`&&typeof Uint16Array<`u`&&typeof Uint32Array<`u`,i=e(`pako`),a=e(`./utils`),o=e(`./stream/GenericWorker`),s=r?`uint8array`:`array`;function c(e,t){o.call(this,`FlateWorker/`+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}n.magic=`\b\0`,a.inherits(c,o),c.prototype.processChunk=function(e){this.meta=e.meta,this._pako===null&&this._createPako(),this._pako.push(a.transformTo(s,e.data),!1)},c.prototype.flush=function(){o.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},c.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this._pako=null},c.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var e=this;this._pako.onData=function(t){e.push({data:t,meta:e.meta})}},n.compressWorker=function(e){return new c(`Deflate`,e)},n.uncompressWorker=function(){return new c(`Inflate`,{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,n){function r(e,t){var n,r=``;for(n=0;n>>=8;return r}function i(e,t,n,i,o,u){var d,f,p=e.file,m=e.compression,h=u!==s.utf8encode,g=a.transformTo(`string`,u(p.name)),_=a.transformTo(`string`,s.utf8encode(p.name)),v=p.comment,y=a.transformTo(`string`,u(v)),b=a.transformTo(`string`,s.utf8encode(v)),x=_.length!==p.name.length,S=b.length!==v.length,C=``,w=``,T=``,E=p.dir,D=p.date,O={crc32:0,compressedSize:0,uncompressedSize:0};t&&!n||(O.crc32=e.crc32,O.compressedSize=e.compressedSize,O.uncompressedSize=e.uncompressedSize);var k=0;t&&(k|=8),h||!x&&!S||(k|=2048);var A=0,j=0;E&&(A|=16),o===`UNIX`?(j=798,A|=function(e,t){var n=e;return e||(n=t?16893:33204),(65535&n)<<16}(p.unixPermissions,E)):(j=20,A|=function(e){return 63&(e||0)}(p.dosPermissions)),d=D.getUTCHours(),d<<=6,d|=D.getUTCMinutes(),d<<=5,d|=D.getUTCSeconds()/2,f=D.getUTCFullYear()-1980,f<<=4,f|=D.getUTCMonth()+1,f<<=5,f|=D.getUTCDate(),x&&(w=r(1,1)+r(c(g),4)+_,C+=`up`+r(w.length,2)+w),S&&(T=r(1,1)+r(c(y),4)+b,C+=`uc`+r(T.length,2)+T);var M=``;return M+=`
+import{i as e,r as t,t as n}from"./chunk-aKtaBQYM.js";import{C as r,D as i,a,l as o,w as s}from"./client-BdOyoZJz.js";import{n as c}from"./info-DcT0QU8O.js";import{r as l}from"./ToastContext-VFOrCCoA.js";import{n as u}from"./ContextMenu-BVYxDFvf.js";import{t as d}from"./loader-circle-CB4leTZa.js";import{t as f}from"./x-Dctff5l9.js";import{n as p,t as m}from"./zoom-out-C85W_TC5.js";import{t as h}from"./Button-pwVKPiYn.js";import{Gt as g,Jt as _,Ln as v,kt as y,un as b}from"./index-ggB_TpPo.js";import{A as x,C as S,D as C,E as w,O as T,S as E,T as D,_ as O,a as k,b as A,c as j,d as M,f as N,g as P,h as F,k as I,l as L,m as R,n as z,o as B,p as V,r as H,s as U,t as ee,u as W,v as G,w as K,x as q,y as J}from"./OrbitControls-Bbqf07B-.js";var Y=e(i(),1);function X(e,t=!1){let n=e[0].index!==null,r=new Set(Object.keys(e[0].attributes)),i=new Set(Object.keys(e[0].morphAttributes)),a={},o={},s=e[0].morphTargetsRelative,c=new j,l=0;for(let u=0;u>5&31)/31,a=(e>>10&31)/31)}for(let c=1;c<=3;c++){let l=n+c*12,u=e*3*3+(c-1)*3;p[u]=t.getFloat32(l,!0),p[u+1]=t.getFloat32(l+4,!0),p[u+2]=t.getFloat32(l+8,!0),m[u]=d,m[u+1]=f,m[u+2]=g,o&&(h.setRGB(r,i,a,C),s[u]=h.r,s[u+1]=h.g,s[u+2]=h.b)}}return f.setAttribute(`position`,new U(p,3)),f.setAttribute(`normal`,new U(m,3)),o&&(f.setAttribute(`color`,new U(s,3)),f.hasColors=!0,f.alpha=d),f}function i(e){let t=new j,n=/solid([\s\S]*?)endsolid/g,r=/facet([\s\S]*?)endfacet/g,i=/solid\s(.+)/,a=0,o=RegExp(`vertex[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),s=RegExp(`normal[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),c=[],l=[],u=[],d=new x,f,p=0,m=0,h=0;for(;(f=n.exec(e))!==null;){m=h;let e=f[0],n=(f=i.exec(e))===null?``:f[1];for(u.push(n);(f=r.exec(e))!==null;){let e=0,t=0,n=f[0];for(;(f=s.exec(n))!==null;)d.x=parseFloat(f[1]),d.y=parseFloat(f[2]),d.z=parseFloat(f[3]),t++;for(;(f=o.exec(n))!==null;)c.push(parseFloat(f[1]),parseFloat(f[2]),parseFloat(f[3])),l.push(d.x,d.y,d.z),e++,h++;t!==1&&console.error(`THREE.STLLoader: Something isn't right with the normal of face number `+a),e!==3&&console.error(`THREE.STLLoader: Something isn't right with the vertices of face number `+a),a++}let g=m,_=h-m;t.userData.groupNames=u,t.addGroup(g,_,p),p++}return t.setAttribute(`position`,new N(c,3)),t.setAttribute(`normal`,new N(l,3)),t}function a(e){return typeof e==`string`?e:new TextDecoder().decode(e)}function o(e){if(typeof e==`string`){let t=new Uint8Array(e.length);for(let n=0;n{t.isMesh&&(e.add(t.geometry),e.add(t.material))});for(let t of e)t.dispose()}};function Z(e){return new q({color:0,emissive:16777215,emissiveIntensity:e})}var ie=e(n(((e,n)=>{(function(t){typeof e==`object`&&n!==void 0?n.exports=t():typeof define==`function`&&define.amd?define([],t):(typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this).JSZip=t()})(function(){return function e(n,r,i){function a(s,c){if(!r[s]){if(!n[s]){var l=typeof t==`function`&&t;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=r[s]={exports:{}};n[s][0].call(d.exports,function(e){var t=n[s][1][e];return a(t||e)},d,d.exports,e,n,r,i)}return r[s].exports}for(var o=typeof t==`function`&&t,s=0;s>2,s=(3&t)<<4|n>>4,c=1>6:64,l=2
>4,n=(15&o)<<4|(s=a.indexOf(e.charAt(l++)))>>2,r=(3&s)<<6|(c=a.indexOf(e.charAt(l++))),f[u++]=t,s!==64&&(f[u++]=n),c!==64&&(f[u++]=r);return f}},{"./support":30,"./utils":32}],2:[function(e,t,n){var r=e(`./external`),i=e(`./stream/DataWorker`),a=e(`./stream/Crc32Probe`),o=e(`./stream/DataLengthProbe`);function s(e,t,n,r,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=n,this.compression=r,this.compressedContent=i}s.prototype={getContentWorker:function(){var e=new i(r.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new o(`data_length`)),t=this;return e.on(`end`,function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw Error(`Bug : uncompressed data size mismatch`)}),e},getCompressedWorker:function(){return new i(r.Promise.resolve(this.compressedContent)).withStreamInfo(`compressedSize`,this.compressedSize).withStreamInfo(`uncompressedSize`,this.uncompressedSize).withStreamInfo(`crc32`,this.crc32).withStreamInfo(`compression`,this.compression)}},s.createWorkerFrom=function(e,t,n){return e.pipe(new a).pipe(new o(`uncompressedSize`)).pipe(t.compressWorker(n)).pipe(new o(`compressedSize`)).withStreamInfo(`compression`,t)},t.exports=s},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,n){var r=e(`./stream/GenericWorker`);n.STORE={magic:`\0\0`,compressWorker:function(){return new r(`STORE compression`)},uncompressWorker:function(){return new r(`STORE decompression`)}},n.DEFLATE=e(`./flate`)},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,n){var r=e(`./utils`),i=function(){for(var e,t=[],n=0;n<256;n++){e=n;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[n]=e}return t}();t.exports=function(e,t){return e!==void 0&&e.length?r.getTypeOf(e)===`string`?function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t.charCodeAt(s))];return-1^e}(0|t,e,e.length,0):function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t[s])];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,n){n.base64=!1,n.binary=!1,n.dir=!1,n.createFolders=!0,n.date=null,n.compression=null,n.compressionOptions=null,n.comment=null,n.unixPermissions=null,n.dosPermissions=null},{}],6:[function(e,t,n){var r=null;r=typeof Promise<`u`?Promise:e(`lie`),t.exports={Promise:r}},{lie:37}],7:[function(e,t,n){var r=typeof Uint8Array<`u`&&typeof Uint16Array<`u`&&typeof Uint32Array<`u`,i=e(`pako`),a=e(`./utils`),o=e(`./stream/GenericWorker`),s=r?`uint8array`:`array`;function c(e,t){o.call(this,`FlateWorker/`+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}n.magic=`\b\0`,a.inherits(c,o),c.prototype.processChunk=function(e){this.meta=e.meta,this._pako===null&&this._createPako(),this._pako.push(a.transformTo(s,e.data),!1)},c.prototype.flush=function(){o.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},c.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this._pako=null},c.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var e=this;this._pako.onData=function(t){e.push({data:t,meta:e.meta})}},n.compressWorker=function(e){return new c(`Deflate`,e)},n.uncompressWorker=function(){return new c(`Inflate`,{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,n){function r(e,t){var n,r=``;for(n=0;n>>=8;return r}function i(e,t,n,i,o,u){var d,f,p=e.file,m=e.compression,h=u!==s.utf8encode,g=a.transformTo(`string`,u(p.name)),_=a.transformTo(`string`,s.utf8encode(p.name)),v=p.comment,y=a.transformTo(`string`,u(v)),b=a.transformTo(`string`,s.utf8encode(v)),x=_.length!==p.name.length,S=b.length!==v.length,C=``,w=``,T=``,E=p.dir,D=p.date,O={crc32:0,compressedSize:0,uncompressedSize:0};t&&!n||(O.crc32=e.crc32,O.compressedSize=e.compressedSize,O.uncompressedSize=e.uncompressedSize);var k=0;t&&(k|=8),h||!x&&!S||(k|=2048);var A=0,j=0;E&&(A|=16),o===`UNIX`?(j=798,A|=function(e,t){var n=e;return e||(n=t?16893:33204),(65535&n)<<16}(p.unixPermissions,E)):(j=20,A|=function(e){return 63&(e||0)}(p.dosPermissions)),d=D.getUTCHours(),d<<=6,d|=D.getUTCMinutes(),d<<=5,d|=D.getUTCSeconds()/2,f=D.getUTCFullYear()-1980,f<<=4,f|=D.getUTCMonth()+1,f<<=5,f|=D.getUTCDate(),x&&(w=r(1,1)+r(c(g),4)+_,C+=`up`+r(w.length,2)+w),S&&(T=r(1,1)+r(c(y),4)+b,C+=`uc`+r(T.length,2)+T);var M=``;return M+=`
\0`,M+=r(k,2),M+=m.magic,M+=r(d,2),M+=r(f,2),M+=r(O.crc32,4),M+=r(O.compressedSize,4),M+=r(O.uncompressedSize,4),M+=r(g.length,2),M+=r(C.length,2),{fileRecord:l.LOCAL_FILE_HEADER+M+g+C,dirRecord:l.CENTRAL_FILE_HEADER+r(j,2)+M+r(y.length,2)+`\0\0\0\0`+r(A,4)+r(i,4)+g+C+y}}var a=e(`../utils`),o=e(`../stream/GenericWorker`),s=e(`../utf8`),c=e(`../crc32`),l=e(`../signature`);function u(e,t,n,r){o.call(this,`ZipFileWorker`),this.bytesWritten=0,this.zipComment=t,this.zipPlatform=n,this.encodeFileName=r,this.streamFiles=e,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}a.inherits(u,o),u.prototype.push=function(e){var t=e.meta.percent||0,n=this.entriesCount,r=this._sources.length;this.accumulate?this.contentBuffer.push(e):(this.bytesWritten+=e.data.length,o.prototype.push.call(this,{data:e.data,meta:{currentFile:this.currentFile,percent:n?(t+100*(n-r-1))/n:100}}))},u.prototype.openedSource=function(e){this.currentSourceOffset=this.bytesWritten,this.currentFile=e.file.name;var t=this.streamFiles&&!e.file.dir;if(t){var n=i(e,t,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:n.fileRecord,meta:{percent:0}})}else this.accumulate=!0},u.prototype.closedSource=function(e){this.accumulate=!1;var t=this.streamFiles&&!e.file.dir,n=i(e,t,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(n.dirRecord),t)this.push({data:function(e){return l.DATA_DESCRIPTOR+r(e.crc32,4)+r(e.compressedSize,4)+r(e.uncompressedSize,4)}(e),meta:{percent:100}});else for(this.push({data:n.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},u.prototype.flush=function(){for(var e=this.bytesWritten,t=0;t=this.index;t--)n=(n<<8)+this.byteAt(t);return this.index+=e,n},readString:function(e){return r.transformTo(`string`,this.readData(e))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var e=this.readInt(4);return new Date(Date.UTC(1980+(e>>25&127),(e>>21&15)-1,e>>16&31,e>>11&31,e>>5&63,(31&e)<<1))}},t.exports=i},{"../utils":32}],19:[function(e,t,n){var r=e(`./Uint8ArrayReader`);function i(e){r.call(this,e)}e(`../utils`).inherits(i,r),i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,n){var r=e(`./DataReader`);function i(e){r.call(this,e)}e(`../utils`).inherits(i,r),i.prototype.byteAt=function(e){return this.data.charCodeAt(this.zero+e)},i.prototype.lastIndexOfSignature=function(e){return this.data.lastIndexOf(e)-this.zero},i.prototype.readAndCheckSignature=function(e){return e===this.readData(4)},i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./DataReader":18}],21:[function(e,t,n){var r=e(`./ArrayReader`);function i(e){r.call(this,e)}e(`../utils`).inherits(i,r),i.prototype.readData=function(e){if(this.checkOffset(e),e===0)return new Uint8Array;var t=this.data.subarray(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,n){var r=e(`../utils`),i=e(`../support`),a=e(`./ArrayReader`),o=e(`./StringReader`),s=e(`./NodeBufferReader`),c=e(`./Uint8ArrayReader`);t.exports=function(e){var t=r.getTypeOf(e);return r.checkSupport(t),t!==`string`||i.uint8array?t===`nodebuffer`?new s(e):i.uint8array?new c(r.transformTo(`uint8array`,e)):new a(r.transformTo(`array`,e)):new o(e)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,n){n.LOCAL_FILE_HEADER=`PK`,n.CENTRAL_FILE_HEADER=`PK`,n.CENTRAL_DIRECTORY_END=`PK`,n.ZIP64_CENTRAL_DIRECTORY_LOCATOR=`PK\x07`,n.ZIP64_CENTRAL_DIRECTORY_END=`PK`,n.DATA_DESCRIPTOR=`PK\x07\b`},{}],24:[function(e,t,n){var r=e(`./GenericWorker`),i=e(`../utils`);function a(e){r.call(this,`ConvertWorker to `+e),this.destType=e}i.inherits(a,r),a.prototype.processChunk=function(e){this.push({data:i.transformTo(this.destType,e.data),meta:e.meta})},t.exports=a},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,n){var r=e(`./GenericWorker`),i=e(`../crc32`);function a(){r.call(this,`Crc32Probe`),this.withStreamInfo(`crc32`,0)}e(`../utils`).inherits(a,r),a.prototype.processChunk=function(e){this.streamInfo.crc32=i(e.data,this.streamInfo.crc32||0),this.push(e)},t.exports=a},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,n){var r=e(`../utils`),i=e(`./GenericWorker`);function a(e){i.call(this,`DataLengthProbe for `+e),this.propName=e,this.withStreamInfo(e,0)}r.inherits(a,i),a.prototype.processChunk=function(e){if(e){var t=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=t+e.data.length}i.prototype.processChunk.call(this,e)},t.exports=a},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,n){var r=e(`../utils`),i=e(`./GenericWorker`);function a(e){i.call(this,`DataWorker`);var t=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type=``,this._tickScheduled=!1,e.then(function(e){t.dataIsReady=!0,t.data=e,t.max=e&&e.length||0,t.type=r.getTypeOf(e),t.isPaused||t._tickAndRepeat()},function(e){t.error(e)})}r.inherits(a,i),a.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this.data=null},a.prototype.resume=function(){return!!i.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,r.delay(this._tickAndRepeat,[],this)),!0)},a.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(r.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},a.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var e=null,t=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case`string`:e=this.data.substring(this.index,t);break;case`uint8array`:e=this.data.subarray(this.index,t);break;case`array`:case`nodebuffer`:e=this.data.slice(this.index,t)}return this.index=t,this.push({data:e,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=a},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,n){function r(e){this.name=e||`default`,this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}r.prototype={push:function(e){this.emit(`data`,e)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit(`end`),this.cleanUp(),this.isFinished=!0}catch(e){this.emit(`error`,e)}return!0},error:function(e){return!this.isFinished&&(this.isPaused?this.generatedError=e:(this.isFinished=!0,this.emit(`error`,e),this.previous&&this.previous.error(e),this.cleanUp()),!0)},on:function(e,t){return this._listeners[e].push(t),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(e,t){if(this._listeners[e])for(var n=0;n `+e:e}},t.exports=r},{}],29:[function(e,t,n){var r=e(`../utils`),i=e(`./ConvertWorker`),a=e(`./GenericWorker`),o=e(`../base64`),s=e(`../support`),c=e(`../external`),l=null;if(s.nodestream)try{l=e(`../nodejs/NodejsStreamOutputAdapter`)}catch{}function u(e,t){return new c.Promise(function(n,i){var a=[],s=e._internalType,c=e._outputType,l=e._mimeType;e.on(`data`,function(e,n){a.push(e),t&&t(n)}).on(`error`,function(e){a=[],i(e)}).on(`end`,function(){try{n(function(e,t,n){switch(e){case`blob`:return r.newBlob(r.transformTo(`arraybuffer`,t),n);case`base64`:return o.encode(t);default:return r.transformTo(e,t)}}(c,function(e,t){var n,r=0,i=null,a=0;for(n=0;n`u`)n.blob=!1;else{var r=new ArrayBuffer(0);try{n.blob=new Blob([r],{type:`application/zip`}).size===0}catch{try{var i=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);i.append(r),n.blob=i.getBlob(`application/zip`).size===0}catch{n.blob=!1}}}try{n.nodestream=!!e(`readable-stream`).Readable}catch{n.nodestream=!1}},{"readable-stream":16}],31:[function(e,t,n){for(var r=e(`./utils`),i=e(`./support`),a=e(`./nodejsUtils`),o=e(`./stream/GenericWorker`),s=Array(256),c=0;c<256;c++)s[c]=252<=c?6:248<=c?5:240<=c?4:224<=c?3:192<=c?2:1;s[254]=s[254]=1;function l(){o.call(this,`utf-8 decode`),this.leftOver=null}function u(){o.call(this,`utf-8 encode`)}n.utf8encode=function(e){return i.nodebuffer?a.newBufferFrom(e,`utf-8`):function(e){var t,n,r,a,o,s=e.length,c=0;for(a=0;a>>6:(n<65536?t[o++]=224|n>>>12:(t[o++]=240|n>>>18,t[o++]=128|n>>>12&63),t[o++]=128|n>>>6&63),t[o++]=128|63&n);return t}(e)},n.utf8decode=function(e){return i.nodebuffer?r.transformTo(`nodebuffer`,e).toString(`utf-8`):function(e){var t,n,i,a,o=e.length,c=Array(2*o);for(t=n=0;t>10&1023,c[n++]=56320|1023&i)}return c.length!==n&&(c.subarray?c=c.subarray(0,n):c.length=n),r.applyFromCharCode(c)}(e=r.transformTo(i.uint8array?`uint8array`:`array`,e))},r.inherits(l,o),l.prototype.processChunk=function(e){var t=r.transformTo(i.uint8array?`uint8array`:`array`,e.data);if(this.leftOver&&this.leftOver.length){if(i.uint8array){var a=t;(t=new Uint8Array(a.length+this.leftOver.length)).set(this.leftOver,0),t.set(a,this.leftOver.length)}else t=this.leftOver.concat(t);this.leftOver=null}var o=function(e,t){var n;for((t||=e.length)>e.length&&(t=e.length),n=t-1;0<=n&&(192&e[n])==128;)n--;return n<0||n===0?t:n+s[e[n]]>t?n:t}(t),c=t;o!==t.length&&(i.uint8array?(c=t.subarray(0,o),this.leftOver=t.subarray(o,t.length)):(c=t.slice(0,o),this.leftOver=t.slice(o,t.length))),this.push({data:n.utf8decode(c),meta:e.meta})},l.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:n.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},n.Utf8DecodeWorker=l,r.inherits(u,o),u.prototype.processChunk=function(e){this.push({data:n.utf8encode(e.data),meta:e.meta})},n.Utf8EncodeWorker=u},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,n){var r=e(`./support`),i=e(`./base64`),a=e(`./nodejsUtils`),o=e(`./external`);function s(e){return e}function c(e,t){for(var n=0;n>8;this.dir=!!(16&this.externalFileAttributes),e==0&&(this.dosPermissions=63&this.externalFileAttributes),e==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!==`/`||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var e=r(this.extraFields[1].value);this.uncompressedSize===i.MAX_VALUE_32BITS&&(this.uncompressedSize=e.readInt(8)),this.compressedSize===i.MAX_VALUE_32BITS&&(this.compressedSize=e.readInt(8)),this.localHeaderOffset===i.MAX_VALUE_32BITS&&(this.localHeaderOffset=e.readInt(8)),this.diskNumberStart===i.MAX_VALUE_32BITS&&(this.diskNumberStart=e.readInt(4))}},readExtraFields:function(e){var t,n,r,i=e.index+this.extraFieldsLength;for(this.extraFields||={};e.index+4>>6:(n<65536?t[o++]=224|n>>>12:(t[o++]=240|n>>>18,t[o++]=128|n>>>12&63),t[o++]=128|n>>>6&63),t[o++]=128|63&n);return t},n.buf2binstring=function(e){return c(e,e.length)},n.binstring2buf=function(e){for(var t=new r.Buf8(e.length),n=0,i=t.length;n>10&1023,l[r++]=56320|1023&i)}return c(l,r)},n.utf8border=function(e,t){var n;for((t||=e.length)>e.length&&(t=e.length),n=t-1;0<=n&&(192&e[n])==128;)n--;return n<0||n===0?t:n+o[e[n]]>t?n:t}},{"./common":41}],43:[function(e,t,n){t.exports=function(e,t,n,r){for(var i=65535&e|0,a=e>>>16&65535|0,o=0;n!==0;){for(n-=o=2e3>>1:e>>>1;t[n]=e}return t}();t.exports=function(e,t,n,i){var a=r,o=i+n;e^=-1;for(var s=i;s>>8^a[255&(e^t[s])];return-1^e}},{}],46:[function(e,t,n){var r,i=e(`../utils/common`),a=e(`./trees`),o=e(`./adler32`),s=e(`./crc32`),c=e(`./messages`),l=0,u=4,d=0,f=-2,p=-1,m=4,h=2,g=8,_=9,v=286,y=30,b=19,x=2*v+1,S=15,C=3,w=258,T=w+C+1,E=42,D=113,O=1,k=2,A=3,j=4;function M(e,t){return e.msg=c[t],t}function N(e){return(e<<1)-(4e.avail_out&&(n=e.avail_out),n!==0&&(i.arraySet(e.output,t.pending_buf,t.pending_out,n,e.next_out),e.next_out+=n,t.pending_out+=n,e.total_out+=n,e.avail_out-=n,t.pending-=n,t.pending===0&&(t.pending_out=0))}function I(e,t){a._tr_flush_block(e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,F(e.strm)}function L(e,t){e.pending_buf[e.pending++]=t}function R(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t}function z(e,t){var n,r,i=e.max_chain_length,a=e.strstart,o=e.prev_length,s=e.nice_match,c=e.strstart>e.w_size-T?e.strstart-(e.w_size-T):0,l=e.window,u=e.w_mask,d=e.prev,f=e.strstart+w,p=l[a+o-1],m=l[a+o];e.prev_length>=e.good_match&&(i>>=2),s>e.lookahead&&(s=e.lookahead);do if(l[(n=t)+o]===m&&l[n+o-1]===p&&l[n]===l[a]&&l[++n]===l[a+1]){a+=2,n++;do;while(l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&ac&&--i!=0);return o<=e.lookahead?o:e.lookahead}function B(e){var t,n,r,a,c,l,u,d,f,p,m=e.w_size;do{if(a=e.window_size-e.lookahead-e.strstart,e.strstart>=m+(m-T)){for(i.arraySet(e.window,e.window,m,m,0),e.match_start-=m,e.strstart-=m,e.block_start-=m,t=n=e.hash_size;r=e.head[--t],e.head[t]=m<=r?r-m:0,--n;);for(t=n=m;r=e.prev[--t],e.prev[t]=m<=r?r-m:0,--n;);a+=m}if(e.strm.avail_in===0)break;if(l=e.strm,u=e.window,d=e.strstart+e.lookahead,f=a,p=void 0,p=l.avail_in,f=C)for(c=e.strstart-e.insert,e.ins_h=e.window[c],e.ins_h=(e.ins_h<=C&&(e.ins_h=(e.ins_h<=C)if(r=a._tr_tally(e,e.strstart-e.match_start,e.match_length-C),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=C){for(e.match_length--;e.strstart++,e.ins_h=(e.ins_h<=C&&(e.ins_h=(e.ins_h<=C&&e.match_length<=e.prev_length){for(i=e.strstart+e.lookahead-C,r=a._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-C),e.lookahead-=e.prev_length-1,e.prev_length-=2;++e.strstart<=i&&(e.ins_h=(e.ins_h<e.pending_buf_size-5&&(n=e.pending_buf_size-5);;){if(e.lookahead<=1){if(B(e),e.lookahead===0&&t===l)return O;if(e.lookahead===0)break}e.strstart+=e.lookahead,e.lookahead=0;var r=e.block_start+n;if((e.strstart===0||e.strstart>=r)&&(e.lookahead=e.strstart-r,e.strstart=r,I(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-T&&(I(e,!1),e.strm.avail_out===0))return O}return e.insert=0,t===u?(I(e,!0),e.strm.avail_out===0?A:j):(e.strstart>e.block_start&&(I(e,!1),e.strm.avail_out),O)}),new U(4,4,8,4,V),new U(4,5,16,8,V),new U(4,6,32,32,V),new U(4,4,16,16,H),new U(8,16,32,32,H),new U(8,16,128,128,H),new U(8,32,128,256,H),new U(32,128,258,1024,H),new U(32,258,258,4096,H)],n.deflateInit=function(e,t){return K(e,t,g,15,8,0)},n.deflateInit2=K,n.deflateReset=G,n.deflateResetKeep=W,n.deflateSetHeader=function(e,t){return e&&e.state&&e.state.wrap===2?(e.state.gzhead=t,d):f},n.deflate=function(e,t){var n,i,o,c;if(!e||!e.state||5>8&255),L(i,i.gzhead.time>>16&255),L(i,i.gzhead.time>>24&255),L(i,i.level===9?2:2<=i.strategy||i.level<2?4:0),L(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(L(i,255&i.gzhead.extra.length),L(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=s(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(L(i,0),L(i,0),L(i,0),L(i,0),L(i,0),L(i,i.level===9?2:2<=i.strategy||i.level<2?4:0),L(i,3),i.status=D);else{var p=g+(i.w_bits-8<<4)<<8;p|=(2<=i.strategy||i.level<2?0:i.level<6?1:i.level===6?2:3)<<6,i.strstart!==0&&(p|=32),p+=31-p%31,i.status=D,R(i,p),i.strstart!==0&&(R(i,e.adler>>>16),R(i,65535&e.adler)),e.adler=1}if(i.status===69)if(i.gzhead.extra){for(o=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),F(e),o=i.pending,i.pending!==i.pending_buf_size));)L(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(i.status===73)if(i.gzhead.name){o=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),F(e),o=i.pending,i.pending===i.pending_buf_size)){c=1;break}c=i.gzindexo&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),c===0&&(i.gzindex=0,i.status=91)}else i.status=91;if(i.status===91)if(i.gzhead.comment){o=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),F(e),o=i.pending,i.pending===i.pending_buf_size)){c=1;break}c=i.gzindexo&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),c===0&&(i.status=103)}else i.status=103;if(i.status===103&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&F(e),i.pending+2<=i.pending_buf_size&&(L(i,255&e.adler),L(i,e.adler>>8&255),e.adler=0,i.status=D)):i.status=D),i.pending!==0){if(F(e),e.avail_out===0)return i.last_flush=-1,d}else if(e.avail_in===0&&N(t)<=N(n)&&t!==u)return M(e,-5);if(i.status===666&&e.avail_in!==0)return M(e,-5);if(e.avail_in!==0||i.lookahead!==0||t!==l&&i.status!==666){var m=i.strategy===2?function(e,t){for(var n;;){if(e.lookahead===0&&(B(e),e.lookahead===0)){if(t===l)return O;break}if(e.match_length=0,n=a._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,n&&(I(e,!1),e.strm.avail_out===0))return O}return e.insert=0,t===u?(I(e,!0),e.strm.avail_out===0?A:j):e.last_lit&&(I(e,!1),e.strm.avail_out===0)?O:k}(i,t):i.strategy===3?function(e,t){for(var n,r,i,o,s=e.window;;){if(e.lookahead<=w){if(B(e),e.lookahead<=w&&t===l)return O;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=C&&0e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=C?(n=a._tr_tally(e,1,e.match_length-C),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(n=a._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),n&&(I(e,!1),e.strm.avail_out===0))return O}return e.insert=0,t===u?(I(e,!0),e.strm.avail_out===0?A:j):e.last_lit&&(I(e,!1),e.strm.avail_out===0)?O:k}(i,t):r[i.level].func(i,t);if(m!==A&&m!==j||(i.status=666),m===O||m===A)return e.avail_out===0&&(i.last_flush=-1),d;if(m===k&&(t===1?a._tr_align(i):t!==5&&(a._tr_stored_block(i,0,0,!1),t===3&&(P(i.head),i.lookahead===0&&(i.strstart=0,i.block_start=0,i.insert=0))),F(e),e.avail_out===0))return i.last_flush=-1,d}return t===u?i.wrap<=0?1:(i.wrap===2?(L(i,255&e.adler),L(i,e.adler>>8&255),L(i,e.adler>>16&255),L(i,e.adler>>24&255),L(i,255&e.total_in),L(i,e.total_in>>8&255),L(i,e.total_in>>16&255),L(i,e.total_in>>24&255)):(R(i,e.adler>>>16),R(i,65535&e.adler)),F(e),0=n.w_size&&(s===0&&(P(n.head),n.strstart=0,n.block_start=0,n.insert=0),p=new i.Buf8(n.w_size),i.arraySet(p,t,m-n.w_size,n.w_size,0),t=p,m=n.w_size),c=e.avail_in,l=e.next_in,u=e.input,e.avail_in=m,e.next_in=0,e.input=t,B(n);n.lookahead>=C;){for(r=n.strstart,a=n.lookahead-(C-1);n.ins_h=(n.ins_h<>>=b=y>>>24,m-=b,(b=y>>>16&255)==0)E[a++]=65535&y;else{if(!(16&b)){if(!(64&b)){y=h[(65535&y)+(p&(1<>>=b,m-=b),m<15&&(p+=T[r++]<>>=b=y>>>24,m-=b,!(16&(b=y>>>16&255))){if(!(64&b)){y=g[(65535&y)+(p&(1<>>=b,m-=b,(b=a-o)>3,p&=(1<<(m-=x<<3))-1,e.next_in=r,e.next_out=a,e.avail_in=r>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function g(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new r.Buf16(320),this.work=new r.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function _(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg=``,t.wrap&&(e.adler=1&t.wrap),t.mode=f,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new r.Buf32(p),t.distcode=t.distdyn=new r.Buf32(m),t.sane=1,t.back=-1,u):d}function v(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,_(e)):d}function y(e,t){var n,r;return e&&e.state?(r=e.state,t<0?(n=0,t=-t):(n=1+(t>>4),t<48&&(t&=15)),t&&(t<8||15=o.wsize?(r.arraySet(o.window,t,n-o.wsize,o.wsize,0),o.wnext=0,o.whave=o.wsize):(i<(a=o.wsize-o.wnext)&&(a=i),r.arraySet(o.window,t,n-i,a,o.wnext),(i-=a)?(r.arraySet(o.window,t,n-i,i,0),o.wnext=i,o.whave=o.wsize):(o.wnext+=a,o.wnext===o.wsize&&(o.wnext=0),o.whave>>8&255,n.check=a(n.check,B,2,0),x=b=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&b)<<8)+(b>>8))%31){e.msg=`incorrect header check`,n.mode=30;break}if((15&b)!=8){e.msg=`unknown compression method`,n.mode=30;break}if(x-=4,F=8+(15&(b>>>=4)),n.wbits===0)n.wbits=F;else if(F>n.wbits){e.msg=`invalid window size`,n.mode=30;break}n.dmax=1<>8&1),512&n.flags&&(B[0]=255&b,B[1]=b>>>8&255,n.check=a(n.check,B,2,0)),x=b=0,n.mode=3;case 3:for(;x<32;){if(v===0)break e;v--,b+=p[g++]<>>8&255,B[2]=b>>>16&255,B[3]=b>>>24&255,n.check=a(n.check,B,4,0)),x=b=0,n.mode=4;case 4:for(;x<16;){if(v===0)break e;v--,b+=p[g++]<>8),512&n.flags&&(B[0]=255&b,B[1]=b>>>8&255,n.check=a(n.check,B,2,0)),x=b=0,n.mode=5;case 5:if(1024&n.flags){for(;x<16;){if(v===0)break e;v--,b+=p[g++]<>>8&255,n.check=a(n.check,B,2,0)),x=b=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&(v<(E=n.length)&&(E=v),E&&(n.head&&(F=n.head.extra_len-n.length,n.head.extra||(n.head.extra=Array(n.head.extra_len)),r.arraySet(n.head.extra,p,g,E,F)),512&n.flags&&(n.check=a(n.check,p,E,g)),v-=E,g+=E,n.length-=E),n.length))break e;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(v===0)break e;for(E=0;F=p[g+ E++],n.head&&F&&n.length<65536&&(n.head.name+=String.fromCharCode(F)),F&&E>9&1,n.head.done=!0),e.adler=n.check=0,n.mode=12;break;case 10:for(;x<32;){if(v===0)break e;v--,b+=p[g++]<>>=7&x,x-=7&x,n.mode=27;break}for(;x<3;){if(v===0)break e;v--,b+=p[g++]<>>=1)){case 0:n.mode=14;break;case 1:if(w(n),n.mode=20,t!==6)break;b>>>=2,x-=2;break e;case 2:n.mode=17;break;case 3:e.msg=`invalid block type`,n.mode=30}b>>>=2,x-=2;break;case 14:for(b>>>=7&x,x-=7&x;x<32;){if(v===0)break e;v--,b+=p[g++]<>>16^65535)){e.msg=`invalid stored block lengths`,n.mode=30;break}if(n.length=65535&b,x=b=0,n.mode=15,t===6)break e;case 15:n.mode=16;case 16:if(E=n.length){if(v>>=5,x-=5,n.ndist=1+(31&b),b>>>=5,x-=5,n.ncode=4+(15&b),b>>>=4,x-=4,286>>=3,x-=3}for(;n.have<19;)n.lens[V[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,L={bits:n.lenbits},I=s(0,n.lens,0,19,n.lencode,0,n.work,L),n.lenbits=L.bits,I){e.msg=`invalid code lengths set`,n.mode=30;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,j=65535&z,!((k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>>=k,x-=k,n.lens[n.have++]=j;else{if(j===16){for(R=k+2;x>>=k,x-=k,n.have===0){e.msg=`invalid bit length repeat`,n.mode=30;break}F=n.lens[n.have-1],E=3+(3&b),b>>>=2,x-=2}else if(j===17){for(R=k+3;x>>=k)),b>>>=3,x-=3}else{for(R=k+7;x>>=k)),b>>>=7,x-=7}if(n.have+E>n.nlen+n.ndist){e.msg=`invalid bit length repeat`,n.mode=30;break}for(;E--;)n.lens[n.have++]=F}}if(n.mode===30)break;if(n.lens[256]===0){e.msg=`invalid code -- missing end-of-block`,n.mode=30;break}if(n.lenbits=9,L={bits:n.lenbits},I=s(c,n.lens,0,n.nlen,n.lencode,0,n.work,L),n.lenbits=L.bits,I){e.msg=`invalid literal/lengths set`,n.mode=30;break}if(n.distbits=6,n.distcode=n.distdyn,L={bits:n.distbits},I=s(l,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,L),n.distbits=L.bits,I){e.msg=`invalid distances set`,n.mode=30;break}if(n.mode=20,t===6)break e;case 20:n.mode=21;case 21:if(6<=v&&258<=y){e.next_out=_,e.avail_out=y,e.next_in=g,e.avail_in=v,n.hold=b,n.bits=x,o(e,C),_=e.next_out,m=e.output,y=e.avail_out,g=e.next_in,p=e.input,v=e.avail_in,b=n.hold,x=n.bits,n.mode===12&&(n.back=-1);break}for(n.back=0;A=(z=n.lencode[b&(1<>>16&255,j=65535&z,!((k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>M)])>>>16&255,j=65535&z,!(M+(k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>>=M,x-=M,n.back+=M}if(b>>>=k,x-=k,n.back+=k,n.length=j,A===0){n.mode=26;break}if(32&A){n.back=-1,n.mode=12;break}if(64&A){e.msg=`invalid literal/length code`,n.mode=30;break}n.extra=15&A,n.mode=22;case 22:if(n.extra){for(R=n.extra;x>>=n.extra,x-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;A=(z=n.distcode[b&(1<>>16&255,j=65535&z,!((k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>M)])>>>16&255,j=65535&z,!(M+(k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>>=M,x-=M,n.back+=M}if(b>>>=k,x-=k,n.back+=k,64&A){e.msg=`invalid distance code`,n.mode=30;break}n.offset=j,n.extra=15&A,n.mode=24;case 24:if(n.extra){for(R=n.extra;x>>=n.extra,x-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){e.msg=`invalid distance too far back`,n.mode=30;break}n.mode=25;case 25:if(y===0)break e;if(E=C-y,n.offset>E){if((E=n.offset-E)>n.whave&&n.sane){e.msg=`invalid distance too far back`,n.mode=30;break}D=E>n.wnext?(E-=n.wnext,n.wsize-E):n.wnext-E,E>n.length&&(E=n.length),O=n.window}else O=m,D=_-n.offset,E=n.length;for(yv?(b=L[R+d[w]],N[P+d[w]]):(b=96,0),p=1<>k)+(m-=p)]=y<<24|b<<16|x|0,m!==0;);for(p=1<>=1;if(p===0?M=0:(M&=p-1,M+=p),w++,--F[C]==0){if(C===E)break;C=t[n+d[w]]}if(D>>7)]}function L(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255}function R(e,t,n){e.bi_valid>h-n?(e.bi_buf|=t<>h-e.bi_valid,e.bi_valid+=n-h):(e.bi_buf|=t<>>=1,n<<=1,0<--t;);return n>>>1}function V(e,t,n){var r,i,a=Array(m+1),o=0;for(r=1;r<=m;r++)a[r]=o=o+n[r-1]<<1;for(i=0;i<=t;i++){var s=e[2*i+1];s!==0&&(e[2*i]=B(a[s]++,s))}}function H(e){var t;for(t=0;t>1;1<=n;n--)W(e,a,n);for(i=c;n=e.heap[1],e.heap[1]=e.heap[e.heap_len--],W(e,a,1),r=e.heap[1],e.heap[--e.heap_max]=n,e.heap[--e.heap_max]=r,a[2*i]=a[2*n]+a[2*r],e.depth[i]=(e.depth[n]>=e.depth[r]?e.depth[n]:e.depth[r])+1,a[2*n+1]=a[2*r+1]=i,e.heap[1]=i++,W(e,a,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var n,r,i,a,o,s,c=t.dyn_tree,l=t.max_code,u=t.stat_desc.static_tree,d=t.stat_desc.has_stree,f=t.stat_desc.extra_bits,h=t.stat_desc.extra_base,g=t.stat_desc.max_length,_=0;for(a=0;a<=m;a++)e.bl_count[a]=0;for(c[2*e.heap[e.heap_max]+1]=0,n=e.heap_max+1;n>=7;r>>=1)if(1&n&&e.dyn_ltree[2*t]!==0)return i;if(e.dyn_ltree[18]!==0||e.dyn_ltree[20]!==0||e.dyn_ltree[26]!==0)return a;for(t=32;t>>3,(s=e.static_len+3+7>>>3)<=o&&(o=s)):o=s=n+5,n+4<=o&&t!==-1?X(e,t,n,r):e.strategy===4||s===o?(R(e,2+ +!!r,3),G(e,T,E)):(R(e,4+ +!!r,3),function(e,t,n,r){var i;for(R(e,t-257,5),R(e,n-1,5),R(e,r-4,4),i=0;i>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&n,e.last_lit++,t===0?e.dyn_ltree[2*n]++:(e.matches++,t--,e.dyn_ltree[2*(O[n]+l+1)]++,e.dyn_dtree[2*I(t)]++),e.last_lit===e.lit_bufsize-1},n._tr_align=function(e){R(e,2,3),z(e,_,T),function(e){e.bi_valid===16?(L(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}(e)}},{"../utils/common":41}],53:[function(e,t,n){t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg=``,this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(e,t,n){(function(e){(function(e,t){if(!e.setImmediate){var n,r,i,a,o=1,s={},c=!1,l=e.document,u=Object.getPrototypeOf&&Object.getPrototypeOf(e);u=u&&u.setTimeout?u:e,n={}.toString.call(e.process)===`[object process]`?function(e){process.nextTick(function(){f(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage(``,`*`),e.onmessage=n,t}}()?(a=`setImmediate$`+Math.random()+`$`,e.addEventListener?e.addEventListener(`message`,p,!1):e.attachEvent(`onmessage`,p),function(t){e.postMessage(a+t,`*`)}):e.MessageChannel?((i=new MessageChannel).port1.onmessage=function(e){f(e.data)},function(e){i.port2.postMessage(e)}):l&&`onreadystatechange`in l.createElement(`script`)?(r=l.documentElement,function(e){var t=l.createElement(`script`);t.onreadystatechange=function(){f(e),t.onreadystatechange=null,r.removeChild(t),t=null},r.appendChild(t)}):function(e){setTimeout(f,0,e)},u.setImmediate=function(e){typeof e!=`function`&&(e=Function(``+e));for(var t=Array(arguments.length-1),r=0;r`u`?e===void 0?this:e:self)}).call(this,typeof global<`u`?global:typeof self<`u`?self:typeof window<`u`?window:{})},{}]},{},[10])(10)})}))(),1),Q=r(),ae=null,oe=0,$=new Map;function se(e){for(let t of $.values())t.reject(Error(e));$.clear()}function ce(){if(!ae){let e=new Worker(new URL(`/assets/stepPreview.worker-QYcQPnWg.js`,``+import.meta.url),{type:`module`});e.onmessage=e=>{let t=$.get(e.data.id);t&&($.delete(e.data.id),e.data.ok?t.resolve(e.data.meshes):t.reject(Error(e.data.reason)))},e.onerror=()=>{se(`error`),e.terminate(),ae===e&&(ae=null)},ae=e}return ae}function le(e){return new Promise((t,n)=>{let r=++oe;$.set(r,{resolve:t,reject:n}),ce().postMessage({id:r,buffer:e},[e])})}var ue=8;function de(e,t,n,r,i=1.15){let a=n.getSize(new x),o=n.getCenter(new x),s=Math.max(a.length()/2,.001),c=O.degToRad(e.fov),l=2*Math.atan(Math.tan(c/2)*e.aspect),u=i*Math.max(s/Math.sin(c/2),s/Math.sin(l/2)),d=new x(.7,.5,.7).normalize();e.position.copy(o).addScaledVector(d,u),t.minDistance=Math.max(s*.05,.05),t.maxDistance=u*ue,e.near=Math.max(u/1e3,.01),e.far=t.maxDistance+s*4+r,e.updateProjectionMatrix(),t.target.copy(o),t.update()}var fe={x:256,y:256,z:256};function pe(){return new Promise(e=>setTimeout(e,0))}var me=2e4,he=2e4;function ge(e){let t=new G;if(!e)return t;let n=e.trim().split(/\s+/).map(parseFloat);return n.length>=12&&t.set(n[0],n[1],n[2],n[9],n[3],n[4],n[5],n[10],n[6],n[7],n[8],n[11],0,0,0,1),t}var _e=ge;async function ve(e,t=0){let n=[],r=e.getElementsByTagName(`mesh`);for(let e=0;e0&&e%me===0&&await pe()}let c=i.getElementsByTagName(`triangle`);for(let e=0;e0&&e%he===0&&await pe()}a.length>0&&o.length>0&&n.push({vertices:a,triangles:o,extruder:t})}return n}function ye(e){let t=Array.from(e.attributes).find(e=>{let t=e.name.toLowerCase();return t===`plate_id`||t===`plater_id`||t===`plateid`||t===`platerid`||t.endsWith(`:plate_id`)||t.endsWith(`:plater_id`)});if(!t?.value)return null;let n=Number.parseInt(t.value,10);return Number.isFinite(n)?n:null}async function be(e){let t;try{t=await ie.default.loadAsync(e)}catch{throw Error(`Unsupported file format`)}let n=new Map,r=[],i=new Map,a=new Map,o=new DOMParser;async function s(e){let n=e.startsWith(`/`)?e.slice(1):e,r=t.files[n];if(!r)return null;let i=await r.async(`string`);return o.parseFromString(i,`application/xml`)}let c=new Map,l=new Map,u=new Map,d=new Map,f=t.files[`Metadata/model_settings.config`];if(f)try{let e=await f.async(`string`),t=o.parseFromString(e,`application/xml`),n=t.getElementsByTagName(`object`);for(let e=0;ee.tagName===`metadata`&&e.getAttribute(`key`)===`extruder`);if(i.length>0){let e=i[0].getAttribute(`value`);e&&c.set(r,Math.max(0,parseInt(e,10)-1))}let a=Array.from(t.children).find(e=>e.tagName===`metadata`&&e.getAttribute(`key`)===`name`)?.getAttribute(`value`);a&&u.set(r,a);let o=t.getElementsByTagName(`part`);for(let e=0;ee.tagName===`metadata`&&e.getAttribute(`key`)===`extruder`);if(i.length>0){let e=i[0].getAttribute(`value`);e&&l.set(`${r}:${n}`,Math.max(0,parseInt(e,10)-1))}}}let r=t.getElementsByTagName(`plate`);for(let e=0;ee.startsWith(`Metadata/plate_`)&&e.endsWith(`.json`));for(let e of m){let n=e.match(/^Metadata\/plate_(\d+)\.json$/);if(!n)continue;let r=Number.parseInt(n[1],10);if(Number.isFinite(r))try{let n=await t.files[e].async(`string`),a=JSON.parse(n),o=a.bbox_objects??[];for(let e of o)e?.name&&p.set(e.name,r);if(Array.isArray(a.bbox_all)&&a.bbox_all.length>=4){let[e,t,n,o]=a.bbox_all;[e,t,n,o].every(e=>Number.isFinite(e))&&i.set(r,{minX:e,minY:t,maxX:n,maxY:o})}}catch{}}let h=Object.keys(t.files).find(e=>e===`3D/3dmodel.model`||e.endsWith(`/3dmodel.model`));if(!h){let e=Object.keys(t.files).find(e=>e.endsWith(`.model`));if(e){let t=await s(e);if(t){let e=await ve(t,0);e.length>0&&n.set(`1`,{id:`1`,meshes:e,defaultExtruder:0})}}return{objects:n,buildItems:r,plateBounds:i,plateOffsets:a}}let g=await s(h);if(!g)return{objects:n,buildItems:r,plateBounds:i,plateOffsets:a};let _=g.getElementsByTagName(`object`);for(let e=0;e<_.length;e++){e>0&&await pe();let t=_[e],r=t.getAttribute(`id`);if(!r)continue;let i=ye(t)??d.get(r)??null,a=c.get(r)??-1;if(a<0){let e=t.getAttribute(`p:extruder`)||t.getAttributeNS(`http://schemas.microsoft.com/3dmanufacturing/production/2015/06`,`extruder`)||`1`;a=Math.max(0,parseInt(e,10)-1)}let o=[],u=t.getElementsByTagName(`mesh`);for(let e=0;e0&&e%me===0&&await pe()}let s=t.getElementsByTagName(`triangle`);for(let e=0;e0&&e%he===0&&await pe()}n.length>0&&r.length>0&&o.push({vertices:n,triangles:r,extruder:a})}let f=t.getElementsByTagName(`component`);for(let e=0;e0&&n.set(r,{id:r,meshes:o,defaultExtruder:a,plateId:i})}let v=g.getElementsByTagName(`build`);if(v.length>0){let e=v[0].getElementsByTagName(`item`);for(let t=0;t{if(e instanceof J)if(e.geometry.dispose(),Array.isArray(e.material))for(let t of e.material)t.dispose();else e.material.dispose()})}function Ce(e,t,n){let{objects:r,buildItems:i}=e,a=new R,o=e=>new E({color:new L(n?.[e]||`#00ae42`),roughness:.62,metalness:0,envMapIntensity:.55,flatShading:!1}),s=new Map,c=i.some(e=>e.plateId!=null),l=t==null||!c?i:i.filter(e=>e.plateId===t),u=l.length>0?l:i;if(u.length>0)for(let e of u){let t=r.get(e.objectId);if(t)for(let n of t.meshes){let t=e.extruder??n.extruder,r=[];for(let t=0;t1)for(let e of t)e.dispose()}return a}function we(e,t){let n=new R,r=t?.[0]||`#00ae42`;for(let t of e){let e=new j;e.setAttribute(`position`,new U(t.positions,3)),t.normals&&e.setAttribute(`normal`,new U(t.normals,3)),t.indices&&e.setIndex(new U(t.indices,1)),t.normals||e.computeVertexNormals(),e.rotateX(-Math.PI/2);let i=new J(e,new E({color:t.color?new L(t.color[0],t.color[1],t.color[2]):new L(r),roughness:.62,metalness:0,envMapIntensity:.55}));i.castShadow=!0,n.add(i)}return n}function Te({url:e,fileType:t,buildVolume:n=fe,filamentColors:r,selectedPlateId:i=null,className:a=``,onSnapshot:c}){let{t:l}=s(),u=(0,Y.useRef)(null),f=(0,Y.useRef)(null),_=(0,Y.useRef)(null),v=(0,Y.useRef)(null),y=(0,Y.useRef)(null),b=(0,Y.useRef)(null),S=(0,Y.useRef)(null),C=(0,Y.useRef)(null),w=(0,Y.useRef)(null),O=(0,Y.useRef)(null),j=(0,Y.useRef)(null),M=(0,Y.useRef)(null),N=(0,Y.useRef)(null),[P,F]=(0,Y.useState)(!0),[B,U]=(0,Y.useState)(null),[G,q]=(0,Y.useState)(null),[X,te]=(0,Y.useState)(null),[Z,ie]=(0,Y.useState)(null),[ae,oe]=(0,Y.useState)(0),$=(t||e.split(`?`)[0].split(`.`).pop()||``).toLowerCase(),se=$===`step`||$===`stp`;(0,Y.useEffect)(()=>{if(!P||!se)return;oe(0);let e=Date.now(),t=window.setInterval(()=>{oe(Math.floor((Date.now()-e)/1e3))},1e3);return()=>window.clearInterval(t)},[P,se]);let ce=(0,Y.useRef)(!1),ue=(0,Y.useRef)(c);(0,Y.useEffect)(()=>{ue.current=c}),(0,Y.useEffect)(()=>{if(!u.current)return;let r=u.current,i=r.clientWidth,a=r.clientHeight,s=new T;s.background=new L(1710618),_.current=s;let c=new K(45,i/a,.1,1e4);c.position.set(150,150,150),v.current=c;let d=new H({antialias:!0});d.setSize(i,a),d.setPixelRatio(Math.min(window.devicePixelRatio,2)),d.toneMapping=4,d.toneMappingExposure=.85,d.shadowMap.enabled=!0,d.shadowMap.type=2,r.appendChild(d.domElement),f.current=d;let p=new ee(c,d.domElement);p.enableDamping=!0,p.dampingFactor=.05,w.current=p;let m=new z(d),h=m.fromScene(new re,.04);s.environment=h.texture,y.current=m,b.current=h.texture;let g=new W(16777215,.75);g.position.set(60,260,90),g.castShadow=!0,g.shadow.mapSize.set(2048,2048),g.shadow.bias=-5e-4,g.shadow.normalBias=.02;let x=Math.max(n.x,n.y)*.75;g.shadow.camera.left=-x,g.shadow.camera.right=x,g.shadow.camera.top=x,g.shadow.camera.bottom=-x,g.shadow.camera.near=1,g.shadow.camera.far=x*6,g.shadow.camera.updateProjectionMatrix(),s.add(g),S.current=g;let E=Math.max(n.x,n.y),k=new V(E,Math.ceil(E/16),4473924,3355443);s.add(k),M.current=k;let N=new J(new D(n.x,n.y),new A({color:44610,transparent:!0,opacity:.15,side:2}));N.rotation.x=-Math.PI/2,N.position.y=-.5,s.add(N),j.current=N;let P=new J(new D(n.x,n.y),new I({opacity:.22}));P.rotation.x=-Math.PI/2,P.position.y=-.49,P.receiveShadow=!0,s.add(P),C.current=P;let R,B=()=>{R=requestAnimationFrame(B),p.update(),d.render(s,c)};B(),F(!0),U(null),q(null),te(null),ie(null),ce.current=!1;let G=(t||e.split(`?`)[0].split(`.`).pop()||``).toLowerCase(),Y={},X=o();X&&(Y.Authorization=`Bearer ${X}`),G===`stl`?fetch(e,{headers:Y}).then(e=>{if(!e.ok)throw Error(l(`modelViewer.errors.failedToLoad`));return e.arrayBuffer()}).then(e=>{let t=new ne().parse(e);t.computeVertexNormals(),t.rotateX(-Math.PI/2),te(t)}).catch(e=>{U(e.message),F(!1)}):G===`3mf`?fetch(e,{headers:Y}).then(e=>{if(!e.ok)throw Error(l(`modelViewer.errors.failedToLoad`));return e.arrayBuffer()}).then(be).then(e=>{if(e.objects.size===0)throw Error(l(`modelViewer.errors.noMeshes`));q(e)}).catch(e=>{U(e.message),F(!1)}):G===`step`||G===`stp`?fetch(e,{headers:Y}).then(e=>{if(!e.ok)throw Error(l(`modelViewer.errors.failedToLoad`));return e.arrayBuffer()}).then(le).then(ie).catch(e=>{U(e.message===`no-meshes`?l(`modelViewer.errors.noMeshes`):e.message===`error`?l(`modelViewer.errors.failedToLoad`):e.message),F(!1)}):(U(l(`modelViewer.errors.unsupportedFormat`)),F(!1));let Z=()=>{if(!r)return;let e=r.clientWidth,t=r.clientHeight;e===0||t===0||(c.aspect=e/t,c.updateProjectionMatrix(),d.setSize(e,t))};window.addEventListener(`resize`,Z),document.addEventListener(`fullscreenchange`,Z);let Q=new ResizeObserver(()=>{Z()});return Q.observe(r),()=>{window.removeEventListener(`resize`,Z),document.removeEventListener(`fullscreenchange`,Z),Q.disconnect(),cancelAnimationFrame(R),p.dispose(),b.current?.dispose(),b.current=null,y.current?.dispose(),y.current=null,s.environment=null,d.dispose(),r.removeChild(d.domElement),O.current=null,j.current=null,M.current=null,S.current=null,C.current=null}},[e,n,t,l]),(0,Y.useEffect)(()=>{if(!_.current||!v.current||!w.current||!G&&!X&&!Z)return;O.current&&(_.current.remove(O.current),Se(O.current));let e=!!X||!!Z,t=X?(()=>{let e=new J(X,new E({color:new L(r?.[0]||`#00ae42`),roughness:.62,metalness:0,envMapIntensity:.55}));e.castShadow=!0;let t=new R;return t.add(e),t})():Z?we(Z,r):Ce(G,i??null,r);O.current=t,_.current.add(t);let a=new k().setFromObject(t),o=a.getCenter(new x);t.position.y=-a.min.y;let s=!e&&i!=null&&G.buildItems.length>0?G.plateBounds.get(i):void 0,c=!e&&i!=null?G.plateOffsets.get(i):void 0,l=e||G.buildItems.length===0||i!=null&&!s&&!c,u=l?-o.x:0,d=l?-o.z:0,p=0,m=0;if(!e&&i!=null&&G.buildItems.length>0&&s){let e=new k().setFromObject(t);p=e.min.x-s.minX,m=e.min.z-s.minY}let h=n.x/2,g=n.y/2;!e&&i!=null&&G.buildItems.length>0&&s?(t.position.x=u-p,t.position.z=d-m):!e&&i!=null&&c?(t.position.x=u+(h-c.offsetX),t.position.z=d+(g-c.offsetY)):l?(t.position.x=u+h,t.position.z=d+g):(t.position.x=u,t.position.z=d),j.current&&(j.current.position.x=h,j.current.position.z=g),M.current&&(M.current.position.x=h,M.current.position.z=g),C.current&&(C.current.position.x=h,C.current.position.z=g);let y=new k().setFromObject(t);N.current=y,de(v.current,w.current,y,Math.hypot(n.x,n.y)),F(!1),ue.current&&!ce.current&&(ce.current=!0,requestAnimationFrame(()=>{let e=f.current,t=_.current,n=v.current;if(!(!e||!t||!n))try{e.render(t,n);let r=e.domElement,i=Math.min(r.width,r.height),a=document.createElement(`canvas`);a.width=256,a.height=256;let o=a.getContext(`2d`);if(!o)return;o.drawImage(r,(r.width-i)/2,(r.height-i)/2,i,i,0,0,256,256),a.toBlob(e=>{e&&ue.current?.(e)},`image/png`)}catch{}}))},[G,X,Z,i,r,n]);let pe=()=>{let e=v.current,t=w.current;!e||!t||(N.current?de(e,t,N.current,Math.hypot(n.x,n.y)):(e.position.set(150,150,150),t.target.set(0,50,0),t.update()))},me=e=>{let t=v.current,n=w.current;if(!t||!n)return;let r=t.position.clone().sub(n.target),i=Math.min(n.maxDistance,Math.max(n.minDistance,r.length()*e));t.position.copy(n.target).addScaledVector(r.normalize(),i),n.update()};return(0,Q.jsxs)(`div`,{className:`relative ${a}`,children:[(0,Q.jsx)(`div`,{ref:u,className:`w-full h-full min-h-[400px]`}),P&&(0,Q.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-3 bg-bambu-dark/80 px-6 text-center`,children:[(0,Q.jsx)(d,{className:`w-8 h-8 text-bambu-green animate-spin`}),se&&(0,Q.jsxs)(`div`,{role:`status`,className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-white tabular-nums`,children:l(`modelViewer.stepConverting`,{seconds:ae})}),(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`modelViewer.stepSlowHint`)})]})]}),B&&(0,Q.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,Q.jsx)(`p`,{className:`text-red-400`,children:B})}),!P&&!B&&(0,Q.jsxs)(`div`,{className:`absolute bottom-4 right-4 flex gap-2`,children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>me(.8),children:(0,Q.jsx)(p,{className:`w-4 h-4`})}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>me(1.25),children:(0,Q.jsx)(m,{className:`w-4 h-4`})}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:pe,children:(0,Q.jsx)(g,{className:`w-4 h-4`})})]})]})}function Ee({folderId:e,onClose:t,onUploadComplete:n,onFileUploaded:r,autoUpload:i,validateFile:o,accept:p,initialFiles:m}){let{t:g}=s(),[x,S]=(0,Y.useState)([]),[C,w]=(0,Y.useState)(!1),[T,E]=(0,Y.useState)(!1),[D,O]=(0,Y.useState)(!0),[k,A]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(!0),[N,P]=(0,Y.useState)(null),F=(0,Y.useRef)(null),I=e=>{e.preventDefault(),w(!0)},L=e=>{e.preventDefault(),w(!1)},R=e=>{e.preventDefault(),w(!1),H(Array.from(e.dataTransfer.files))},z=e=>{e.target.files&&H(Array.from(e.target.files))},B=(e,t)=>{S(n=>n.map(n=>n.file===e?{...n,...t}:n))},V=async i=>{E(!0);for(let t of i)if(t.status===`pending`){B(t.file,{status:`uploading`});try{if(t.isZip){let n=await a.extractZipFile(t.file,e,D,k,j);B(t.file,{status:n.errors.length>0&&n.extracted===0?`error`:`success`,extractedCount:n.extracted,error:n.errors.length>0?g(`fileManager.zipFilesFailed`,`{{count}} files failed`,{count:n.errors.length}):void 0})}else{let n=await a.uploadLibraryFile(t.file,e,j);B(t.file,{status:`success`});let i=r?.(n);if(i){P(i),S([]),E(!1);return}}}catch(e){B(t.file,{status:`error`,error:e instanceof Error?e.message:g(`fileManager.uploadFailed`,`Upload failed`)})}}E(!1),n(),S(e=>(e.some(e=>e.status===`error`)||t(),e))},H=e=>{if(P(null),o)for(let t of e){let e=o(t);if(e){P(e);return}}let t=e.map(e=>({file:e,status:`pending`,isZip:e.name.toLowerCase().endsWith(`.zip`),is3mf:e.name.toLowerCase().endsWith(`.3mf`)}));S(e=>[...e,...t]),i&&e.length>0&&V(t)},U=e=>{S(t=>t.filter((t,n)=>n!==e))},ee=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>{ee.current||!m||m.length===0||(ee.current=!0,H(m))},[]);let W=x.some(e=>e.isZip&&e.status===`pending`),G=x.some(e=>e.file.name.toLowerCase().endsWith(`.stl`)&&e.status===`pending`),K=x.some(e=>e.is3mf&&e.status===`pending`),q=x.filter(e=>e.status===`pending`).length,J=x.length>0&&q===0&&!T;return(0,Q.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,Q.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary`,children:[(0,Q.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:g(`fileManager.uploadFiles`)}),(0,Q.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,Q.jsx)(f,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Q.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,Q.jsxs)(`div`,{onDragOver:I,onDragLeave:L,onDrop:R,onClick:()=>F.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${C?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,Q.jsx)(y,{className:`w-10 h-10 mx-auto mb-3 ${C?`text-bambu-green`:`text-bambu-gray`}`}),(0,Q.jsx)(`p`,{className:`text-white font-medium`,children:g(C?`fileManager.dropFilesHere`:`fileManager.dragDropFiles`)}),(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:g(`fileManager.orClickToBrowse`)}),(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-2`,children:g(`fileManager.allFileTypesSupported`)})]}),(0,Q.jsx)(`input`,{ref:F,type:`file`,multiple:!0,accept:p,className:`hidden`,onChange:z}),W&&(0,Q.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,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(v,{className:`w-5 h-5 text-blue-600 dark:text-blue-400 mt-0.5 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-blue-700 dark:text-blue-300 font-medium`,children:g(`fileManager.zipFilesDetected`)}),(0,Q.jsx)(`p`,{className:`text-xs text-blue-700/80 dark:text-blue-300/70 mt-1`,children:g(`fileManager.zipExtractOptions`)}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:D,onChange:e=>O(e.target.checked),className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Q.jsx)(`span`,{className:`text-sm text-white`,children:g(`fileManager.preserveZipStructure`)})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:k,onChange:e=>A(e.target.checked),className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Q.jsx)(`span`,{className:`text-sm text-white`,children:g(`fileManager.createFolderFromZip`)})]})]})]})}),K&&(0,Q.jsx)(`div`,{className:`p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(_,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 mt-0.5 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-purple-700 dark:text-purple-300 font-medium`,children:g(`fileManager.threemfDetected`)}),(0,Q.jsx)(`p`,{className:`text-xs text-purple-700/80 dark:text-purple-300/70 mt-1`,children:g(`fileManager.threemfExtractionInfo`)})]})]})}),(G||W)&&(0,Q.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(b,{className:`w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-green font-medium`,children:g(`fileManager.stlThumbnailGeneration`)}),(0,Q.jsx)(`p`,{className:`text-xs text-bambu-green/70 mt-1`,children:g(W&&!G?`fileManager.zipMayContainStl`:`fileManager.thumbnailsCanBeGenerated`)}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>M(e.target.checked),className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Q.jsx)(`span`,{className:`text-sm text-white`,children:g(`fileManager.generateThumbnailsForStl`)})]})]})]})}),x.length>0&&(0,Q.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-2`,children:x.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 p-2 bg-bambu-dark rounded-lg`,children:[e.isZip?(0,Q.jsx)(v,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0`}):(0,Q.jsx)(u,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.file.name}),(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/1024/1024).toFixed(2),` MB`,e.isZip&&e.status===`pending`&&(0,Q.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-400 ml-2`,children:[`• `,g(`fileManager.willBeExtracted`)]}),e.extractedCount!==void 0&&(0,Q.jsxs)(`span`,{className:`text-green-700 dark:text-green-400 ml-2`,children:[`• `,g(`fileManager.filesExtracted`,{count:e.extractedCount})]})]}),e.status===`error`&&e.error&&(0,Q.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1 break-words`,children:e.error})]}),e.status===`pending`&&(0,Q.jsx)(`button`,{onClick:()=>U(t),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Q.jsx)(f,{className:`w-4 h-4 text-bambu-gray`})}),e.status===`uploading`&&(0,Q.jsx)(d,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,Q.jsx)(l,{className:`w-4 h-4 text-green-500`}),e.status===`error`&&(0,Q.jsx)(`span`,{title:e.error,children:(0,Q.jsx)(c,{className:`w-4 h-4 text-red-500`})})]},t))}),N&&(0,Q.jsx)(`div`,{className:`p-3 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(c,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,Q.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:N})]})})]}),(0,Q.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,Q.jsx)(h,{variant:`secondary`,onClick:t,children:g(`common.cancel`)}),!J&&(0,Q.jsx)(h,{onClick:()=>V(x),disabled:q===0||T,children:T?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(d,{className:`w-4 h-4 mr-2 animate-spin`}),g(`fileManager.uploading`)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{className:`w-4 h-4 mr-2`}),g(`common.upload`),` `,q>0?`(${q})`:``]})})]})]})})}export{Te as n,Ee as t};
\ No newline at end of file
diff --git a/static/assets/FinancePage-COWXFGjj.js b/static/assets/FinancePage-1_FzUI4P.js
similarity index 99%
rename from static/assets/FinancePage-COWXFGjj.js
rename to static/assets/FinancePage-1_FzUI4P.js
index 632efe66a..8ba7e4996 100644
--- a/static/assets/FinancePage-COWXFGjj.js
+++ b/static/assets/FinancePage-1_FzUI4P.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as ee}from"./client-BdOyoZJz.js";import{n as te}from"./QueryClientProvider-Clbyr4Jg.js";import{t as i}from"./useQuery-CCy0EwsM.js";import{t as a}from"./useMutation-qh3Iyscy.js";import{t as o}from"./createLucideIcon-Yo2YoYjm.js";import{n as ne,t as re}from"./chevrons-right-OnQ-9jKz.js";import{n as ie}from"./ToastContext-VFOrCCoA.js";import{i as s,n as c,t as l}from"./Card-OUAj0Ayh.js";import{t as u}from"./Button-pwVKPiYn.js";import{v as d}from"./date-G9KUauqz.js";import{$t as ae,At as oe,Mn as se,_t as ce,at as le,jn as ue,yt as de}from"./index-Bw-_P2Fg.js";var fe=o(`building-2`,[[`path`,{d:`M10 12h4`,key:`a56b0p`}],[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M14 21v-3a2 2 0 0 0-4 0v3`,key:`1rgiei`}],[`path`,{d:`M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2`,key:`secmi2`}],[`path`,{d:`M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16`,key:`16ra0t`}]]),pe=o(`clock-3`,[[`path`,{d:`M12 6v6h4`,key:`135r8i`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),me=o(`wallet`,[[`path`,{d:`M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1`,key:`18etb6`}],[`path`,{d:`M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4`,key:`xoc0q4`}]]),f=e(n(),1),p=t(),m=/\[(aborted|failed|cancelled):\s*([^\]]*)\]/i;function he(e){if(!e)return{isPartial:!1,partialType:null,cleanedDescription:null};let t=e.match(m);if(!t)return{isPartial:!1,partialType:null,cleanedDescription:e};let n=e.replace(t[0],``).trim();return{isPartial:!0,partialType:t[1].toLowerCase(),cleanedDescription:n||null}}function ge(e,t){if(!e)return`-`;let n=d(e);return n?n.toLocaleString(t):e}function h(e){let t=e.trim();if(!t)return null;let n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function _e(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}T${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}var g=`w-full px-3 py-2 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:outline-none focus:ring-1 focus:ring-bambu-green`,_=`block text-sm font-medium text-white mb-1`,v=`px-4 py-3 text-left text-bambu-gray font-medium`,y=`px-4 py-3 align-top text-white`;function b({title:e,onClose:t,children:n,size:r=`md`}){let{t:te}=ee();return(0,p.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,p.jsxs)(`div`,{className:`w-full ${r===`sm`?`max-w-xl`:r===`lg`?`max-w-6xl`:`max-w-4xl`} overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,p.jsxs)(`div`,{className:`flex items-center justify-between border-b border-bambu-dark-tertiary px-4 py-3`,children:[(0,p.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e}),(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:t,children:te(`common.close`,`Close`)})]}),(0,p.jsx)(`div`,{className:`max-h-[75vh] overflow-auto p-4`,children:n})]})})}function x(){let{t:e,i18n:t}=ee(),{hasPermission:n,user:o}=de(),{showToast:d}=ie(),m=te(),x=n(`cost_centers:read_own`),S=n(`cost_centers:read_all`),C=n(`cost_centers:create`),w=n(`cost_centers:modify`),T=n(`cost_centers:modify`),E=n(`cost_centers:modify`),D=n(`cost_centers:modify`),O=n(`users:read_slim`)||n(`users:read`),ve=S||C||w||T||E||D,ye=x||ve,be=ye,[xe,Se]=(0,f.useState)(``),[k,Ce]=(0,f.useState)(`monthly`),[we,Te]=(0,f.useState)(``),[A,Ee]=(0,f.useState)(null),[De,Oe]=(0,f.useState)(`deposit`),[ke,Ae]=(0,f.useState)(``),[je,Me]=(0,f.useState)(``),[Ne,Pe]=(0,f.useState)(null),[j,M]=(0,f.useState)(null),[Fe,Ie]=(0,f.useState)(null),[Le,Re]=(0,f.useState)(!0),[N,P]=(0,f.useState)(0),[F,ze]=(0,f.useState)(`all`),[I,Be]=(0,f.useState)(`all`),[Ve,He]=(0,f.useState)(!1),[Ue,We]=(0,f.useState)(!1),[Ge,Ke]=(0,f.useState)(!1),[L,qe]=(0,f.useState)(!1),[R,Je]=(0,f.useState)(`personal`),[z,Ye]=(0,f.useState)(null),[Xe,Ze]=(0,f.useState)(``),[Qe,B]=(0,f.useState)(`monthly`),[$e,V]=(0,f.useState)(``),[et,tt]=(0,f.useState)(!1),[nt,rt]=(0,f.useState)(null),[it,at]=(0,f.useState)(null),[ot,st]=(0,f.useState)(null),[ct,lt]=(0,f.useState)(``),[ut,dt]=(0,f.useState)(``),[ft,H]=(0,f.useState)(!1),[pt,mt]=(0,f.useState)(null),[ht,gt]=(0,f.useState)(null),[_t,vt]=(0,f.useState)(``),[yt,bt]=(0,f.useState)(``),[xt,St]=(0,f.useState)(_e(new Date)),[U,Ct]=(0,f.useState)(null),[wt,Tt]=(0,f.useState)(null),W=S||C||w||T||D&&O||E&&O;(0,f.useEffect)(()=>{W||Je(`personal`)},[W]);let{data:Et,isLoading:Dt}=i({queryKey:[`finance`,`me`,`balance`],queryFn:r.getMyBalance,enabled:x}),{data:Ot}=i({queryKey:[`ui-flags`],queryFn:r.getUiFlags}),{data:kt,isLoading:At}=i({queryKey:[`finance`,`me`,`transactions`,50,N],queryFn:()=>r.getMyTransactions(50,N),enabled:x}),{data:jt,isLoading:Mt}=i({queryKey:[`finance`,`transactions`,50,N],queryFn:()=>r.getAllTransactions(50,N),enabled:R===`admin`&&S}),{data:G,isLoading:K}=i({queryKey:[`finance`,`cost-centers`,R],queryFn:()=>R===`admin`&&ve?r.listCostCenters(!0):r.getMyCostCenters(),enabled:be}),{data:q}=i({queryKey:[`users`,`slim`],queryFn:r.getUsersSlim,enabled:O&&(be||D||E)}),{data:J}=i({queryKey:[`finance`,`cost-center`,j],queryFn:()=>r.getCostCenter(j),enabled:E&&j!=null});(0,f.useEffect)(()=>{!q||q.length===0||A!=null&&q.some(e=>e.id===A)||Ee(q[0].id)},[q,A]),(0,f.useEffect)(()=>{if(!E)return;let e=(G||[]).filter(e=>!e.is_private);if(e.length===0){M(null);return}j!=null&&e.some(e=>e.id===j)||M(e[0].id)},[E,G,j]),(0,f.useEffect)(()=>{if(!E||!q||q.length===0)return;let e=new Set((J?.members||[]).map(e=>e.user_id)),t=q.find(t=>!e.has(t.id));Ie(t?t.id:null)},[E,q,J]),(0,f.useEffect)(()=>{if(!L)return;let e=G||[];if(e.length===0){Ye(null);return}z!=null&&e.some(e=>e.id===z)||Ye(e[0].id)},[L,z,G]),(0,f.useEffect)(()=>{if(!L||z==null)return;let e=(G||[]).find(e=>e.id===z);if(e){if(Ze(e.name),e.budget_mode===`total`){B(`total`),V(e.total_budget==null?``:String(e.total_budget));return}B(`monthly`),V(e.monthly_budget==null?``:String(e.monthly_budget))}},[L,z,G]);let Nt=a({mutationFn:()=>r.createCostCenter({name:xe.trim(),total_budget:k===`total`?h(we):null,monthly_budget:k===`monthly`?h(we):null,is_active:!0}),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),Se(``),Te(``),d(e(`finance.createdCostCenter`,`Cost center created`))},onError:t=>{d(t.message||e(`finance.createCostCenterFailed`,`Failed to create cost center`),`error`)}}),Pt=a({mutationFn:({costCenterId:e,value:t,mode:n})=>r.updateCostCenterBudgets(e,{total_budget:n===`total`?h(t):null,monthly_budget:n===`monthly`?h(t):null})}),Ft=a({mutationFn:({costCenterId:e,name:t})=>r.updateCostCenter(e,{name:t})}),It=a({mutationFn:e=>r.deleteCostCenter(e)}),Lt=a({mutationFn:e=>r.deleteTransaction(e),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.transactionDeleted`,`Transaction deleted`))},onError:t=>{d(t.message||e(`finance.deleteTransactionFailed`,`Failed to delete transaction`),`error`)}}),Rt=a({mutationFn:e=>r.editTransaction(e.transactionId,e.data),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.transactionEdited`,`Transaction updated and ledger recalculated`)),tt(!1)},onError:t=>{d(t.message||e(`finance.editTransactionFailed`,`Failed to edit transaction`),`error`)}}),zt=a({mutationFn:e=>r.createManualPrint(e),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.manualPrintCreated`,`Manual print charge added and ledger recalculated`)),H(!1),mt(null),gt(null),vt(``),bt(``),St(_e(new Date))},onError:t=>{d(t.message||e(`finance.manualPrintFailed`,`Failed to create manual print`),`error`)}}),Bt=a({mutationFn:e=>r.depositUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),Vt=a({mutationFn:e=>r.withdrawUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),Ht=a({mutationFn:e=>r.upsertCostCenterMember(e.costCenterId,{user_id:e.userId,can_print:e.canPrint}),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.memberSaved`,`Member saved`))},onError:t=>{d(t.message||e(`finance.memberSaveFailed`,`Failed to save member`),`error`)}}),Ut=a({mutationFn:e=>r.removeCostCenterMember(e.costCenterId,e.userId),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.memberRemoved`,`Member removed`))},onError:t=>{d(t.message||e(`finance.memberRemoveFailed`,`Failed to remove member`),`error`)}}),Wt=Bt.isPending||Vt.isPending,Gt=()=>{if(!xe.trim()){d(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}Nt.mutate()},Kt=async()=>{if(z==null){d(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}let t=Xe.trim();if(!t){d(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}try{w&&await Ft.mutateAsync({costCenterId:z,name:t}),T&&await Pt.mutateAsync({costCenterId:z,mode:Qe,value:$e}),m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.costCenterUpdated`,`Cost center updated`)),qe(!1)}catch(t){d(t.message||e(`finance.costCenterUpdateFailed`,`Failed to update cost center`),`error`)}},qt=e=>{let t=(G||[]).find(t=>t.id===e);t&&(Ye(t.id),Ze(t.name),t.budget_mode===`total`?(B(`total`),V(t.total_budget==null?``:String(t.total_budget))):(B(`monthly`),V(t.monthly_budget==null?``:String(t.monthly_budget))),qe(!0))},Jt=async()=>{if(U)try{await It.mutateAsync(U.id),m.invalidateQueries({queryKey:[`finance`]}),j===U.id&&M(null),d(e(`finance.costCenterDeleted`,`Cost center deleted`))}catch(t){d(t.message||e(`finance.costCenterDeleteFailed`,`Failed to delete cost center`),`error`)}finally{Ct(null)}},Yt=()=>{wt!=null&&Lt.mutate(wt,{onSettled:()=>Tt(null)})},Xt=e=>{rt(e.id),at(e.user_id),st(e.cost_center_id),lt(String(e.amount)),dt(e.description||``),tt(!0)},Zt=async()=>{if(nt==null)return;let t=ct?Number.parseFloat(ct):null;if(t!==null&&!Number.isFinite(t)){d(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}Rt.mutate({transactionId:nt,data:{user_id:it||void 0,cost_center_id:ot||void 0,amount:t??void 0,description:ut||void 0}})},Qt=async()=>{if(pt==null){d(e(`finance.userRequired`,`Please select a user`),`error`);return}if(ht==null){d(e(`finance.costCenterRequired`,`Please select a cost center`),`error`);return}let t=_t?Number.parseFloat(_t):null;if(t===null||!Number.isFinite(t)){d(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}t=Math.abs(t),zt.mutate({user_id:pt,cost_center_id:ht,amount:t,description:yt||void 0,created_at:xt?new Date(xt).toISOString():void 0})},$t=async()=>{if(A==null){d(e(`finance.userRequired`,`Please select a user`),`error`);return}let t=Number.parseFloat(ke);if(!Number.isFinite(t)||t<=0){d(e(`finance.amountMustBePositive`,`Amount must be greater than zero`),`error`);return}let n={userId:A,amount:t,description:je.trim()||void 0,costCenterId:Ne};try{De===`deposit`?await Bt.mutateAsync(n):await Vt.mutateAsync(n),m.invalidateQueries({queryKey:[`finance`]}),Ae(``),Me(``),d(De===`deposit`?e(`finance.depositSuccess`,`Deposit successful`):e(`finance.withdrawSuccess`,`Withdrawal successful`))}catch(t){d(t.message||e(`finance.adjustmentFailed`,`Wallet adjustment failed`),`error`)}},en=()=>{if(j==null){d(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}if(Fe==null){d(e(`finance.noEligibleUsers`,`No eligible users available`),`error`);return}Ht.mutate({costCenterId:j,userId:Fe,canPrint:Le})},tn=e=>{j!=null&&Ut.mutate({costCenterId:j,userId:e})},Y=le(Ot?.currency||`USD`),X=(0,f.useMemo)(()=>[...q||[]].sort((e,t)=>e.username.localeCompare(t.username)),[q]),nn=(0,f.useMemo)(()=>{let e=new Map;for(let t of X)e.set(t.id,t.username);return e},[X]),rn=(0,f.useMemo)(()=>{let e=new Set((J?.members||[]).map(e=>e.user_id));return X.filter(t=>!e.has(t.id))},[X,J]),an=R===`admin`&&S?jt:kt,Z=R===`admin`&&S?Mt:At,Q=(0,f.useMemo)(()=>an?.items??[],[an?.items]),on=an?.total??0,sn=Math.max(1,Math.ceil(on/50)),cn=(0,f.useMemo)(()=>Q.filter(e=>!(F!==`all`&&e.transaction_type!==F||I!==`all`&&e.cost_center_id!==I)),[Q,F,I]),ln=Math.floor(N/50)+1,$=R===`admin`,un=t=>t===`deposit`?e(`finance.deposit`):t===`withdraw`?e(`finance.withdraw`):t===`print_charge`?e(`finance.printCharge`):t,dn=t=>t==null?e(`finance.personal`,`Personal`):nn.get(t)||(o?.id===t&&o.username?o.username:e(`finance.userWithId`,`User #{{id}}`,{id:t})),fn=t=>t.budget_limit==null||t.budget_available==null?e(`finance.unlimited`,`Unlimited`):`${Y}${t.budget_available.toFixed(2)}/${Y}${t.budget_limit.toFixed(2)}`;return ye?(0,p.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,p.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(me,{className:`h-6 w-6 text-bambu-green`}),(0,p.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,p.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)}),(0,p.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 max-w-2xl`,children:e(`finance.budgetPolicyHint`,`Account balances track costs. Printing is limited only by the selected cost center budget; without a budget, printing is unlimited.`)})]}),(0,p.jsxs)(`div`,{className:`flex flex-col gap-2 lg:items-end`,children:[W&&(0,p.jsxs)(`div`,{className:`inline-flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>Je(`personal`),className:`px-3 py-1.5 text-sm ${R===`personal`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.personalView`,`Personal view`)}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>Je(`admin`),className:`px-3 py-1.5 text-sm ${R===`admin`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.adminView`,`Admin view`)})]}),R===`admin`&&W&&(0,p.jsxs)(`div`,{className:`flex flex-wrap gap-2 lg:justify-end`,children:[C&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>He(!0),children:e(`finance.createCostCenter`,`Create cost center`)}),D&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>We(!0),children:e(`finance.adjustWallet`,`Adjust wallet`)}),D&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>H(!0),children:e(`finance.addManualPrint`,`Add manual print`)}),E&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>Ke(!0),children:e(`finance.manageMembers`,`Manage cost center members`)})]})]})]}),(0,p.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2 xl:grid-cols-3`,children:[(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.currentBalance`,`Personal account balance`)}),(0,p.jsx)(me,{className:`w-4 h-4 text-bambu-green/90`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Dt?e(`common.loading`,`Loading...`):`${Y}${(Et?.balance??0).toFixed(2)}`})})]}),(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:R===`admin`?e(`finance.transactions`,`Transactions`):e(`finance.personalTransactions`,`Personal transactions`)}),(0,p.jsx)(pe,{className:`w-4 h-4 text-blue-400`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Z?`-`:on})})]}),(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsx)(fe,{className:`w-4 h-4 text-orange-400`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:K?`-`:G?.length??0})})]})]}),Ve&&C&&(0,p.jsx)(b,{title:e(`finance.createCostCenter`,`Create cost center`),size:`md`,onClose:()=>He(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenterName`,`Name`)}),(0,p.jsx)(`input`,{type:`text`,value:xe,onChange:e=>Se(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.budgetType`,`Budget type`)}),(0,p.jsxs)(`select`,{value:k,onChange:e=>Ce(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,p.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:k===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,value:we,onChange:e=>Te(e.target.value),placeholder:`0.00`,className:g})]})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:Gt,disabled:Nt.isPending,children:Nt.isPending?e(`common.saving`,`Saving...`):e(`finance.create`,`Create`)})]})}),Ue&&D&&O&&(0,p.jsx)(b,{title:e(`finance.adjustWallet`,`Adjust wallet`),size:`md`,onClose:()=>We(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.selectUser`,`Select user`)}),(0,p.jsx)(`select`,{value:A??``,onChange:e=>Ee(e.target.value?Number(e.target.value):null),className:g,children:(X||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.transactionType`,`Type`)}),(0,p.jsxs)(`select`,{value:De,onChange:e=>Oe(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`,`Deposit`)}),(0,p.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`,`Withdraw`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:ke,onChange:e=>Ae(e.target.value),placeholder:`0.00`,className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsxs)(`select`,{value:Ne??``,onChange:e=>Pe(e.target.value?Number(e.target.value):null),className:g,children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`No cost center`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`input`,{type:`text`,value:je,onChange:e=>Me(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:g})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:$t,disabled:Wt,children:Wt?e(`common.saving`,`Saving...`):e(`finance.applyAdjustment`,`Apply adjustment`)})]})}),Ge&&E&&O&&(0,p.jsx)(b,{title:e(`finance.manageMembers`,`Manage cost center members`),size:`lg`,onClose:()=>Ke(!1),children:(0,p.jsxs)(`div`,{className:`space-y-5`,children:[(0,p.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsx)(`select`,{value:j??``,onChange:e=>M(e.target.value?Number(e.target.value):null),className:g,children:(G||[]).filter(e=>!e.is_private).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.selectUser`,`Select user`)}),(0,p.jsxs)(`select`,{value:Fe??``,onChange:e=>Ie(e.target.value?Number(e.target.value):null),className:g,children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user`)}),rn.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary px-3 py-2`,children:[(0,p.jsx)(`input`,{id:`memberCanPrint`,type:`checkbox`,checked:Le,onChange:e=>Re(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,p.jsx)(`label`,{htmlFor:`memberCanPrint`,className:`text-sm text-bambu-gray`,children:e(`finance.memberCanPrint`,`Member can print`)})]}),(0,p.jsx)(`div`,{className:`flex items-end`,children:(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:en,disabled:Ht.isPending||Fe==null,children:Ht.isPending?e(`common.saving`,`Saving...`):e(`finance.addMember`,`Add member`)})})]}),(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.name`,`Name`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.canPrint`,`Can print`)}),(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsxs)(`tbody`,{children:[(J?.members||[]).map(t=>(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:X.find(e=>e.id===t.user_id)?.username||`User ${t.user_id}`}),(0,p.jsx)(`td`,{className:y,children:t.can_print?e(`common.yes`,`Yes`):e(`common.no`,`No`)}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsx)(u,{size:`sm`,variant:`danger`,onClick:()=>tn(t.user_id),disabled:Ut.isPending,children:e(`common.remove`,`Remove`)})})]},t.id)),(J?.members||[]).length===0&&(0,p.jsx)(`tr`,{children:(0,p.jsx)(`td`,{colSpan:3,className:`py-3 text-bambu-gray`,children:e(`finance.noMembers`,`No members assigned.`)})})]})]})})]})}),L&&(w||T)&&(0,p.jsx)(b,{title:e(`finance.editCostCenter`,`Edit cost center`),size:`md`,onClose:()=>qe(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenterName`,`Name`)}),(0,p.jsx)(`input`,{type:`text`,value:Xe,onChange:e=>Ze(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:g,disabled:!w})]}),(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.budgetType`,`Budget type`)}),(0,p.jsxs)(`select`,{value:Qe,onChange:e=>B(e.target.value),className:g,disabled:!T,children:[(0,p.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,p.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:Qe===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,value:$e,onChange:e=>V(e.target.value),placeholder:`0.00`,className:g,disabled:!T})]})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:Kt,disabled:Ft.isPending||Pt.isPending||z==null,children:Ft.isPending||Pt.isPending?e(`common.saving`,`Saving...`):e(`common.save`,`Save`)})]})}),(0,p.jsxs)(`div`,{className:`grid gap-6 ${be&&x?`xl:grid-cols-2`:``}`,children:[be&&(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{children:[(0,p.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.myCostCenters`,`My cost centers`)}),(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.costCentersHint`,`Review budget limits and keep costs under control`)})]}),(0,p.jsxs)(c,{className:`space-y-3`,children:[K&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!K&&(!G||G.length===0)&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noCostCenters`,`No cost centers found.`)}),!K&&G&&G.length>0&&(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.name`,`Name`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`finance.owner`,`Owner`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.balance`,`Account balance`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.budget`,`Budget`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsx)(`tbody`,{children:G.map(t=>{let n=w||T,r=!t.is_private&&w;return(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:t.name}),$&&(0,p.jsx)(`td`,{className:y,children:t.is_private?dn(t.owner_user_id):e(`finance.shared`,`Shared`)}),(0,p.jsxs)(`td`,{className:y,children:[Y,t.total_balance.toFixed(2)]}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,p.jsx)(`span`,{children:fn(t)}),(0,p.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t.budget_mode===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):t.budget_mode===`total`?e(`finance.totalBudget`,`Total budget`):e(`finance.noBudget`,`No budget`)})]})}),$&&(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(u,{size:`sm`,variant:`ghost`,onClick:()=>qt(t.id),disabled:!n,title:n?e(`common.edit`,`Edit`):e(`finance.cannotEditPrivateCostCenter`,`Private cost centers cannot be edited here`),className:`p-1.5 sm:p-2`,children:(0,p.jsx)(ae,{className:`w-4 h-4`})}),r&&(0,p.jsx)(u,{size:`sm`,variant:`ghost`,onClick:()=>Ct({id:t.id,name:t.name}),disabled:It.isPending,title:e(`common.delete`,`Delete`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,p.jsx)(oe,{className:`w-4 h-4`})})]})})]},t.id)})})]})})]})]}),x&&(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{children:[(0,p.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.recentTransactions`,`Recent transactions`)}),(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.transactionsHint`,`Filter by type and cost center, then navigate pages`)})]}),(0,p.jsxs)(c,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-end`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.transactionType`,`Type`)}),(0,p.jsxs)(`select`,{value:F,onChange:e=>ze(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`all`,children:e(`finance.allTypes`)}),(0,p.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`)}),(0,p.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`)}),(0,p.jsx)(`option`,{value:`print_charge`,children:e(`finance.printCharge`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsxs)(`select`,{value:I,onChange:e=>Be(e.target.value===`all`?`all`:Number(e.target.value)),className:g,children:[(0,p.jsx)(`option`,{value:`all`,children:e(`finance.allCostCenters`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),Z&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!Z&&(!Q||Q.length===0)&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactions`,`No transactions available.`)}),!Z&&Q.length>0&&cn.length===0&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactionsForFilter`,`No transactions match the selected filters.`)}),!Z&&cn.length>0&&(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.date`,`Date`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.user`,`User`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.costCenter`,`Cost center`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.transactionType`,`Type`)}),(0,p.jsx)(`th`,{className:v,children:e(`common.description`,`Description`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.balanceAfter`,`Balance after`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsx)(`tbody`,{children:cn.map(n=>{let r=n.amount>=0,ee=n.cost_center_id==null?null:(G||[]).find(e=>e.id===n.cost_center_id),te=nn.get(n.user_id),i=n.transaction_type===`print_charge`?he(n.description??null):null,a=i?.isPartial??!1;return(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:ge(n.created_at,t.language)}),$&&(0,p.jsx)(`td`,{className:y,children:te||e(`finance.userWithId`,`User #{{id}}`,{id:n.user_id})}),(0,p.jsx)(`td`,{className:y,children:ee?.name||`-`}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,p.jsx)(`span`,{children:un(n.transaction_type)}),a&&(0,p.jsx)(`span`,{className:`rounded border border-yellow-500/40 bg-yellow-500/10 px-2 py-0.5 text-[11px] text-yellow-300`,children:i&&i.partialType?e(`finance.partialStatus.${i.partialType}`,i.partialType):e(`finance.partial`,`Partial`)})]})}),(0,p.jsx)(`td`,{className:y,children:(i?.cleanedDescription??n.description)||`-`}),(0,p.jsxs)(`td`,{className:`${y} ${r?`text-green-400`:`text-red-400`}`,children:[r?`+`:`-`,Y,Math.abs(n.amount).toFixed(2)]}),(0,p.jsx)(`td`,{className:y,children:n.balance_after==null?`-`:`${n.balance_after<0?`-`:``}${Y}${Math.abs(n.balance_after).toFixed(2)}`}),$&&(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>Xt(n),disabled:Rt.isPending,children:(0,p.jsx)(ae,{className:`w-4 h-4`})}),(0,p.jsx)(u,{size:`sm`,variant:`danger`,onClick:()=>Tt(n.id),disabled:Lt.isPending,children:(0,p.jsx)(oe,{className:`w-4 h-4`})})]})})]},n.id)})})]})}),!Z&&cn.length>0&&(0,p.jsx)(`div`,{className:`flex justify-end pt-2 lg:pt-0`,children:(0,p.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(0),disabled:N===0||Z,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.first`,`First`),children:(0,p.jsx)(ne,{className:`w-4 h-4`})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(e=>Math.max(0,e-50)),disabled:N===0||Z,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.prev`,`Previous`),children:(0,p.jsx)(ue,{className:`w-4 h-4`})}),(0,p.jsx)(`span`,{className:`text-bambu-gray px-1 whitespace-nowrap`,children:e(`finance.pageNumberOf`,`Page {{page}} of {{total}}`,{page:ln,total:sn})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(e=>e+50),disabled:Z||ln>=sn,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.next`,`Next`),children:(0,p.jsx)(se,{className:`w-4 h-4`})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(Math.max(0,(sn-1)*50)),disabled:Z||ln>=sn,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.last`,`Last`),children:(0,p.jsx)(re,{className:`w-4 h-4`})})]})})]})]}),et&&nt!==null&&(0,p.jsx)(b,{title:e(`finance.editTransaction`,`Edit Transaction`),onClose:()=>tt(!1),size:`md`,children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.user`,`User`)}),(0,p.jsxs)(`select`,{className:g,value:it||``,onChange:e=>at(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),X.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenter`,`Cost center (optional)`)}),(0,p.jsxs)(`select`,{className:g,value:ot||``,onChange:e=>st(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`Personal (no cost center)`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,className:g,value:ct,onChange:e=>lt(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 10.50`)})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`textarea`,{className:`${g} resize-none`,rows:3,value:ut,onChange:e=>dt(e.target.value),placeholder:e(`finance.manualAdjustmentExample`,`e.g., Manual adjustment`)})]}),(0,p.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,p.jsx)(u,{variant:`secondary`,onClick:()=>tt(!1),children:e(`common.cancel`,`Cancel`)}),(0,p.jsx)(u,{onClick:Zt,disabled:Rt.isPending,children:e(`common.save`,`Save`)})]})]})}),ft&&(0,p.jsx)(b,{title:e(`finance.addManualPrint`,`Add manual print`),onClose:()=>H(!1),size:`md`,children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.user`,`User`)}),(0,p.jsxs)(`select`,{className:g,value:pt||``,onChange:e=>mt(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),X.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenter`,`Cost center`)}),(0,p.jsxs)(`select`,{className:g,value:ht||``,onChange:e=>gt(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectCostCenter`,`Select cost center...`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,className:g,value:_t,onChange:e=>vt(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 4.00`)})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`input`,{type:`text`,value:yt,onChange:e=>bt(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.date`,`Date`)}),(0,p.jsx)(`input`,{type:`datetime-local`,value:xt,onChange:e=>St(e.target.value),className:g})]}),(0,p.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,p.jsx)(u,{variant:`secondary`,onClick:()=>H(!1),children:e(`common.cancel`,`Cancel`)}),(0,p.jsx)(u,{onClick:Qt,disabled:zt.isPending,children:zt.isPending?e(`common.saving`,`Saving...`):e(`finance.addManualPrint`,`Add manual print`)})]})]})}),U&&(0,p.jsx)(ce,{title:e(`common.delete`,`Delete`),message:e(`finance.confirmDeleteCostCenter`,`Delete cost center "{{name}}"?`,{name:U.name}),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:It.isPending,onConfirm:Jt,onCancel:()=>Ct(null)}),wt!=null&&(0,p.jsx)(ce,{title:e(`finance.deleteTransaction`,`Delete transaction`),message:e(`finance.deleteTransactionConfirm`,`Delete this transaction? Balances will be recalculated automatically.`),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:Lt.isPending,onConfirm:Yt,onCancel:()=>Tt(null)})]})]}):(0,p.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(me,{className:`h-6 w-6 text-bambu-green`}),(0,p.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,p.jsx)(`div`,{children:(0,p.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)})}),(0,p.jsx)(l,{children:(0,p.jsx)(c,{className:`py-8 text-center text-bambu-gray`,children:e(`finance.noAccess`,`You do not have permission to view finance data.`)})})]})}export{x as FinancePage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as ee}from"./client-BdOyoZJz.js";import{n as te}from"./QueryClientProvider-Clbyr4Jg.js";import{t as i}from"./useQuery-CCy0EwsM.js";import{t as a}from"./useMutation-qh3Iyscy.js";import{t as o}from"./createLucideIcon-Yo2YoYjm.js";import{n as ne,t as re}from"./chevrons-right-OnQ-9jKz.js";import{n as ie}from"./ToastContext-VFOrCCoA.js";import{i as s,n as c,t as l}from"./Card-OUAj0Ayh.js";import{t as u}from"./Button-pwVKPiYn.js";import{v as d}from"./date-G9KUauqz.js";import{$t as ae,At as oe,Mn as se,_t as ce,at as le,jn as ue,yt as de}from"./index-ggB_TpPo.js";var fe=o(`building-2`,[[`path`,{d:`M10 12h4`,key:`a56b0p`}],[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M14 21v-3a2 2 0 0 0-4 0v3`,key:`1rgiei`}],[`path`,{d:`M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2`,key:`secmi2`}],[`path`,{d:`M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16`,key:`16ra0t`}]]),pe=o(`clock-3`,[[`path`,{d:`M12 6v6h4`,key:`135r8i`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),me=o(`wallet`,[[`path`,{d:`M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1`,key:`18etb6`}],[`path`,{d:`M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4`,key:`xoc0q4`}]]),f=e(n(),1),p=t(),m=/\[(aborted|failed|cancelled):\s*([^\]]*)\]/i;function he(e){if(!e)return{isPartial:!1,partialType:null,cleanedDescription:null};let t=e.match(m);if(!t)return{isPartial:!1,partialType:null,cleanedDescription:e};let n=e.replace(t[0],``).trim();return{isPartial:!0,partialType:t[1].toLowerCase(),cleanedDescription:n||null}}function ge(e,t){if(!e)return`-`;let n=d(e);return n?n.toLocaleString(t):e}function h(e){let t=e.trim();if(!t)return null;let n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function _e(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}T${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}var g=`w-full px-3 py-2 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:outline-none focus:ring-1 focus:ring-bambu-green`,_=`block text-sm font-medium text-white mb-1`,v=`px-4 py-3 text-left text-bambu-gray font-medium`,y=`px-4 py-3 align-top text-white`;function b({title:e,onClose:t,children:n,size:r=`md`}){let{t:te}=ee();return(0,p.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,p.jsxs)(`div`,{className:`w-full ${r===`sm`?`max-w-xl`:r===`lg`?`max-w-6xl`:`max-w-4xl`} overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,p.jsxs)(`div`,{className:`flex items-center justify-between border-b border-bambu-dark-tertiary px-4 py-3`,children:[(0,p.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e}),(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:t,children:te(`common.close`,`Close`)})]}),(0,p.jsx)(`div`,{className:`max-h-[75vh] overflow-auto p-4`,children:n})]})})}function x(){let{t:e,i18n:t}=ee(),{hasPermission:n,user:o}=de(),{showToast:d}=ie(),m=te(),x=n(`cost_centers:read_own`),S=n(`cost_centers:read_all`),C=n(`cost_centers:create`),w=n(`cost_centers:modify`),T=n(`cost_centers:modify`),E=n(`cost_centers:modify`),D=n(`cost_centers:modify`),O=n(`users:read_slim`)||n(`users:read`),ve=S||C||w||T||E||D,ye=x||ve,be=ye,[xe,Se]=(0,f.useState)(``),[k,Ce]=(0,f.useState)(`monthly`),[we,Te]=(0,f.useState)(``),[A,Ee]=(0,f.useState)(null),[De,Oe]=(0,f.useState)(`deposit`),[ke,Ae]=(0,f.useState)(``),[je,Me]=(0,f.useState)(``),[Ne,Pe]=(0,f.useState)(null),[j,M]=(0,f.useState)(null),[Fe,Ie]=(0,f.useState)(null),[Le,Re]=(0,f.useState)(!0),[N,P]=(0,f.useState)(0),[F,ze]=(0,f.useState)(`all`),[I,Be]=(0,f.useState)(`all`),[Ve,He]=(0,f.useState)(!1),[Ue,We]=(0,f.useState)(!1),[Ge,Ke]=(0,f.useState)(!1),[L,qe]=(0,f.useState)(!1),[R,Je]=(0,f.useState)(`personal`),[z,Ye]=(0,f.useState)(null),[Xe,Ze]=(0,f.useState)(``),[Qe,B]=(0,f.useState)(`monthly`),[$e,V]=(0,f.useState)(``),[et,tt]=(0,f.useState)(!1),[nt,rt]=(0,f.useState)(null),[it,at]=(0,f.useState)(null),[ot,st]=(0,f.useState)(null),[ct,lt]=(0,f.useState)(``),[ut,dt]=(0,f.useState)(``),[ft,H]=(0,f.useState)(!1),[pt,mt]=(0,f.useState)(null),[ht,gt]=(0,f.useState)(null),[_t,vt]=(0,f.useState)(``),[yt,bt]=(0,f.useState)(``),[xt,St]=(0,f.useState)(_e(new Date)),[U,Ct]=(0,f.useState)(null),[wt,Tt]=(0,f.useState)(null),W=S||C||w||T||D&&O||E&&O;(0,f.useEffect)(()=>{W||Je(`personal`)},[W]);let{data:Et,isLoading:Dt}=i({queryKey:[`finance`,`me`,`balance`],queryFn:r.getMyBalance,enabled:x}),{data:Ot}=i({queryKey:[`ui-flags`],queryFn:r.getUiFlags}),{data:kt,isLoading:At}=i({queryKey:[`finance`,`me`,`transactions`,50,N],queryFn:()=>r.getMyTransactions(50,N),enabled:x}),{data:jt,isLoading:Mt}=i({queryKey:[`finance`,`transactions`,50,N],queryFn:()=>r.getAllTransactions(50,N),enabled:R===`admin`&&S}),{data:G,isLoading:K}=i({queryKey:[`finance`,`cost-centers`,R],queryFn:()=>R===`admin`&&ve?r.listCostCenters(!0):r.getMyCostCenters(),enabled:be}),{data:q}=i({queryKey:[`users`,`slim`],queryFn:r.getUsersSlim,enabled:O&&(be||D||E)}),{data:J}=i({queryKey:[`finance`,`cost-center`,j],queryFn:()=>r.getCostCenter(j),enabled:E&&j!=null});(0,f.useEffect)(()=>{!q||q.length===0||A!=null&&q.some(e=>e.id===A)||Ee(q[0].id)},[q,A]),(0,f.useEffect)(()=>{if(!E)return;let e=(G||[]).filter(e=>!e.is_private);if(e.length===0){M(null);return}j!=null&&e.some(e=>e.id===j)||M(e[0].id)},[E,G,j]),(0,f.useEffect)(()=>{if(!E||!q||q.length===0)return;let e=new Set((J?.members||[]).map(e=>e.user_id)),t=q.find(t=>!e.has(t.id));Ie(t?t.id:null)},[E,q,J]),(0,f.useEffect)(()=>{if(!L)return;let e=G||[];if(e.length===0){Ye(null);return}z!=null&&e.some(e=>e.id===z)||Ye(e[0].id)},[L,z,G]),(0,f.useEffect)(()=>{if(!L||z==null)return;let e=(G||[]).find(e=>e.id===z);if(e){if(Ze(e.name),e.budget_mode===`total`){B(`total`),V(e.total_budget==null?``:String(e.total_budget));return}B(`monthly`),V(e.monthly_budget==null?``:String(e.monthly_budget))}},[L,z,G]);let Nt=a({mutationFn:()=>r.createCostCenter({name:xe.trim(),total_budget:k===`total`?h(we):null,monthly_budget:k===`monthly`?h(we):null,is_active:!0}),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),Se(``),Te(``),d(e(`finance.createdCostCenter`,`Cost center created`))},onError:t=>{d(t.message||e(`finance.createCostCenterFailed`,`Failed to create cost center`),`error`)}}),Pt=a({mutationFn:({costCenterId:e,value:t,mode:n})=>r.updateCostCenterBudgets(e,{total_budget:n===`total`?h(t):null,monthly_budget:n===`monthly`?h(t):null})}),Ft=a({mutationFn:({costCenterId:e,name:t})=>r.updateCostCenter(e,{name:t})}),It=a({mutationFn:e=>r.deleteCostCenter(e)}),Lt=a({mutationFn:e=>r.deleteTransaction(e),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.transactionDeleted`,`Transaction deleted`))},onError:t=>{d(t.message||e(`finance.deleteTransactionFailed`,`Failed to delete transaction`),`error`)}}),Rt=a({mutationFn:e=>r.editTransaction(e.transactionId,e.data),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.transactionEdited`,`Transaction updated and ledger recalculated`)),tt(!1)},onError:t=>{d(t.message||e(`finance.editTransactionFailed`,`Failed to edit transaction`),`error`)}}),zt=a({mutationFn:e=>r.createManualPrint(e),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.manualPrintCreated`,`Manual print charge added and ledger recalculated`)),H(!1),mt(null),gt(null),vt(``),bt(``),St(_e(new Date))},onError:t=>{d(t.message||e(`finance.manualPrintFailed`,`Failed to create manual print`),`error`)}}),Bt=a({mutationFn:e=>r.depositUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),Vt=a({mutationFn:e=>r.withdrawUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),Ht=a({mutationFn:e=>r.upsertCostCenterMember(e.costCenterId,{user_id:e.userId,can_print:e.canPrint}),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.memberSaved`,`Member saved`))},onError:t=>{d(t.message||e(`finance.memberSaveFailed`,`Failed to save member`),`error`)}}),Ut=a({mutationFn:e=>r.removeCostCenterMember(e.costCenterId,e.userId),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.memberRemoved`,`Member removed`))},onError:t=>{d(t.message||e(`finance.memberRemoveFailed`,`Failed to remove member`),`error`)}}),Wt=Bt.isPending||Vt.isPending,Gt=()=>{if(!xe.trim()){d(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}Nt.mutate()},Kt=async()=>{if(z==null){d(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}let t=Xe.trim();if(!t){d(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}try{w&&await Ft.mutateAsync({costCenterId:z,name:t}),T&&await Pt.mutateAsync({costCenterId:z,mode:Qe,value:$e}),m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.costCenterUpdated`,`Cost center updated`)),qe(!1)}catch(t){d(t.message||e(`finance.costCenterUpdateFailed`,`Failed to update cost center`),`error`)}},qt=e=>{let t=(G||[]).find(t=>t.id===e);t&&(Ye(t.id),Ze(t.name),t.budget_mode===`total`?(B(`total`),V(t.total_budget==null?``:String(t.total_budget))):(B(`monthly`),V(t.monthly_budget==null?``:String(t.monthly_budget))),qe(!0))},Jt=async()=>{if(U)try{await It.mutateAsync(U.id),m.invalidateQueries({queryKey:[`finance`]}),j===U.id&&M(null),d(e(`finance.costCenterDeleted`,`Cost center deleted`))}catch(t){d(t.message||e(`finance.costCenterDeleteFailed`,`Failed to delete cost center`),`error`)}finally{Ct(null)}},Yt=()=>{wt!=null&&Lt.mutate(wt,{onSettled:()=>Tt(null)})},Xt=e=>{rt(e.id),at(e.user_id),st(e.cost_center_id),lt(String(e.amount)),dt(e.description||``),tt(!0)},Zt=async()=>{if(nt==null)return;let t=ct?Number.parseFloat(ct):null;if(t!==null&&!Number.isFinite(t)){d(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}Rt.mutate({transactionId:nt,data:{user_id:it||void 0,cost_center_id:ot||void 0,amount:t??void 0,description:ut||void 0}})},Qt=async()=>{if(pt==null){d(e(`finance.userRequired`,`Please select a user`),`error`);return}if(ht==null){d(e(`finance.costCenterRequired`,`Please select a cost center`),`error`);return}let t=_t?Number.parseFloat(_t):null;if(t===null||!Number.isFinite(t)){d(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}t=Math.abs(t),zt.mutate({user_id:pt,cost_center_id:ht,amount:t,description:yt||void 0,created_at:xt?new Date(xt).toISOString():void 0})},$t=async()=>{if(A==null){d(e(`finance.userRequired`,`Please select a user`),`error`);return}let t=Number.parseFloat(ke);if(!Number.isFinite(t)||t<=0){d(e(`finance.amountMustBePositive`,`Amount must be greater than zero`),`error`);return}let n={userId:A,amount:t,description:je.trim()||void 0,costCenterId:Ne};try{De===`deposit`?await Bt.mutateAsync(n):await Vt.mutateAsync(n),m.invalidateQueries({queryKey:[`finance`]}),Ae(``),Me(``),d(De===`deposit`?e(`finance.depositSuccess`,`Deposit successful`):e(`finance.withdrawSuccess`,`Withdrawal successful`))}catch(t){d(t.message||e(`finance.adjustmentFailed`,`Wallet adjustment failed`),`error`)}},en=()=>{if(j==null){d(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}if(Fe==null){d(e(`finance.noEligibleUsers`,`No eligible users available`),`error`);return}Ht.mutate({costCenterId:j,userId:Fe,canPrint:Le})},tn=e=>{j!=null&&Ut.mutate({costCenterId:j,userId:e})},Y=le(Ot?.currency||`USD`),X=(0,f.useMemo)(()=>[...q||[]].sort((e,t)=>e.username.localeCompare(t.username)),[q]),nn=(0,f.useMemo)(()=>{let e=new Map;for(let t of X)e.set(t.id,t.username);return e},[X]),rn=(0,f.useMemo)(()=>{let e=new Set((J?.members||[]).map(e=>e.user_id));return X.filter(t=>!e.has(t.id))},[X,J]),an=R===`admin`&&S?jt:kt,Z=R===`admin`&&S?Mt:At,Q=(0,f.useMemo)(()=>an?.items??[],[an?.items]),on=an?.total??0,sn=Math.max(1,Math.ceil(on/50)),cn=(0,f.useMemo)(()=>Q.filter(e=>!(F!==`all`&&e.transaction_type!==F||I!==`all`&&e.cost_center_id!==I)),[Q,F,I]),ln=Math.floor(N/50)+1,$=R===`admin`,un=t=>t===`deposit`?e(`finance.deposit`):t===`withdraw`?e(`finance.withdraw`):t===`print_charge`?e(`finance.printCharge`):t,dn=t=>t==null?e(`finance.personal`,`Personal`):nn.get(t)||(o?.id===t&&o.username?o.username:e(`finance.userWithId`,`User #{{id}}`,{id:t})),fn=t=>t.budget_limit==null||t.budget_available==null?e(`finance.unlimited`,`Unlimited`):`${Y}${t.budget_available.toFixed(2)}/${Y}${t.budget_limit.toFixed(2)}`;return ye?(0,p.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,p.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(me,{className:`h-6 w-6 text-bambu-green`}),(0,p.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,p.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)}),(0,p.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 max-w-2xl`,children:e(`finance.budgetPolicyHint`,`Account balances track costs. Printing is limited only by the selected cost center budget; without a budget, printing is unlimited.`)})]}),(0,p.jsxs)(`div`,{className:`flex flex-col gap-2 lg:items-end`,children:[W&&(0,p.jsxs)(`div`,{className:`inline-flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>Je(`personal`),className:`px-3 py-1.5 text-sm ${R===`personal`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.personalView`,`Personal view`)}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>Je(`admin`),className:`px-3 py-1.5 text-sm ${R===`admin`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.adminView`,`Admin view`)})]}),R===`admin`&&W&&(0,p.jsxs)(`div`,{className:`flex flex-wrap gap-2 lg:justify-end`,children:[C&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>He(!0),children:e(`finance.createCostCenter`,`Create cost center`)}),D&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>We(!0),children:e(`finance.adjustWallet`,`Adjust wallet`)}),D&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>H(!0),children:e(`finance.addManualPrint`,`Add manual print`)}),E&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>Ke(!0),children:e(`finance.manageMembers`,`Manage cost center members`)})]})]})]}),(0,p.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2 xl:grid-cols-3`,children:[(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.currentBalance`,`Personal account balance`)}),(0,p.jsx)(me,{className:`w-4 h-4 text-bambu-green/90`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Dt?e(`common.loading`,`Loading...`):`${Y}${(Et?.balance??0).toFixed(2)}`})})]}),(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:R===`admin`?e(`finance.transactions`,`Transactions`):e(`finance.personalTransactions`,`Personal transactions`)}),(0,p.jsx)(pe,{className:`w-4 h-4 text-blue-400`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Z?`-`:on})})]}),(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsx)(fe,{className:`w-4 h-4 text-orange-400`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:K?`-`:G?.length??0})})]})]}),Ve&&C&&(0,p.jsx)(b,{title:e(`finance.createCostCenter`,`Create cost center`),size:`md`,onClose:()=>He(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenterName`,`Name`)}),(0,p.jsx)(`input`,{type:`text`,value:xe,onChange:e=>Se(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.budgetType`,`Budget type`)}),(0,p.jsxs)(`select`,{value:k,onChange:e=>Ce(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,p.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:k===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,value:we,onChange:e=>Te(e.target.value),placeholder:`0.00`,className:g})]})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:Gt,disabled:Nt.isPending,children:Nt.isPending?e(`common.saving`,`Saving...`):e(`finance.create`,`Create`)})]})}),Ue&&D&&O&&(0,p.jsx)(b,{title:e(`finance.adjustWallet`,`Adjust wallet`),size:`md`,onClose:()=>We(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.selectUser`,`Select user`)}),(0,p.jsx)(`select`,{value:A??``,onChange:e=>Ee(e.target.value?Number(e.target.value):null),className:g,children:(X||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.transactionType`,`Type`)}),(0,p.jsxs)(`select`,{value:De,onChange:e=>Oe(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`,`Deposit`)}),(0,p.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`,`Withdraw`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:ke,onChange:e=>Ae(e.target.value),placeholder:`0.00`,className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsxs)(`select`,{value:Ne??``,onChange:e=>Pe(e.target.value?Number(e.target.value):null),className:g,children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`No cost center`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`input`,{type:`text`,value:je,onChange:e=>Me(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:g})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:$t,disabled:Wt,children:Wt?e(`common.saving`,`Saving...`):e(`finance.applyAdjustment`,`Apply adjustment`)})]})}),Ge&&E&&O&&(0,p.jsx)(b,{title:e(`finance.manageMembers`,`Manage cost center members`),size:`lg`,onClose:()=>Ke(!1),children:(0,p.jsxs)(`div`,{className:`space-y-5`,children:[(0,p.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsx)(`select`,{value:j??``,onChange:e=>M(e.target.value?Number(e.target.value):null),className:g,children:(G||[]).filter(e=>!e.is_private).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.selectUser`,`Select user`)}),(0,p.jsxs)(`select`,{value:Fe??``,onChange:e=>Ie(e.target.value?Number(e.target.value):null),className:g,children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user`)}),rn.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary px-3 py-2`,children:[(0,p.jsx)(`input`,{id:`memberCanPrint`,type:`checkbox`,checked:Le,onChange:e=>Re(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,p.jsx)(`label`,{htmlFor:`memberCanPrint`,className:`text-sm text-bambu-gray`,children:e(`finance.memberCanPrint`,`Member can print`)})]}),(0,p.jsx)(`div`,{className:`flex items-end`,children:(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:en,disabled:Ht.isPending||Fe==null,children:Ht.isPending?e(`common.saving`,`Saving...`):e(`finance.addMember`,`Add member`)})})]}),(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.name`,`Name`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.canPrint`,`Can print`)}),(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsxs)(`tbody`,{children:[(J?.members||[]).map(t=>(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:X.find(e=>e.id===t.user_id)?.username||`User ${t.user_id}`}),(0,p.jsx)(`td`,{className:y,children:t.can_print?e(`common.yes`,`Yes`):e(`common.no`,`No`)}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsx)(u,{size:`sm`,variant:`danger`,onClick:()=>tn(t.user_id),disabled:Ut.isPending,children:e(`common.remove`,`Remove`)})})]},t.id)),(J?.members||[]).length===0&&(0,p.jsx)(`tr`,{children:(0,p.jsx)(`td`,{colSpan:3,className:`py-3 text-bambu-gray`,children:e(`finance.noMembers`,`No members assigned.`)})})]})]})})]})}),L&&(w||T)&&(0,p.jsx)(b,{title:e(`finance.editCostCenter`,`Edit cost center`),size:`md`,onClose:()=>qe(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenterName`,`Name`)}),(0,p.jsx)(`input`,{type:`text`,value:Xe,onChange:e=>Ze(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:g,disabled:!w})]}),(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.budgetType`,`Budget type`)}),(0,p.jsxs)(`select`,{value:Qe,onChange:e=>B(e.target.value),className:g,disabled:!T,children:[(0,p.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,p.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:Qe===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,value:$e,onChange:e=>V(e.target.value),placeholder:`0.00`,className:g,disabled:!T})]})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:Kt,disabled:Ft.isPending||Pt.isPending||z==null,children:Ft.isPending||Pt.isPending?e(`common.saving`,`Saving...`):e(`common.save`,`Save`)})]})}),(0,p.jsxs)(`div`,{className:`grid gap-6 ${be&&x?`xl:grid-cols-2`:``}`,children:[be&&(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{children:[(0,p.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.myCostCenters`,`My cost centers`)}),(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.costCentersHint`,`Review budget limits and keep costs under control`)})]}),(0,p.jsxs)(c,{className:`space-y-3`,children:[K&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!K&&(!G||G.length===0)&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noCostCenters`,`No cost centers found.`)}),!K&&G&&G.length>0&&(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.name`,`Name`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`finance.owner`,`Owner`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.balance`,`Account balance`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.budget`,`Budget`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsx)(`tbody`,{children:G.map(t=>{let n=w||T,r=!t.is_private&&w;return(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:t.name}),$&&(0,p.jsx)(`td`,{className:y,children:t.is_private?dn(t.owner_user_id):e(`finance.shared`,`Shared`)}),(0,p.jsxs)(`td`,{className:y,children:[Y,t.total_balance.toFixed(2)]}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,p.jsx)(`span`,{children:fn(t)}),(0,p.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t.budget_mode===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):t.budget_mode===`total`?e(`finance.totalBudget`,`Total budget`):e(`finance.noBudget`,`No budget`)})]})}),$&&(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(u,{size:`sm`,variant:`ghost`,onClick:()=>qt(t.id),disabled:!n,title:n?e(`common.edit`,`Edit`):e(`finance.cannotEditPrivateCostCenter`,`Private cost centers cannot be edited here`),className:`p-1.5 sm:p-2`,children:(0,p.jsx)(ae,{className:`w-4 h-4`})}),r&&(0,p.jsx)(u,{size:`sm`,variant:`ghost`,onClick:()=>Ct({id:t.id,name:t.name}),disabled:It.isPending,title:e(`common.delete`,`Delete`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,p.jsx)(oe,{className:`w-4 h-4`})})]})})]},t.id)})})]})})]})]}),x&&(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{children:[(0,p.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.recentTransactions`,`Recent transactions`)}),(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.transactionsHint`,`Filter by type and cost center, then navigate pages`)})]}),(0,p.jsxs)(c,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-end`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.transactionType`,`Type`)}),(0,p.jsxs)(`select`,{value:F,onChange:e=>ze(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`all`,children:e(`finance.allTypes`)}),(0,p.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`)}),(0,p.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`)}),(0,p.jsx)(`option`,{value:`print_charge`,children:e(`finance.printCharge`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsxs)(`select`,{value:I,onChange:e=>Be(e.target.value===`all`?`all`:Number(e.target.value)),className:g,children:[(0,p.jsx)(`option`,{value:`all`,children:e(`finance.allCostCenters`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),Z&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!Z&&(!Q||Q.length===0)&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactions`,`No transactions available.`)}),!Z&&Q.length>0&&cn.length===0&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactionsForFilter`,`No transactions match the selected filters.`)}),!Z&&cn.length>0&&(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.date`,`Date`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.user`,`User`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.costCenter`,`Cost center`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.transactionType`,`Type`)}),(0,p.jsx)(`th`,{className:v,children:e(`common.description`,`Description`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.balanceAfter`,`Balance after`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsx)(`tbody`,{children:cn.map(n=>{let r=n.amount>=0,ee=n.cost_center_id==null?null:(G||[]).find(e=>e.id===n.cost_center_id),te=nn.get(n.user_id),i=n.transaction_type===`print_charge`?he(n.description??null):null,a=i?.isPartial??!1;return(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:ge(n.created_at,t.language)}),$&&(0,p.jsx)(`td`,{className:y,children:te||e(`finance.userWithId`,`User #{{id}}`,{id:n.user_id})}),(0,p.jsx)(`td`,{className:y,children:ee?.name||`-`}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,p.jsx)(`span`,{children:un(n.transaction_type)}),a&&(0,p.jsx)(`span`,{className:`rounded border border-yellow-500/40 bg-yellow-500/10 px-2 py-0.5 text-[11px] text-yellow-300`,children:i&&i.partialType?e(`finance.partialStatus.${i.partialType}`,i.partialType):e(`finance.partial`,`Partial`)})]})}),(0,p.jsx)(`td`,{className:y,children:(i?.cleanedDescription??n.description)||`-`}),(0,p.jsxs)(`td`,{className:`${y} ${r?`text-green-400`:`text-red-400`}`,children:[r?`+`:`-`,Y,Math.abs(n.amount).toFixed(2)]}),(0,p.jsx)(`td`,{className:y,children:n.balance_after==null?`-`:`${n.balance_after<0?`-`:``}${Y}${Math.abs(n.balance_after).toFixed(2)}`}),$&&(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>Xt(n),disabled:Rt.isPending,children:(0,p.jsx)(ae,{className:`w-4 h-4`})}),(0,p.jsx)(u,{size:`sm`,variant:`danger`,onClick:()=>Tt(n.id),disabled:Lt.isPending,children:(0,p.jsx)(oe,{className:`w-4 h-4`})})]})})]},n.id)})})]})}),!Z&&cn.length>0&&(0,p.jsx)(`div`,{className:`flex justify-end pt-2 lg:pt-0`,children:(0,p.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(0),disabled:N===0||Z,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.first`,`First`),children:(0,p.jsx)(ne,{className:`w-4 h-4`})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(e=>Math.max(0,e-50)),disabled:N===0||Z,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.prev`,`Previous`),children:(0,p.jsx)(ue,{className:`w-4 h-4`})}),(0,p.jsx)(`span`,{className:`text-bambu-gray px-1 whitespace-nowrap`,children:e(`finance.pageNumberOf`,`Page {{page}} of {{total}}`,{page:ln,total:sn})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(e=>e+50),disabled:Z||ln>=sn,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.next`,`Next`),children:(0,p.jsx)(se,{className:`w-4 h-4`})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(Math.max(0,(sn-1)*50)),disabled:Z||ln>=sn,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.last`,`Last`),children:(0,p.jsx)(re,{className:`w-4 h-4`})})]})})]})]}),et&&nt!==null&&(0,p.jsx)(b,{title:e(`finance.editTransaction`,`Edit Transaction`),onClose:()=>tt(!1),size:`md`,children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.user`,`User`)}),(0,p.jsxs)(`select`,{className:g,value:it||``,onChange:e=>at(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),X.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenter`,`Cost center (optional)`)}),(0,p.jsxs)(`select`,{className:g,value:ot||``,onChange:e=>st(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`Personal (no cost center)`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,className:g,value:ct,onChange:e=>lt(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 10.50`)})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`textarea`,{className:`${g} resize-none`,rows:3,value:ut,onChange:e=>dt(e.target.value),placeholder:e(`finance.manualAdjustmentExample`,`e.g., Manual adjustment`)})]}),(0,p.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,p.jsx)(u,{variant:`secondary`,onClick:()=>tt(!1),children:e(`common.cancel`,`Cancel`)}),(0,p.jsx)(u,{onClick:Zt,disabled:Rt.isPending,children:e(`common.save`,`Save`)})]})]})}),ft&&(0,p.jsx)(b,{title:e(`finance.addManualPrint`,`Add manual print`),onClose:()=>H(!1),size:`md`,children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.user`,`User`)}),(0,p.jsxs)(`select`,{className:g,value:pt||``,onChange:e=>mt(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),X.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenter`,`Cost center`)}),(0,p.jsxs)(`select`,{className:g,value:ht||``,onChange:e=>gt(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectCostCenter`,`Select cost center...`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,className:g,value:_t,onChange:e=>vt(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 4.00`)})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`input`,{type:`text`,value:yt,onChange:e=>bt(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.date`,`Date`)}),(0,p.jsx)(`input`,{type:`datetime-local`,value:xt,onChange:e=>St(e.target.value),className:g})]}),(0,p.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,p.jsx)(u,{variant:`secondary`,onClick:()=>H(!1),children:e(`common.cancel`,`Cancel`)}),(0,p.jsx)(u,{onClick:Qt,disabled:zt.isPending,children:zt.isPending?e(`common.saving`,`Saving...`):e(`finance.addManualPrint`,`Add manual print`)})]})]})}),U&&(0,p.jsx)(ce,{title:e(`common.delete`,`Delete`),message:e(`finance.confirmDeleteCostCenter`,`Delete cost center "{{name}}"?`,{name:U.name}),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:It.isPending,onConfirm:Jt,onCancel:()=>Ct(null)}),wt!=null&&(0,p.jsx)(ce,{title:e(`finance.deleteTransaction`,`Delete transaction`),message:e(`finance.deleteTransactionConfirm`,`Delete this transaction? Balances will be recalculated automatically.`),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:Lt.isPending,onConfirm:Yt,onCancel:()=>Tt(null)})]})]}):(0,p.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(me,{className:`h-6 w-6 text-bambu-green`}),(0,p.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,p.jsx)(`div`,{children:(0,p.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)})}),(0,p.jsx)(l,{children:(0,p.jsx)(c,{className:`py-8 text-center text-bambu-gray`,children:e(`finance.noAccess`,`You do not have permission to view finance data.`)})})]})}export{x as FinancePage};
\ No newline at end of file
diff --git a/static/assets/GCodeViewerPage-BhjPYegv.js b/static/assets/GCodeViewerPage-CqHPk_o-.js
similarity index 97%
rename from static/assets/GCodeViewerPage-BhjPYegv.js
rename to static/assets/GCodeViewerPage-CqHPk_o-.js
index 065953f91..afc6fc319 100644
--- a/static/assets/GCodeViewerPage-BhjPYegv.js
+++ b/static/assets/GCodeViewerPage-CqHPk_o-.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./useQuery-CCy0EwsM.js";import{t as o}from"./arrow-left-MSgMxOFV.js";import{t as s}from"./GcodeToolpathViewer-D4M17KI8.js";import{Vn as c,Wn as l}from"./index-Bw-_P2Fg.js";var u=e(n(),1),d=t();function f(){let e=c(),[t,n]=l(),{t:f}=i(),p=t.get(`archive`),m=t.get(`library_file`),h=t.get(`plate`),g=a({queryKey:[`gcode-viewer-archive-colors`,p],queryFn:()=>r.getArchiveCapabilities(Number(p)),enabled:!!p,staleTime:5*6e4,retry:!1}),_=a({queryKey:[`gcode-viewer-library-colors`,m],queryFn:()=>r.getLibraryFilePlates(Number(m)),enabled:!!m,staleTime:5*6e4,retry:!1}),v=a({queryKey:[`gcode-viewer-archive-plates`,p],queryFn:()=>r.getArchivePlates(Number(p)),enabled:!!p,staleTime:5*6e4,retry:!1}),y=(0,u.useMemo)(()=>(p?v.data?.plates:_.data?.plates)??[],[p,v.data,_.data]),b=(0,u.useMemo)(()=>h?Number(h):y.length===0?null:Math.min(...y.map(e=>e.index)),[h,y]),x=e=>{if(e===b)return;let r=new URLSearchParams(t);r.set(`plate`,String(e)),n(r,{replace:!0})},S=(0,u.useMemo)(()=>{if(p)return g.data?.filament_colors;let e=y.find(e=>e.index===b)||y[0];if(!e?.filaments?.length)return;let t=[];for(let n of e.filaments){let e=Math.max(0,(n.slot_id??1)-1);n.color&&(t[e]=n.color)}return t.length>0?t:void 0},[p,g.data,y,b]),C=(0,u.useMemo)(()=>{let e=e=>h?`${e}?plate=${encodeURIComponent(h)}`:e;return p?e(r.getArchiveGcode(Number(p))):m?e(r.getLibraryFileGcodeUrl(Number(m))):null},[p,m,h]),w=()=>{window.history.length>1?e(-1):e(p?`/archives`:`/files`)},T=p?f(`gcodeViewer.backToArchives`,`Back to Archives`):f(`gcodeViewer.backToFiles`,`Back to File Manager`);return(0,d.jsxs)(`div`,{className:`flex flex-col min-h-[calc(100vh-64px)] lg:h-screen`,children:[(0,d.jsxs)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-bambu-dark-tertiary flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,d.jsxs)(`button`,{type:`button`,onClick:w,className:`inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,d.jsx)(o,{className:`w-4 h-4`}),T]}),y.length>1&&(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:f(`gcodeViewer.plates`,`Plates`)}),y.map(e=>(0,d.jsx)(`button`,{type:`button`,onClick:()=>x(e.index),"aria-pressed":e.index===b,title:e.name??void 0,className:`px-2 py-0.5 rounded text-xs transition-colors ${e.index===b?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white`}`,children:f(`gcodeViewer.plateN`,`Plate {{n}}`,{n:e.index})},e.index))]})]}),C?(0,d.jsx)(s,{gcodeUrl:C,filamentColors:S,className:`flex-1 min-h-0`}):(0,d.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-bambu-gray`,children:f(`gcodeViewer.noSource`,`No file was given to preview.`)})]})}export{f as GCodeViewerPage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./useQuery-CCy0EwsM.js";import{t as o}from"./arrow-left-MSgMxOFV.js";import{t as s}from"./GcodeToolpathViewer-D4M17KI8.js";import{Vn as c,Wn as l}from"./index-ggB_TpPo.js";var u=e(n(),1),d=t();function f(){let e=c(),[t,n]=l(),{t:f}=i(),p=t.get(`archive`),m=t.get(`library_file`),h=t.get(`plate`),g=a({queryKey:[`gcode-viewer-archive-colors`,p],queryFn:()=>r.getArchiveCapabilities(Number(p)),enabled:!!p,staleTime:5*6e4,retry:!1}),_=a({queryKey:[`gcode-viewer-library-colors`,m],queryFn:()=>r.getLibraryFilePlates(Number(m)),enabled:!!m,staleTime:5*6e4,retry:!1}),v=a({queryKey:[`gcode-viewer-archive-plates`,p],queryFn:()=>r.getArchivePlates(Number(p)),enabled:!!p,staleTime:5*6e4,retry:!1}),y=(0,u.useMemo)(()=>(p?v.data?.plates:_.data?.plates)??[],[p,v.data,_.data]),b=(0,u.useMemo)(()=>h?Number(h):y.length===0?null:Math.min(...y.map(e=>e.index)),[h,y]),x=e=>{if(e===b)return;let r=new URLSearchParams(t);r.set(`plate`,String(e)),n(r,{replace:!0})},S=(0,u.useMemo)(()=>{if(p)return g.data?.filament_colors;let e=y.find(e=>e.index===b)||y[0];if(!e?.filaments?.length)return;let t=[];for(let n of e.filaments){let e=Math.max(0,(n.slot_id??1)-1);n.color&&(t[e]=n.color)}return t.length>0?t:void 0},[p,g.data,y,b]),C=(0,u.useMemo)(()=>{let e=e=>h?`${e}?plate=${encodeURIComponent(h)}`:e;return p?e(r.getArchiveGcode(Number(p))):m?e(r.getLibraryFileGcodeUrl(Number(m))):null},[p,m,h]),w=()=>{window.history.length>1?e(-1):e(p?`/archives`:`/files`)},T=p?f(`gcodeViewer.backToArchives`,`Back to Archives`):f(`gcodeViewer.backToFiles`,`Back to File Manager`);return(0,d.jsxs)(`div`,{className:`flex flex-col min-h-[calc(100vh-64px)] lg:h-screen`,children:[(0,d.jsxs)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-bambu-dark-tertiary flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,d.jsxs)(`button`,{type:`button`,onClick:w,className:`inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,d.jsx)(o,{className:`w-4 h-4`}),T]}),y.length>1&&(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:f(`gcodeViewer.plates`,`Plates`)}),y.map(e=>(0,d.jsx)(`button`,{type:`button`,onClick:()=>x(e.index),"aria-pressed":e.index===b,title:e.name??void 0,className:`px-2 py-0.5 rounded text-xs transition-colors ${e.index===b?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white`}`,children:f(`gcodeViewer.plateN`,`Plate {{n}}`,{n:e.index})},e.index))]})]}),C?(0,d.jsx)(s,{gcodeUrl:C,filamentColors:S,className:`flex-1 min-h-0`}):(0,d.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-bambu-gray`,children:f(`gcodeViewer.noSource`,`No file was given to preview.`)})]})}export{f as GCodeViewerPage};
\ No newline at end of file
diff --git a/static/assets/GroupEditPage-D6XMJTTK.js b/static/assets/GroupEditPage-Cr0OHBE3.js
similarity index 99%
rename from static/assets/GroupEditPage-D6XMJTTK.js
rename to static/assets/GroupEditPage-Cr0OHBE3.js
index 591ee9cb0..98d500281 100644
--- a/static/assets/GroupEditPage-D6XMJTTK.js
+++ b/static/assets/GroupEditPage-Cr0OHBE3.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as ee}from"./arrow-left-MSgMxOFV.js";import{t as c}from"./check-D1Pn8T1J.js";import{n as l}from"./ToastContext-VFOrCCoA.js";import{t as u}from"./loader-circle-CB4leTZa.js";import{t as d}from"./minus-D0aY9wbr.js";import{t as f}from"./search-BpAJdxRw.js";import{t as p}from"./shield-CfkeOiiL.js";import{t as m}from"./triangle-alert-gIik0G2C.js";import{t as h}from"./Card-OUAj0Ayh.js";import{t as g}from"./Button-pwVKPiYn.js";import{Jt as _,Rn as v,Un as y,Ut as b,Vn as x}from"./index-Bw-_P2Fg.js";var S=e(n(),1),C=t();function w(){let{id:e}=y(),t=x(),n=a(),{t:w}=i(),{showToast:T}=l(),E=!!e,[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)([]),[N,P]=(0,S.useState)(``),[F,I]=(0,S.useState)(!1),{data:L,isLoading:R}=o({queryKey:[`group`,e],queryFn:()=>r.getGroup(Number(e)),enabled:E}),{data:z,isLoading:B}=o({queryKey:[`permissions`],queryFn:()=>r.getPermissions()});E&&L&&!F&&(O(L.name),A(L.description||``),M(L.permissions),I(!0));let V=s({mutationFn:e=>r.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),T(w(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{T(e.message,`error`)}}),H=s({mutationFn:t=>r.updateGroup(Number(e),t),onSuccess:r=>{n.invalidateQueries({queryKey:[`groups`]}),r&&n.setQueryData([`group`,e],r),T(w(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{T(e.message,`error`)}}),U=V.isPending||H.isPending,W=E&&L?.is_system===!0&&L.name===`Administrators`,G=()=>{if(!D.trim()){T(w(`groups.toast.enterGroupName`),`error`);return}if(E){let e=!L||j.length!==L.permissions.length||j.some(e=>!L.permissions.includes(e));H.mutate({name:D===L?.name?void 0:D,description:k,permissions:L?.is_system&&!e?void 0:j})}else V.mutate({name:D,description:k||void 0,permissions:j})},K=e=>{M(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},q=(e,t)=>{let n=e.permissions.map(e=>e.value);M(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},J=e=>e.permissions.every(e=>j.includes(e.value)),Y=e=>{let t=e.permissions.filter(e=>j.includes(e.value)).length;return t>0&&t{z&&M(z.all_permissions)},Z=()=>{M([])},Q=N.toLowerCase(),$=(0,S.useMemo)(()=>z?Q?z.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(Q))})).filter(e=>e.permissions.length>0):z.categories:[],[z,Q]),te=z?.all_permissions.length??0;return R||B?(0,C.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,C.jsx)(u,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,C.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,C.jsx)(ee,{className:`w-5 h-5`})}),(0,C.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:w(E?`groups.editor.title`:`groups.editor.createTitle`)})]}),E&&L?.is_system&&(0,C.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-sm`,children:[(0,C.jsx)(m,{className:`w-4 h-4 shrink-0`}),w(`groups.form.systemGroupWarning`)]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:w(`groups.form.groupName`)}),(0,C.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(e.target.value),disabled:E&&L?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:w(`groups.form.groupNamePlaceholder`)})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:w(`groups.form.description`)}),(0,C.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:w(`groups.form.descriptionPlaceholder`)})]})]}),(0,C.jsx)(h,{children:(0,C.jsxs)(`div`,{className:`p-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,C.jsx)(_,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,C.jsx)(`span`,{className:`text-white font-medium text-sm`,children:w(`groups.editor.printerAccess`)}),(0,C.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:W?w(`groups.editor.adminsSeeAllPrinters`):E?L?.restrict_printers?w(`groups.editor.printerAccessLimited`,{printers:L.printer_ids.length,locations:L.locations?.length??0}):w(`groups.editor.printerAccessOpen`):w(`groups.editor.printerAccessAfterCreate`)})]}),E&&!W&&(0,C.jsx)(v,{to:`/settings?tab=users&sub=printer-access&group=${e}`,className:`text-sm text-bambu-green hover:underline shrink-0`,children:w(`groups.editor.managePrinterAccess`)})]})}),(0,C.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[w(`groups.editor.permissionsSelected`,{count:j.length}),` / `,te]}),(0,C.jsx)(g,{size:`sm`,variant:`ghost`,onClick:X,children:w(`groups.editor.selectAll`)}),(0,C.jsx)(g,{size:`sm`,variant:`ghost`,onClick:Z,children:w(`groups.editor.clearAll`)})]}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(f,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,C.jsx)(`input`,{type:`text`,value:N,onChange:e=>P(e.target.value),placeholder:w(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),$.length===0?(0,C.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:w(`groups.editor.noResults`)}):(0,C.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:$.map(e=>{let t=z.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>j.includes(e.value)).length,r=t.permissions.length,i=J(t),a=Y(t);return(0,C.jsxs)(h,{children:[(0,C.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsxs)(`button`,{type:`button`,onClick:()=>q(t,!i),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${i?`bg-bambu-green border-bambu-green`:a?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[i&&(0,C.jsx)(c,{className:`w-3 h-3 text-white`}),a&&!i&&(0,C.jsx)(d,{className:`w-3 h-3 text-white`})]}),(0,C.jsx)(p,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,C.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,C.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,r]})]}),(0,C.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,C.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:j.includes(e.value),onChange:()=>K(e.value),className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,C.jsxs)(`span`,{className:`flex flex-col`,children:[(0,C.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,C.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:w(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,C.jsx)(`div`,{className:`h-16`}),(0,C.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,C.jsx)(g,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:w(`common.cancel`)}),(0,C.jsx)(g,{onClick:G,disabled:U||!D.trim(),children:U?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(u,{className:`w-4 h-4 animate-spin`}),w(`common.saving`)]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(b,{className:`w-4 h-4`}),w(`common.save`)]})})]})]})}export{w as GroupEditPage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as ee}from"./arrow-left-MSgMxOFV.js";import{t as c}from"./check-D1Pn8T1J.js";import{n as l}from"./ToastContext-VFOrCCoA.js";import{t as u}from"./loader-circle-CB4leTZa.js";import{t as d}from"./minus-D0aY9wbr.js";import{t as f}from"./search-BpAJdxRw.js";import{t as p}from"./shield-CfkeOiiL.js";import{t as m}from"./triangle-alert-gIik0G2C.js";import{t as h}from"./Card-OUAj0Ayh.js";import{t as g}from"./Button-pwVKPiYn.js";import{Jt as _,Rn as v,Un as y,Ut as b,Vn as x}from"./index-ggB_TpPo.js";var S=e(n(),1),C=t();function w(){let{id:e}=y(),t=x(),n=a(),{t:w}=i(),{showToast:T}=l(),E=!!e,[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)([]),[N,P]=(0,S.useState)(``),[F,I]=(0,S.useState)(!1),{data:L,isLoading:R}=o({queryKey:[`group`,e],queryFn:()=>r.getGroup(Number(e)),enabled:E}),{data:z,isLoading:B}=o({queryKey:[`permissions`],queryFn:()=>r.getPermissions()});E&&L&&!F&&(O(L.name),A(L.description||``),M(L.permissions),I(!0));let V=s({mutationFn:e=>r.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),T(w(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{T(e.message,`error`)}}),H=s({mutationFn:t=>r.updateGroup(Number(e),t),onSuccess:r=>{n.invalidateQueries({queryKey:[`groups`]}),r&&n.setQueryData([`group`,e],r),T(w(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{T(e.message,`error`)}}),U=V.isPending||H.isPending,W=E&&L?.is_system===!0&&L.name===`Administrators`,G=()=>{if(!D.trim()){T(w(`groups.toast.enterGroupName`),`error`);return}if(E){let e=!L||j.length!==L.permissions.length||j.some(e=>!L.permissions.includes(e));H.mutate({name:D===L?.name?void 0:D,description:k,permissions:L?.is_system&&!e?void 0:j})}else V.mutate({name:D,description:k||void 0,permissions:j})},K=e=>{M(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},q=(e,t)=>{let n=e.permissions.map(e=>e.value);M(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},J=e=>e.permissions.every(e=>j.includes(e.value)),Y=e=>{let t=e.permissions.filter(e=>j.includes(e.value)).length;return t>0&&t{z&&M(z.all_permissions)},Z=()=>{M([])},Q=N.toLowerCase(),$=(0,S.useMemo)(()=>z?Q?z.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(Q))})).filter(e=>e.permissions.length>0):z.categories:[],[z,Q]),te=z?.all_permissions.length??0;return R||B?(0,C.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,C.jsx)(u,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,C.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,C.jsx)(ee,{className:`w-5 h-5`})}),(0,C.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:w(E?`groups.editor.title`:`groups.editor.createTitle`)})]}),E&&L?.is_system&&(0,C.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-sm`,children:[(0,C.jsx)(m,{className:`w-4 h-4 shrink-0`}),w(`groups.form.systemGroupWarning`)]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:w(`groups.form.groupName`)}),(0,C.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(e.target.value),disabled:E&&L?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:w(`groups.form.groupNamePlaceholder`)})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:w(`groups.form.description`)}),(0,C.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:w(`groups.form.descriptionPlaceholder`)})]})]}),(0,C.jsx)(h,{children:(0,C.jsxs)(`div`,{className:`p-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,C.jsx)(_,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,C.jsx)(`span`,{className:`text-white font-medium text-sm`,children:w(`groups.editor.printerAccess`)}),(0,C.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:W?w(`groups.editor.adminsSeeAllPrinters`):E?L?.restrict_printers?w(`groups.editor.printerAccessLimited`,{printers:L.printer_ids.length,locations:L.locations?.length??0}):w(`groups.editor.printerAccessOpen`):w(`groups.editor.printerAccessAfterCreate`)})]}),E&&!W&&(0,C.jsx)(v,{to:`/settings?tab=users&sub=printer-access&group=${e}`,className:`text-sm text-bambu-green hover:underline shrink-0`,children:w(`groups.editor.managePrinterAccess`)})]})}),(0,C.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[w(`groups.editor.permissionsSelected`,{count:j.length}),` / `,te]}),(0,C.jsx)(g,{size:`sm`,variant:`ghost`,onClick:X,children:w(`groups.editor.selectAll`)}),(0,C.jsx)(g,{size:`sm`,variant:`ghost`,onClick:Z,children:w(`groups.editor.clearAll`)})]}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(f,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,C.jsx)(`input`,{type:`text`,value:N,onChange:e=>P(e.target.value),placeholder:w(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),$.length===0?(0,C.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:w(`groups.editor.noResults`)}):(0,C.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:$.map(e=>{let t=z.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>j.includes(e.value)).length,r=t.permissions.length,i=J(t),a=Y(t);return(0,C.jsxs)(h,{children:[(0,C.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsxs)(`button`,{type:`button`,onClick:()=>q(t,!i),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${i?`bg-bambu-green border-bambu-green`:a?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[i&&(0,C.jsx)(c,{className:`w-3 h-3 text-white`}),a&&!i&&(0,C.jsx)(d,{className:`w-3 h-3 text-white`})]}),(0,C.jsx)(p,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,C.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,C.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,r]})]}),(0,C.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,C.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:j.includes(e.value),onChange:()=>K(e.value),className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,C.jsxs)(`span`,{className:`flex flex-col`,children:[(0,C.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,C.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:w(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,C.jsx)(`div`,{className:`h-16`}),(0,C.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,C.jsx)(g,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:w(`common.cancel`)}),(0,C.jsx)(g,{onClick:G,disabled:U||!D.trim(),children:U?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(u,{className:`w-4 h-4 animate-spin`}),w(`common.saving`)]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(b,{className:`w-4 h-4`}),w(`common.save`)]})})]})]})}export{w as GroupEditPage};
\ No newline at end of file
diff --git a/static/assets/ImagePreviewModal-CTLU6Jnd.js b/static/assets/ImagePreviewModal-kbbJSk44.js
similarity index 98%
rename from static/assets/ImagePreviewModal-CTLU6Jnd.js
rename to static/assets/ImagePreviewModal-kbbJSk44.js
index f75ebd949..579cff3c9 100644
--- a/static/assets/ImagePreviewModal-CTLU6Jnd.js
+++ b/static/assets/ImagePreviewModal-kbbJSk44.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-BdOyoZJz.js";import{t as o}from"./loader-circle-CB4leTZa.js";import{n as s,t as c}from"./zoom-out-C85W_TC5.js";import{t as l}from"./file-DDkFXH-b.js";import{Gt as u,un as d}from"./index-Bw-_P2Fg.js";import{n as f,r as p,t as m}from"./usePreviewFullscreen-DOsgAeT7.js";var h=e(n(),1),g=t(),_=.4,v=8,y=1.25,b=30,x=Math.log(y)/b,S=e=>Math.min(v,Math.max(_,e)),C={x:0,y:0};function w(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:t,fileSize:n,onClose:_}){let{t:v}=a(),T=m(),{isFullscreen:E,toggleFullscreen:D}=T,O=(0,h.useRef)(null),k=(0,h.useRef)(null),[A,j]=(0,h.useState)(null),[M,N]=(0,h.useState)(!1),[P,F]=(0,h.useState)(null),[I,L]=(0,h.useState)(1),[R,z]=(0,h.useState)(C),[B,V]=(0,h.useState)(!1),H=(0,h.useRef)(1),U=(0,h.useRef)(C),W=(0,h.useRef)(new Map),G=(0,h.useRef)(null),K=(0,h.useCallback)((e,t)=>{let n=O.current,r=k.current;if(!n||!r)return e;let i=Math.max(0,(r.offsetWidth*t-n.clientWidth)/2),a=Math.max(0,(r.offsetHeight*t-n.clientHeight)/2);return{x:Math.min(i,Math.max(-i,e.x)),y:Math.min(a,Math.max(-a,e.y))}},[]),q=(0,h.useCallback)((e,t)=>{H.current=e,U.current=t,L(e),z(t)},[]),J=(0,h.useCallback)((e,t,n)=>{let r=H.current,i=S(r*e);if(i===r)return;let a=O.current,o=U.current,s={x:o.x*(i/r),y:o.y*(i/r)};if(a){let e=a.getBoundingClientRect(),c=(t??e.left+e.width/2)-(e.left+e.width/2),l=(n??e.top+e.height/2)-(e.top+e.height/2),u=i/r;s={x:c-(c-o.x)*u,y:l-(l-o.y)*u}}q(i,K(s,i))},[K,q]),Y=(0,h.useCallback)(()=>q(1,C),[q]);(0,h.useEffect)(()=>{let t=!1,a=null;if(j(null),N(!1),F(null),q(1,C),n>52428800){F(v(`fileManager.preview.tooLarge`,{size:l(n)}));return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let n=await fetch(r.getLibraryFileDownloadUrl(e),{headers:o});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.blob();t||(a=URL.createObjectURL(i),j(a))})().catch(e=>{console.error(`[image-preview] load failed`,e),t||F(v(`fileManager.preview.error`))}),()=>{t=!0,a&&URL.revokeObjectURL(a)}},[e,n,v,q]),(0,h.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),J(y)):e.key===`-`?(e.preventDefault(),J(1/y)):e.key===`0`&&(e.preventDefault(),Y()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Y,J]),(0,h.useEffect)(()=>{let e=O.current;if(!e)return;let t=e=>{e.preventDefault();let t=Math.max(-30,Math.min(b,w(e)));J(Math.exp(-t*x),e.clientX,e.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[J,A]);let X=e=>{W.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),G.current=null,W.current.size===1&&H.current>1&&(e.currentTarget.setPointerCapture(e.pointerId),V(!0))},Z=e=>{W.current.delete(e.pointerId),G.current=null,W.current.size===0&&V(!1)},Q=e=>{let t=W.current,n=t.get(e.pointerId);if(!n)return;if(e.pointerType===`mouse`&&e.buttons===0){Z(e);return}if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){if(H.current<=1)return;let t={x:U.current.x+(e.clientX-n.x),y:U.current.y+(e.clientY-n.y)};q(H.current,K(t,H.current));return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=G.current;G.current=a,o!=null&&o>0&&a>0&&J(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},$=I>1;return(0,g.jsx)(f,{title:t,fullscreen:T,onClose:_,icon:(0,g.jsx)(d,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:A?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{onClick:()=>J(1/y),className:p,"aria-label":v(`fileManager.preview.zoomOut`),children:(0,g.jsx)(c,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:()=>J(y),className:p,"aria-label":v(`fileManager.preview.zoomIn`),children:(0,g.jsx)(s,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:Y,className:p,"aria-label":v(`fileManager.preview.resetZoom`),children:(0,g.jsx)(u,{className:`w-4 h-4`})})]}):void 0,children:(0,g.jsx)(`div`,{ref:O,"data-testid":`image-preview-content`,className:`relative flex-1 min-h-0 overflow-hidden bg-bambu-dark flex items-center justify-center touch-none ${E?``:`rounded-b-lg`} ${$?B?`cursor-grabbing`:`cursor-grab`:``}`,onDoubleClick:D,onPointerDown:X,onPointerMove:Q,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:P?(0,g.jsx)(`p`,{className:`text-bambu-gray text-center p-6`,children:P}):(0,g.jsxs)(g.Fragment,{children:[A&&(0,g.jsx)(`img`,{ref:k,src:A,alt:t,draggable:!1,onLoad:()=>N(!0),onError:()=>F(v(`fileManager.preview.error`)),style:{transform:`translate(${R.x}px, ${R.y}px) scale(${I})`},className:`max-w-full max-h-full object-contain select-none`}),!M&&(0,g.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,g.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})})}export{T as ImagePreviewModal};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-BdOyoZJz.js";import{t as o}from"./loader-circle-CB4leTZa.js";import{n as s,t as c}from"./zoom-out-C85W_TC5.js";import{t as l}from"./file-DDkFXH-b.js";import{Gt as u,un as d}from"./index-ggB_TpPo.js";import{n as f,r as p,t as m}from"./usePreviewFullscreen-DOsgAeT7.js";var h=e(n(),1),g=t(),_=.4,v=8,y=1.25,b=30,x=Math.log(y)/b,S=e=>Math.min(v,Math.max(_,e)),C={x:0,y:0};function w(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:t,fileSize:n,onClose:_}){let{t:v}=a(),T=m(),{isFullscreen:E,toggleFullscreen:D}=T,O=(0,h.useRef)(null),k=(0,h.useRef)(null),[A,j]=(0,h.useState)(null),[M,N]=(0,h.useState)(!1),[P,F]=(0,h.useState)(null),[I,L]=(0,h.useState)(1),[R,z]=(0,h.useState)(C),[B,V]=(0,h.useState)(!1),H=(0,h.useRef)(1),U=(0,h.useRef)(C),W=(0,h.useRef)(new Map),G=(0,h.useRef)(null),K=(0,h.useCallback)((e,t)=>{let n=O.current,r=k.current;if(!n||!r)return e;let i=Math.max(0,(r.offsetWidth*t-n.clientWidth)/2),a=Math.max(0,(r.offsetHeight*t-n.clientHeight)/2);return{x:Math.min(i,Math.max(-i,e.x)),y:Math.min(a,Math.max(-a,e.y))}},[]),q=(0,h.useCallback)((e,t)=>{H.current=e,U.current=t,L(e),z(t)},[]),J=(0,h.useCallback)((e,t,n)=>{let r=H.current,i=S(r*e);if(i===r)return;let a=O.current,o=U.current,s={x:o.x*(i/r),y:o.y*(i/r)};if(a){let e=a.getBoundingClientRect(),c=(t??e.left+e.width/2)-(e.left+e.width/2),l=(n??e.top+e.height/2)-(e.top+e.height/2),u=i/r;s={x:c-(c-o.x)*u,y:l-(l-o.y)*u}}q(i,K(s,i))},[K,q]),Y=(0,h.useCallback)(()=>q(1,C),[q]);(0,h.useEffect)(()=>{let t=!1,a=null;if(j(null),N(!1),F(null),q(1,C),n>52428800){F(v(`fileManager.preview.tooLarge`,{size:l(n)}));return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let n=await fetch(r.getLibraryFileDownloadUrl(e),{headers:o});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.blob();t||(a=URL.createObjectURL(i),j(a))})().catch(e=>{console.error(`[image-preview] load failed`,e),t||F(v(`fileManager.preview.error`))}),()=>{t=!0,a&&URL.revokeObjectURL(a)}},[e,n,v,q]),(0,h.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),J(y)):e.key===`-`?(e.preventDefault(),J(1/y)):e.key===`0`&&(e.preventDefault(),Y()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Y,J]),(0,h.useEffect)(()=>{let e=O.current;if(!e)return;let t=e=>{e.preventDefault();let t=Math.max(-30,Math.min(b,w(e)));J(Math.exp(-t*x),e.clientX,e.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[J,A]);let X=e=>{W.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),G.current=null,W.current.size===1&&H.current>1&&(e.currentTarget.setPointerCapture(e.pointerId),V(!0))},Z=e=>{W.current.delete(e.pointerId),G.current=null,W.current.size===0&&V(!1)},Q=e=>{let t=W.current,n=t.get(e.pointerId);if(!n)return;if(e.pointerType===`mouse`&&e.buttons===0){Z(e);return}if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){if(H.current<=1)return;let t={x:U.current.x+(e.clientX-n.x),y:U.current.y+(e.clientY-n.y)};q(H.current,K(t,H.current));return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=G.current;G.current=a,o!=null&&o>0&&a>0&&J(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},$=I>1;return(0,g.jsx)(f,{title:t,fullscreen:T,onClose:_,icon:(0,g.jsx)(d,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:A?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{onClick:()=>J(1/y),className:p,"aria-label":v(`fileManager.preview.zoomOut`),children:(0,g.jsx)(c,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:()=>J(y),className:p,"aria-label":v(`fileManager.preview.zoomIn`),children:(0,g.jsx)(s,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:Y,className:p,"aria-label":v(`fileManager.preview.resetZoom`),children:(0,g.jsx)(u,{className:`w-4 h-4`})})]}):void 0,children:(0,g.jsx)(`div`,{ref:O,"data-testid":`image-preview-content`,className:`relative flex-1 min-h-0 overflow-hidden bg-bambu-dark flex items-center justify-center touch-none ${E?``:`rounded-b-lg`} ${$?B?`cursor-grabbing`:`cursor-grab`:``}`,onDoubleClick:D,onPointerDown:X,onPointerMove:Q,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:P?(0,g.jsx)(`p`,{className:`text-bambu-gray text-center p-6`,children:P}):(0,g.jsxs)(g.Fragment,{children:[A&&(0,g.jsx)(`img`,{ref:k,src:A,alt:t,draggable:!1,onLoad:()=>N(!0),onError:()=>F(v(`fileManager.preview.error`)),style:{transform:`translate(${R.x}px, ${R.y}px) scale(${I})`},className:`max-w-full max-h-full object-contain select-none`}),!M&&(0,g.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,g.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})})}export{T as ImagePreviewModal};
\ No newline at end of file
diff --git a/static/assets/InventoryPage-CFjZN794.js b/static/assets/InventoryPage-BLBZoEYd.js
similarity index 99%
rename from static/assets/InventoryPage-CFjZN794.js
rename to static/assets/InventoryPage-BLBZoEYd.js
index 4c42c68f6..77faa049e 100644
--- a/static/assets/InventoryPage-CFjZN794.js
+++ b/static/assets/InventoryPage-BLBZoEYd.js
@@ -1,2 +1,2 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,n as i,r as a,t as o,v as s,w as c}from"./client-BdOyoZJz.js";import{n as l}from"./QueryClientProvider-Clbyr4Jg.js";import{t as u}from"./useQuery-CCy0EwsM.js";import{t as d}from"./useMutation-qh3Iyscy.js";import{t as f}from"./useQueries-C87lFrjE.js";import{t as p}from"./createLucideIcon-Yo2YoYjm.js";import{i as m,n as h,r as g}from"./haSensorDisplay-CSo8Nw_c.js";import{t as _}from"./arrow-down-C4OBNDqJ.js";import{t as v}from"./arrow-up-down-C-1Kkt1x.js";import{t as y}from"./arrow-up-Dam8cLfE.js";import{i as b,n as x,r as S,t as C}from"./ReferenceLine-l3CI8D5f.js";import{t as w}from"./check-D1Pn8T1J.js";import{a as T,i as E,n as D,t as O}from"./info-DcT0QU8O.js";import{n as ee,t as k}from"./chevrons-right-OnQ-9jKz.js";import{n as te,r as A}from"./ToastContext-VFOrCCoA.js";import{t as j}from"./columns-2-CGEUxYp_.js";import{t as M}from"./copy-3N5VKzXz.js";import{t as N}from"./layout-grid-D4S7CgZJ.js";import{t as P}from"./link-2-Bj1oMj3O.js";import{t as F}from"./loader-circle-CB4leTZa.js";import{t as ne}from"./lock-C288ZvMI.js";import{_ as I,c as L,g as re,h as R,s as ie,v as ae}from"./locationSensorDefaults-BtezRgcN.js";import{t as oe}from"./package-D9xR0eOt.js";import{t as se}from"./search-BpAJdxRw.js";import{t as z}from"./sparkles-AUof3WTI.js";import{L as ce,Rn as le,Xt as ue,c as de,p as fe,s as pe}from"./CartesianChart-DcboTNtX.js";import{t as B}from"./triangle-alert-gIik0G2C.js";import{t as me}from"./unlink-DJBJ04VB.js";import{t as he}from"./x-Dctff5l9.js";import{t as V}from"./Button-pwVKPiYn.js";import{r as ge,v as H,y as _e}from"./date-G9KUauqz.js";import{n as ve}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$t as ye,At as be,Cn as xe,Gt as Se,H as Ce,Jt as U,Kt as we,Ln as Te,Lt as Ee,Mn as De,On as Oe,Pt as ke,Rt as Ae,Tt as je,Ut as Me,Wn as Ne,Zt as Pe,_t as Fe,a as Ie,at as Le,bt as Re,cn as ze,en as Be,ft as Ve,i as He,jn as Ue,kn as We,kt as Ge,lt as Ke,o as qe,ot as Je,r as Ye,s as Xe,st as W,w as Ze,wn as Qe,xn as $e,yt as et,zt as tt}from"./index-Bw-_P2Fg.js";import{i as nt,r as rt}from"./slicerPrinterMatch-CUdoNag2.js";import{t as it}from"./ColumnConfigModal-BPctn5Lk.js";import{n as at,t as ot}from"./AreaChart-J0I0YlYN.js";import{a as st,i as ct,n as lt,o as ut,r as G,s as dt,t as ft}from"./AdditionalSection-B9iB6xW2.js";import{_ as pt,a as K,b as mt,c as ht,d as gt,f as _t,g as vt,i as yt,l as bt,m as xt,n as St,o as Ct,r as wt,s as Tt,t as Et,u as Dt,v as Ot}from"./utils-D29gNIio.js";import{t as kt}from"./AssignToAmsModal-DKCru_ir.js";import{t as At}from"./inventorySearch-C82dQp2B.js";var q=p(`beaker`,[[`path`,{d:`M4.5 3h15`,key:`c7n0jr`}],[`path`,{d:`M6 3v16a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V3`,key:`m1uhx7`}],[`path`,{d:`M6 14h12`,key:`4cwo0f`}]]),jt=p(`chart-no-axes-column`,[[`path`,{d:`M5 21v-6`,key:`1hz6c0`}],[`path`,{d:`M12 21V3`,key:`1lcnhd`}],[`path`,{d:`M19 21V9`,key:`unv183`}]]),Mt=p(`credit-card`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`2`,key:`ynyp8z`}],[`line`,{x1:`2`,x2:`22`,y1:`10`,y2:`10`,key:`1b3vmo`}]]),Nt=p(`group`,[[`path`,{d:`M3 7V5c0-1.1.9-2 2-2h2`,key:`adw53z`}],[`path`,{d:`M17 3h2c1.1 0 2 .9 2 2v2`,key:`an4l38`}],[`path`,{d:`M21 17v2c0 1.1-.9 2-2 2h-2`,key:`144t0e`}],[`path`,{d:`M7 21H5c-1.1 0-2-.9-2-2v-2`,key:`rtnfgi`}],[`rect`,{width:`7`,height:`5`,x:`7`,y:`7`,rx:`1`,key:`1eyiv7`}],[`rect`,{width:`7`,height:`5`,x:`10`,y:`12`,rx:`1`,key:`1qlmkx`}]]),Pt=p(`package-check`,[[`path`,{d:`m16 16 2 2 4-4`,key:`gfu2re`}],[`path`,{d:`M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14`,key:`e7tb2h`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`12`,key:`a4e8g8`}]]),Ft=p(`store`,[[`path`,{d:`M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5`,key:`slp6dd`}],[`path`,{d:`M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244`,key:`o0xfot`}],[`path`,{d:`M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05`,key:`wn3emo`}]]),It=p(`table-properties`,[[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),J=e(n(),1),Y=t(),Lt=1.65,Rt=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function X(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function Z(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function zt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function Bt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Vt(e){if(e.length<2)return null;let t=new Map;for(let n of e){let e=n.created_at.slice(0,10);t.set(e,(t.get(e)??0)+n.weight_used)}if(t.size<2)return null;let n=[...t.entries()].map(([e,t])=>({ms:new Date(e).getTime(),totalG:t})).sort((e,t)=>e.ms-t.ms),r=Date.now(),i=Math.LN2/30,a=[];for(let e=1;ee+t.weight,0);if(o===0)return null;let s=a.reduce((e,t)=>e+t.rate*t.weight,0)/o,c=a.reduce((e,t)=>e+t.weight*(t.rate-s)**2,0)/o;return{rate:s,stdDev:Math.sqrt(c)}}function Ht(e){let t=e.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0);if(t===0)return null;let n=Date.now(),r=(n-e.reduce((e,t)=>{let n=new Date(t.created_at).getTime();return nr.getAllUsageHistory(5e3),staleTime:6e4,enabled:s}),{data:M=[]}=u({queryKey:[`shopping-list`],queryFn:r.getShoppingList,staleTime:3e4,enabled:s}),N=k?.forecast_global_lead_time_days??0,P=(0,J.useMemo)(()=>{let e=new Map;for(let t of A)e.set(X(t.material,t.subtype,t.brand,t.color_name),t);return e},[A]),F=(0,J.useMemo)(()=>{let e=new Map;for(let t of j){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[j]),I=(0,J.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=X(n.material,n.subtype,n.brand,n.color_name),r=t.get(e)??{key:e,material:n.material,subtype:n.subtype,brand:n.brand,colorName:n.color_name,spools:[]};r.spools.push(n),t.set(e,r)}return[...t.values()]},[e]),L=(0,J.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),I.map(t=>{let n=P.get(t.key)??(t.colorName===null?null:P.get(X(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(N,r),a=n?.safety_margin_value??14,o=n?.safety_margin_unit??`days`,s=t.spools.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),c=t.spools.reduce((e,t)=>e+t.label_weight,0),l=t.spools.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0),u=[];for(let e of t.spools)(e.weight_used_baseline??0)===0&&u.push(...F.get(e.id)??[]);let d=null,f=null,p=`none`,m=Vt(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=Ht(t.spools);e!==null&&(d=e,p=`delta`)}let h=Lt*(f??(d===null?0:d*.2))*Math.sqrt(i)+(o===`g`?a:d===null?a*5:d*a),g=d===null?0:d*i+h,_=d&&d>0?Math.floor(s/d):null,v=_===null?null:Z(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:Z(e,Math.max(0,y)),x=_!==null&&i>0&&_<=i,S=!x&&y!==null&&y<=0;return{group:t,settings:n,totalRemainingG:s,totalLabelG:c,totalSpools:t.spools.length,totalUsedG:l,dailyRateG:d,dailyRateStdDev:f,rateTier:p,effectiveLeadTimeDays:i,safetyStockG:h,reorderPointG:g,daysRemaining:_,daysUntilROP:y,projectedEmptyDate:v,reorderTriggerDate:b,reorderAlert:S,stockBreakAlert:x}})},[I,P,F,N]),re=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.material))].sort(),[I]),R=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.brand).filter(Boolean))].sort(),[I]),ie=(0,J.useMemo)(()=>{let e=[...L];return v&&(e=e.filter(e=>e.group.material===v)),b&&(e=e.filter(e=>e.group.brand===b)),e.sort((e,t)=>{let n=0,r=0;switch(m){case`material`:n=[e.group.material,e.group.subtype??``,e.group.brand??``].join(` `).toLowerCase(),r=[t.group.material,t.group.subtype??``,t.group.brand??``].join(` `).toLowerCase();break;case`used`:n=e.totalUsedG,r=t.totalUsedG;break;case`days_left`:n=e.daysRemaining??999999,r=t.daysRemaining??999999;break;case`stock`:n=e.totalRemainingG,r=t.totalRemainingG;break}let i=nr);return g===`asc`?i:-i}),e},[L,m,g,v,b]),ae=(0,J.useMemo)(()=>L.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[L]),oe=(0,J.useMemo)(()=>[...L].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[L]);if(!s)return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,Y.jsx)(ne,{className:`w-8 h-8 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noReadAccess`)})]});function se(e){m===e?_(e=>e===`asc`?`desc`:`asc`):(h(e),_(e===`days_left`?`asc`:`desc`))}let z=M.length>0?M.length:null;return(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[ae.length>0&&(0,Y.jsxs)(`button`,{onClick:()=>p(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${ae.some(e=>e.stockBreakAlert)?`bg-red-100 dark:bg-red-500/15 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300 hover:bg-red-200 dark:hover:bg-red-500/25`:`bg-yellow-100 dark:bg-yellow-500/15 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300 hover:bg-yellow-200 dark:hover:bg-yellow-500/25`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),i(`forecast.alertCount`,{count:ae.length}),f?(0,Y.jsx)(E,{className:`w-3.5 h-3.5`}):(0,Y.jsx)(T,{className:`w-3.5 h-3.5`})]}),d&&(0,Y.jsx)(Yt,{value:N,onSave:e=>{r.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(i(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,Y.jsxs)(`select`,{value:v,onChange:e=>y(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${v?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.material`)}),re.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${b?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.brand`)}),R.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`button`,{onClick:()=>D(e=>!e),className:`relative flex items-center gap-2 px-3 py-1.5 rounded-lg border border-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary text-sm transition-colors ml-auto`,children:[(0,Y.jsx)(tt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:i(`forecast.shoppingList`)}),z&&(0,Y.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-bambu-green text-white text-[10px] font-bold flex items-center justify-center`,children:z})]})]}),f&&ae.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2`,children:ae.map(e=>(0,Y.jsx)(Kt,{forecast:e,onCart:()=>C(e)},e.group.key))}),w&&(0,Y.jsx)(en,{items:M,forecasts:L,globalLeadTime:N,canWrite:d,onClose:()=>D(!1),onRemove:e=>{r.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))},onClear:()=>{r.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))}}),oe.length>0&&(0,Y.jsx)(Jt,{forecasts:oe,days:O,onDaysChange:ee}),L.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,Y.jsx)(le,{className:`w-10 h-10 mb-3 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noSpools`)})]}):(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,Y.jsx)(Gt,{col:`material`,active:m,dir:g,onSort:se,children:i(`forecast.sku`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`locations.spools`)}),(0,Y.jsx)(Gt,{col:`stock`,active:m,dir:g,onSort:se,children:i(`forecast.stock`)}),(0,Y.jsx)(Gt,{col:`used`,active:m,dir:g,onSort:se,children:i(`forecast.dailyRate`)}),(0,Y.jsx)(Gt,{col:`days_left`,active:m,dir:g,onSort:se,children:i(`forecast.daysLeft`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.emptyBy`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.reorderBy`)}),(0,Y.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:ie.map(e=>(0,Y.jsx)(Xt,{forecast:e,globalLeadTime:N,canWrite:d,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>C(e),showToast:n},e.group.key))})]})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-3 text-xs text-bambu-gray border-t border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),i(`forecast.trendLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),i(`forecast.estimatedLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),i(`forecast.noDataLegend`)]})]})]}),S&&(0,Y.jsx)(nn,{forecast:S,onClose:()=>C(null),onAdd:e=>{r.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(i(`forecast.addedToCart`),`success`),C(null),D(!0)}).catch(()=>n(i(`forecast.failedAddItem`),`error`))}})]})}function Gt({col:e,active:t,dir:n,onSort:r,children:i}){return(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide cursor-pointer select-none hover:text-white transition-colors`,onClick:()=>r(e),children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,Y.jsx)(y,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(_,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(v,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function Kt({forecast:e,onCart:t}){let{t:n}=c(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${i?`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`:`bg-yellow-50 dark:bg-yellow-500/10 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})]})]}),(0,Y.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 px-2.5 py-1 rounded border border-current text-xs opacity-70 hover:opacity-100 transition-opacity`,children:[(0,Y.jsx)(tt,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var qt=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function Jt({forecasts:e,days:t,onDaysChange:n}){let{t:r}=c(),i=Array.from({length:t+1},(e,t)=>t),a=e.map((e,n)=>({key:e.group.key,label:[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),color:Rt[n%Rt.length],rop:e.reorderPointG,points:Ut(e,t)})),o=i.map(e=>{let t={day:e,label:Bt(Z(new Date,e))};for(let n of a){let r=n.points.find(t=>t.day===e);t[n.key]=r?.stock??0}return t}),s=(()=>{for(let e=t;e>=0;e--)if(a.some(t=>o[e]?.[t.key]>0))return e;return t})(),l=o.slice(0,s+1),u=a.filter(e=>e.rop>0);return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsx)(le,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:qt.map(e=>(0,Y.jsx)(`button`,{onClick:()=>n(e.value),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${t===e.value?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:e.label},e.value))})]}),(0,Y.jsx)(ue,{width:`100%`,height:220,children:(0,Y.jsxs)(ot,{data:l,margin:{top:4,right:8,bottom:0,left:0},children:[(0,Y.jsx)(`defs`,{children:a.map(e=>(0,Y.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Y.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,Y.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,Y.jsx)(fe,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,Y.jsx)(de,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,Y.jsx)(pe,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,Y.jsx)(ce,{content:({label:e,payload:t})=>t?.length?(0,Y.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,Y.jsx)(`div`,{style:{color:`#9CA3AF`,marginBottom:6},children:e}),t.map(e=>{let t=a.find(t=>t.key===String(e.dataKey));return typeof e.value==`number`?(0,Y.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,Y.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,Y.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,Y.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,Y.jsx)(x,{formatter:e=>(0,Y.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,Y.jsx)(at,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),u.map(e=>(0,Y.jsx)(C,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function Yt({value:e,onSave:t}){let{t:n}=c(),[r,i]=(0,J.useState)(!1),[a,o]=(0,J.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-tertiary/40 rounded-lg border border-bambu-dark-tertiary text-xs text-bambu-gray`,children:[(0,Y.jsx)(O,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,Y.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-14 px-1.5 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,Y.jsx)(`button`,{type:`submit`,className:`px-2 py-0.5 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80`,children:n(`forecast.save`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,Y.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function Xt({forecast:e,globalLeadTime:t,canWrite:n,onSaved:i,onCart:a,showToast:o}){let{t:s}=c(),[l,u]=(0,J.useState)(!1),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(String(e.settings?.lead_time_days??0)),[v,y]=(0,J.useState)(String(e.settings?.safety_margin_value??14)),[x,S]=(0,J.useState)(e.settings?.safety_margin_unit??`days`);(0,J.useEffect)(()=>{f||_(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,f]),(0,J.useEffect)(()=>{m||(y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,m]);let C=d({mutationFn:r.upsertSkuSettings,onSuccess:()=>{i(),o(s(`forecast.settingsSaved`),`success`)},onError:()=>o(s(`forecast.failedSaveSettings`),`error`)}),D=e.settings?.alerts_snoozed??!1,O=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),ee=e.group.spools[0]?.rgba?Ke(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},k=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,te=D||e.daysRemaining===null?`text-bambu-gray`:e.stockBreakAlert?`text-red-700 dark:text-red-400`:e.reorderAlert||e.daysRemaining<30?`text-yellow-700 dark:text-yellow-400`:`text-green-700 dark:text-green-400`;function A(t,n,r,i=D){C.mutate({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,lead_time_days:t,safety_margin_value:n,safety_margin_unit:r,alerts_snoozed:i})}function j(t){t.stopPropagation(),A(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!D)}let M=e.rateTier===`history`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-green/15 text-bambu-green`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),s(`forecast.trend`)]}):e.rateTier===`delta`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-400/15 text-blue-700 dark:text-blue-400`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),s(`forecast.estimated`)]}):(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray/60`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),s(`forecast.noData`)]});return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${D?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${D?`opacity-50`:``}`,onClick:()=>u(e=>!e),children:[(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:ee})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:O})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,Y.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${k>50?`bg-bambu-green`:k>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(k,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),M]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm font-semibold ${te}`,children:e.daysRemaining===null?(0,Y.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?zt(e.projectedEmptyDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm ${!D&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,Y.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:s(`forecast.addToCart`),children:(0,Y.jsx)(tt,{className:`w-4 h-4`})}),!D&&(e.stockBreakAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":s(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":s(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,Y.jsx)(w,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,Y.jsx)(`button`,{onClick:j,className:`p-1 rounded transition-colors ${D?`text-amber-600/80 dark:text-amber-400/80 hover:text-amber-700 dark:hover:text-amber-300`:`text-slate-400 hover:text-white`}`,title:s(D?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,Y.jsx)(b,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:l?(0,Y.jsx)(E,{className:`w-4 h-4`}):(0,Y.jsx)(T,{className:`w-4 h-4`})})]})})]}),l&&(0,Y.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,Y.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,Y.jsx)(Zt,{label:s(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:s(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,Y.jsx)(Zt,{label:s(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:s(`forecast.reorderPointHint`)}),n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Qt,{label:s(`forecast.skuLeadTimeOverride`),hint:s(`forecast.skuLeadTimeHint`),unit:s(`forecast.leadTime`),editing:f,value:e.settings?.lead_time_days??0,inputValue:g,onInputChange:_,onEdit:()=>{_(String(e.settings?.lead_time_days??0)),p(!0)},onSave:()=>{let t=parseInt(g,10);!isNaN(t)&&t>=0&&(A(t,e.settings?.safety_margin_value??14,x),p(!1))},onCancel:()=>p(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`)}),(0,Y.jsx)($t,{value:e.settings?.safety_margin_value??14,unit:x,editing:m,inputValue:v,dailyRateG:e.dailyRateG,onInputChange:y,onUnitChange:e=>S(e),onEdit:()=>{y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`),h(!0)},onSave:()=>{let t=parseInt(v,10);!isNaN(t)&&t>=0&&(A(e.settings?.lead_time_days??0,t,x),h(!1))},onCancel:()=>h(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`),safetyMarginLabel:s(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:s(`forecast.individualSpools`)}),(0,Y.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.remaining`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.used`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.labelWeight`)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.group.spools.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used),n=e.label_weight>0?t/e.label_weight*100:0;return(0,Y.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function Zt({label:e,value:t,hint:n}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,Y.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function Qt({label:e,hint:t,unit:n,editing:r,value:i,inputValue:a,onInputChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,Y.jsx)(`span`,{title:t,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,Y.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function $t({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:l,onCancel:u,isPending:d,saveLabel:f=`Save`,cancelLabel:p=`Cancel`,safetyMarginLabel:m=`Safety Margin`}){let{t:h}=c(),g=t===`g`?e:i===null?null:Math.round(i*e),_=t===`days`?h(`forecast.safetyMarginHintDays`,{approx:g===null?``:h(`forecast.safetyMarginHintDaysApprox`,{g})}):h(`forecast.safetyMarginHintG`,{approx:i===null?``:h(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m}),(0,Y.jsx)(`span`,{title:_,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:t===`g`?1e4:365,value:r,onChange:e=>a(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:d}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`days`),className:`px-2 py-1 transition-colors ${t===`days`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`days`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`g`),className:`px-2 py-1 transition-colors ${t===`g`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`g`})]}),(0,Y.jsx)(`button`,{type:`submit`,disabled:d,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:f}),(0,Y.jsx)(`button`,{type:`button`,onClick:u,disabled:d,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:p})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),g!==null&&t===`days`&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,g,`g`]}),t===`g`&&i!==null&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function en({items:e,forecasts:t,globalLeadTime:n,canWrite:i,onClose:a,onRemove:o,onClear:s}){let{t:u}=c(),f=l(),[p,m]=(0,J.useState)(`list`),h=d({mutationFn:async({id:e,status:t,item:n,avgSpoolG:i})=>{if(await r.updateShoppingListStatus(e,t),t===`received`&&n){let t=i??1e3,a={material:n.material,subtype:n.subtype,brand:n.brand,label_weight:t,core_weight:0,core_weight_catalog_id:null,color_name:n.color_name,rgba:null,extra_colors:null,effect_type:null,nozzle_temp_min:null,nozzle_temp_max:null,note:n.note??null,tag_uid:null,tray_uuid:null,data_origin:`manual`,tag_type:null,cost_per_kg:null,last_scale_weight:null,last_weighed_at:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,added_full:null,last_used:null,encode_time:null,category:`Stock`,low_stock_threshold_pct:null,material_number:null};await r.bulkCreateSpools(a,n.quantity_spools),await r.removeFromShoppingList(e)}},onSuccess:()=>{f.invalidateQueries({queryKey:[`shopping-list`]}),f.invalidateQueries({queryKey:[`spools`]})}}),g=(0,J.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),_=(0,J.useMemo)(()=>e.map(e=>({item:e,forecast:g.get(X(e.material,e.subtype,e.brand,e.color_name))??null})),[e,g]),v=(0,J.useMemo)(()=>_.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[_]);function y(){let t=[u(`forecast.qty`),u(`forecast.material`),u(`inventory.brand`),u(`inventory.subtype`),u(`inventory.color`),`${u(`forecast.weight`)} (g)`,`${u(`forecast.leadTime`)} (d)`,u(`forecast.expectedRestock`),u(`forecast.status`),u(`forecast.note`)],r=e.map(e=>{let t=g.get(X(e.material,e.subtype,e.brand,e.color_name))??null,r=t&&t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,i=Math.round(e.quantity_spools*r),a=t?.effectiveLeadTimeDays??n??0,o=a>0?zt(Z(new Date,a)):``;return[e.quantity_spools,e.material,e.brand??``,e.subtype??``,e.color_name??``,i,a||``,o,e.status,e.note??``].map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`)}),i=[t.join(`,`),...r].join(`
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,n as i,r as a,t as o,v as s,w as c}from"./client-BdOyoZJz.js";import{n as l}from"./QueryClientProvider-Clbyr4Jg.js";import{t as u}from"./useQuery-CCy0EwsM.js";import{t as d}from"./useMutation-qh3Iyscy.js";import{t as f}from"./useQueries-C87lFrjE.js";import{t as p}from"./createLucideIcon-Yo2YoYjm.js";import{i as m,n as h,r as g}from"./haSensorDisplay-CSo8Nw_c.js";import{t as _}from"./arrow-down-C4OBNDqJ.js";import{t as v}from"./arrow-up-down-C-1Kkt1x.js";import{t as y}from"./arrow-up-Dam8cLfE.js";import{i as b,n as x,r as S,t as C}from"./ReferenceLine-l3CI8D5f.js";import{t as w}from"./check-D1Pn8T1J.js";import{a as T,i as E,n as D,t as O}from"./info-DcT0QU8O.js";import{n as ee,t as k}from"./chevrons-right-OnQ-9jKz.js";import{n as te,r as A}from"./ToastContext-VFOrCCoA.js";import{t as j}from"./columns-2-CGEUxYp_.js";import{t as M}from"./copy-3N5VKzXz.js";import{t as N}from"./layout-grid-D4S7CgZJ.js";import{t as P}from"./link-2-Bj1oMj3O.js";import{t as F}from"./loader-circle-CB4leTZa.js";import{t as ne}from"./lock-C288ZvMI.js";import{_ as I,c as L,g as re,h as R,s as ie,v as ae}from"./locationSensorDefaults-D85td_im.js";import{t as oe}from"./package-D9xR0eOt.js";import{t as se}from"./search-BpAJdxRw.js";import{t as z}from"./sparkles-AUof3WTI.js";import{L as ce,Rn as le,Xt as ue,c as de,p as fe,s as pe}from"./CartesianChart-DcboTNtX.js";import{t as B}from"./triangle-alert-gIik0G2C.js";import{t as me}from"./unlink-DJBJ04VB.js";import{t as he}from"./x-Dctff5l9.js";import{t as V}from"./Button-pwVKPiYn.js";import{r as ge,v as H,y as _e}from"./date-G9KUauqz.js";import{n as ve}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$t as ye,At as be,Cn as xe,Gt as Se,H as Ce,Jt as U,Kt as we,Ln as Te,Lt as Ee,Mn as De,On as Oe,Pt as ke,Rt as Ae,Tt as je,Ut as Me,Wn as Ne,Zt as Pe,_t as Fe,a as Ie,at as Le,bt as Re,cn as ze,en as Be,ft as Ve,i as He,jn as Ue,kn as We,kt as Ge,lt as Ke,o as qe,ot as Je,r as Ye,s as Xe,st as W,w as Ze,wn as Qe,xn as $e,yt as et,zt as tt}from"./index-ggB_TpPo.js";import{i as nt,r as rt}from"./slicerPrinterMatch-CUdoNag2.js";import{t as it}from"./ColumnConfigModal-D9ot5fd_.js";import{n as at,t as ot}from"./AreaChart-J0I0YlYN.js";import{a as st,i as ct,n as lt,o as ut,r as G,s as dt,t as ft}from"./AdditionalSection-CQLJ4IHC.js";import{_ as pt,a as K,b as mt,c as ht,d as gt,f as _t,g as vt,i as yt,l as bt,m as xt,n as St,o as Ct,r as wt,s as Tt,t as Et,u as Dt,v as Ot}from"./utils--AXHSbgQ.js";import{t as kt}from"./AssignToAmsModal-7j6MLCKH.js";import{t as At}from"./inventorySearch-CqDFyHRc.js";var q=p(`beaker`,[[`path`,{d:`M4.5 3h15`,key:`c7n0jr`}],[`path`,{d:`M6 3v16a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V3`,key:`m1uhx7`}],[`path`,{d:`M6 14h12`,key:`4cwo0f`}]]),jt=p(`chart-no-axes-column`,[[`path`,{d:`M5 21v-6`,key:`1hz6c0`}],[`path`,{d:`M12 21V3`,key:`1lcnhd`}],[`path`,{d:`M19 21V9`,key:`unv183`}]]),Mt=p(`credit-card`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`2`,key:`ynyp8z`}],[`line`,{x1:`2`,x2:`22`,y1:`10`,y2:`10`,key:`1b3vmo`}]]),Nt=p(`group`,[[`path`,{d:`M3 7V5c0-1.1.9-2 2-2h2`,key:`adw53z`}],[`path`,{d:`M17 3h2c1.1 0 2 .9 2 2v2`,key:`an4l38`}],[`path`,{d:`M21 17v2c0 1.1-.9 2-2 2h-2`,key:`144t0e`}],[`path`,{d:`M7 21H5c-1.1 0-2-.9-2-2v-2`,key:`rtnfgi`}],[`rect`,{width:`7`,height:`5`,x:`7`,y:`7`,rx:`1`,key:`1eyiv7`}],[`rect`,{width:`7`,height:`5`,x:`10`,y:`12`,rx:`1`,key:`1qlmkx`}]]),Pt=p(`package-check`,[[`path`,{d:`m16 16 2 2 4-4`,key:`gfu2re`}],[`path`,{d:`M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14`,key:`e7tb2h`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`12`,key:`a4e8g8`}]]),Ft=p(`store`,[[`path`,{d:`M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5`,key:`slp6dd`}],[`path`,{d:`M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244`,key:`o0xfot`}],[`path`,{d:`M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05`,key:`wn3emo`}]]),It=p(`table-properties`,[[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),J=e(n(),1),Y=t(),Lt=1.65,Rt=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function X(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function Z(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function zt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function Bt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Vt(e){if(e.length<2)return null;let t=new Map;for(let n of e){let e=n.created_at.slice(0,10);t.set(e,(t.get(e)??0)+n.weight_used)}if(t.size<2)return null;let n=[...t.entries()].map(([e,t])=>({ms:new Date(e).getTime(),totalG:t})).sort((e,t)=>e.ms-t.ms),r=Date.now(),i=Math.LN2/30,a=[];for(let e=1;ee+t.weight,0);if(o===0)return null;let s=a.reduce((e,t)=>e+t.rate*t.weight,0)/o,c=a.reduce((e,t)=>e+t.weight*(t.rate-s)**2,0)/o;return{rate:s,stdDev:Math.sqrt(c)}}function Ht(e){let t=e.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0);if(t===0)return null;let n=Date.now(),r=(n-e.reduce((e,t)=>{let n=new Date(t.created_at).getTime();return nr.getAllUsageHistory(5e3),staleTime:6e4,enabled:s}),{data:M=[]}=u({queryKey:[`shopping-list`],queryFn:r.getShoppingList,staleTime:3e4,enabled:s}),N=k?.forecast_global_lead_time_days??0,P=(0,J.useMemo)(()=>{let e=new Map;for(let t of A)e.set(X(t.material,t.subtype,t.brand,t.color_name),t);return e},[A]),F=(0,J.useMemo)(()=>{let e=new Map;for(let t of j){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[j]),I=(0,J.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=X(n.material,n.subtype,n.brand,n.color_name),r=t.get(e)??{key:e,material:n.material,subtype:n.subtype,brand:n.brand,colorName:n.color_name,spools:[]};r.spools.push(n),t.set(e,r)}return[...t.values()]},[e]),L=(0,J.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),I.map(t=>{let n=P.get(t.key)??(t.colorName===null?null:P.get(X(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(N,r),a=n?.safety_margin_value??14,o=n?.safety_margin_unit??`days`,s=t.spools.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),c=t.spools.reduce((e,t)=>e+t.label_weight,0),l=t.spools.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0),u=[];for(let e of t.spools)(e.weight_used_baseline??0)===0&&u.push(...F.get(e.id)??[]);let d=null,f=null,p=`none`,m=Vt(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=Ht(t.spools);e!==null&&(d=e,p=`delta`)}let h=Lt*(f??(d===null?0:d*.2))*Math.sqrt(i)+(o===`g`?a:d===null?a*5:d*a),g=d===null?0:d*i+h,_=d&&d>0?Math.floor(s/d):null,v=_===null?null:Z(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:Z(e,Math.max(0,y)),x=_!==null&&i>0&&_<=i,S=!x&&y!==null&&y<=0;return{group:t,settings:n,totalRemainingG:s,totalLabelG:c,totalSpools:t.spools.length,totalUsedG:l,dailyRateG:d,dailyRateStdDev:f,rateTier:p,effectiveLeadTimeDays:i,safetyStockG:h,reorderPointG:g,daysRemaining:_,daysUntilROP:y,projectedEmptyDate:v,reorderTriggerDate:b,reorderAlert:S,stockBreakAlert:x}})},[I,P,F,N]),re=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.material))].sort(),[I]),R=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.brand).filter(Boolean))].sort(),[I]),ie=(0,J.useMemo)(()=>{let e=[...L];return v&&(e=e.filter(e=>e.group.material===v)),b&&(e=e.filter(e=>e.group.brand===b)),e.sort((e,t)=>{let n=0,r=0;switch(m){case`material`:n=[e.group.material,e.group.subtype??``,e.group.brand??``].join(` `).toLowerCase(),r=[t.group.material,t.group.subtype??``,t.group.brand??``].join(` `).toLowerCase();break;case`used`:n=e.totalUsedG,r=t.totalUsedG;break;case`days_left`:n=e.daysRemaining??999999,r=t.daysRemaining??999999;break;case`stock`:n=e.totalRemainingG,r=t.totalRemainingG;break}let i=nr);return g===`asc`?i:-i}),e},[L,m,g,v,b]),ae=(0,J.useMemo)(()=>L.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[L]),oe=(0,J.useMemo)(()=>[...L].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[L]);if(!s)return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,Y.jsx)(ne,{className:`w-8 h-8 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noReadAccess`)})]});function se(e){m===e?_(e=>e===`asc`?`desc`:`asc`):(h(e),_(e===`days_left`?`asc`:`desc`))}let z=M.length>0?M.length:null;return(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[ae.length>0&&(0,Y.jsxs)(`button`,{onClick:()=>p(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${ae.some(e=>e.stockBreakAlert)?`bg-red-100 dark:bg-red-500/15 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300 hover:bg-red-200 dark:hover:bg-red-500/25`:`bg-yellow-100 dark:bg-yellow-500/15 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300 hover:bg-yellow-200 dark:hover:bg-yellow-500/25`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),i(`forecast.alertCount`,{count:ae.length}),f?(0,Y.jsx)(E,{className:`w-3.5 h-3.5`}):(0,Y.jsx)(T,{className:`w-3.5 h-3.5`})]}),d&&(0,Y.jsx)(Yt,{value:N,onSave:e=>{r.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(i(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,Y.jsxs)(`select`,{value:v,onChange:e=>y(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${v?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.material`)}),re.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${b?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.brand`)}),R.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`button`,{onClick:()=>D(e=>!e),className:`relative flex items-center gap-2 px-3 py-1.5 rounded-lg border border-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary text-sm transition-colors ml-auto`,children:[(0,Y.jsx)(tt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:i(`forecast.shoppingList`)}),z&&(0,Y.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-bambu-green text-white text-[10px] font-bold flex items-center justify-center`,children:z})]})]}),f&&ae.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2`,children:ae.map(e=>(0,Y.jsx)(Kt,{forecast:e,onCart:()=>C(e)},e.group.key))}),w&&(0,Y.jsx)(en,{items:M,forecasts:L,globalLeadTime:N,canWrite:d,onClose:()=>D(!1),onRemove:e=>{r.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))},onClear:()=>{r.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))}}),oe.length>0&&(0,Y.jsx)(Jt,{forecasts:oe,days:O,onDaysChange:ee}),L.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,Y.jsx)(le,{className:`w-10 h-10 mb-3 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noSpools`)})]}):(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,Y.jsx)(Gt,{col:`material`,active:m,dir:g,onSort:se,children:i(`forecast.sku`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`locations.spools`)}),(0,Y.jsx)(Gt,{col:`stock`,active:m,dir:g,onSort:se,children:i(`forecast.stock`)}),(0,Y.jsx)(Gt,{col:`used`,active:m,dir:g,onSort:se,children:i(`forecast.dailyRate`)}),(0,Y.jsx)(Gt,{col:`days_left`,active:m,dir:g,onSort:se,children:i(`forecast.daysLeft`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.emptyBy`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.reorderBy`)}),(0,Y.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:ie.map(e=>(0,Y.jsx)(Xt,{forecast:e,globalLeadTime:N,canWrite:d,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>C(e),showToast:n},e.group.key))})]})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-3 text-xs text-bambu-gray border-t border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),i(`forecast.trendLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),i(`forecast.estimatedLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),i(`forecast.noDataLegend`)]})]})]}),S&&(0,Y.jsx)(nn,{forecast:S,onClose:()=>C(null),onAdd:e=>{r.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(i(`forecast.addedToCart`),`success`),C(null),D(!0)}).catch(()=>n(i(`forecast.failedAddItem`),`error`))}})]})}function Gt({col:e,active:t,dir:n,onSort:r,children:i}){return(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide cursor-pointer select-none hover:text-white transition-colors`,onClick:()=>r(e),children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,Y.jsx)(y,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(_,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(v,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function Kt({forecast:e,onCart:t}){let{t:n}=c(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${i?`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`:`bg-yellow-50 dark:bg-yellow-500/10 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})]})]}),(0,Y.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 px-2.5 py-1 rounded border border-current text-xs opacity-70 hover:opacity-100 transition-opacity`,children:[(0,Y.jsx)(tt,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var qt=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function Jt({forecasts:e,days:t,onDaysChange:n}){let{t:r}=c(),i=Array.from({length:t+1},(e,t)=>t),a=e.map((e,n)=>({key:e.group.key,label:[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),color:Rt[n%Rt.length],rop:e.reorderPointG,points:Ut(e,t)})),o=i.map(e=>{let t={day:e,label:Bt(Z(new Date,e))};for(let n of a){let r=n.points.find(t=>t.day===e);t[n.key]=r?.stock??0}return t}),s=(()=>{for(let e=t;e>=0;e--)if(a.some(t=>o[e]?.[t.key]>0))return e;return t})(),l=o.slice(0,s+1),u=a.filter(e=>e.rop>0);return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsx)(le,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:qt.map(e=>(0,Y.jsx)(`button`,{onClick:()=>n(e.value),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${t===e.value?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:e.label},e.value))})]}),(0,Y.jsx)(ue,{width:`100%`,height:220,children:(0,Y.jsxs)(ot,{data:l,margin:{top:4,right:8,bottom:0,left:0},children:[(0,Y.jsx)(`defs`,{children:a.map(e=>(0,Y.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Y.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,Y.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,Y.jsx)(fe,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,Y.jsx)(de,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,Y.jsx)(pe,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,Y.jsx)(ce,{content:({label:e,payload:t})=>t?.length?(0,Y.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,Y.jsx)(`div`,{style:{color:`#9CA3AF`,marginBottom:6},children:e}),t.map(e=>{let t=a.find(t=>t.key===String(e.dataKey));return typeof e.value==`number`?(0,Y.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,Y.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,Y.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,Y.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,Y.jsx)(x,{formatter:e=>(0,Y.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,Y.jsx)(at,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),u.map(e=>(0,Y.jsx)(C,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function Yt({value:e,onSave:t}){let{t:n}=c(),[r,i]=(0,J.useState)(!1),[a,o]=(0,J.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-tertiary/40 rounded-lg border border-bambu-dark-tertiary text-xs text-bambu-gray`,children:[(0,Y.jsx)(O,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,Y.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-14 px-1.5 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,Y.jsx)(`button`,{type:`submit`,className:`px-2 py-0.5 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80`,children:n(`forecast.save`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,Y.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function Xt({forecast:e,globalLeadTime:t,canWrite:n,onSaved:i,onCart:a,showToast:o}){let{t:s}=c(),[l,u]=(0,J.useState)(!1),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(String(e.settings?.lead_time_days??0)),[v,y]=(0,J.useState)(String(e.settings?.safety_margin_value??14)),[x,S]=(0,J.useState)(e.settings?.safety_margin_unit??`days`);(0,J.useEffect)(()=>{f||_(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,f]),(0,J.useEffect)(()=>{m||(y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,m]);let C=d({mutationFn:r.upsertSkuSettings,onSuccess:()=>{i(),o(s(`forecast.settingsSaved`),`success`)},onError:()=>o(s(`forecast.failedSaveSettings`),`error`)}),D=e.settings?.alerts_snoozed??!1,O=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),ee=e.group.spools[0]?.rgba?Ke(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},k=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,te=D||e.daysRemaining===null?`text-bambu-gray`:e.stockBreakAlert?`text-red-700 dark:text-red-400`:e.reorderAlert||e.daysRemaining<30?`text-yellow-700 dark:text-yellow-400`:`text-green-700 dark:text-green-400`;function A(t,n,r,i=D){C.mutate({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,lead_time_days:t,safety_margin_value:n,safety_margin_unit:r,alerts_snoozed:i})}function j(t){t.stopPropagation(),A(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!D)}let M=e.rateTier===`history`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-green/15 text-bambu-green`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),s(`forecast.trend`)]}):e.rateTier===`delta`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-400/15 text-blue-700 dark:text-blue-400`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),s(`forecast.estimated`)]}):(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray/60`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),s(`forecast.noData`)]});return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${D?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${D?`opacity-50`:``}`,onClick:()=>u(e=>!e),children:[(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:ee})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:O})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,Y.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${k>50?`bg-bambu-green`:k>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(k,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),M]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm font-semibold ${te}`,children:e.daysRemaining===null?(0,Y.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?zt(e.projectedEmptyDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm ${!D&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,Y.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:s(`forecast.addToCart`),children:(0,Y.jsx)(tt,{className:`w-4 h-4`})}),!D&&(e.stockBreakAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":s(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":s(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,Y.jsx)(w,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,Y.jsx)(`button`,{onClick:j,className:`p-1 rounded transition-colors ${D?`text-amber-600/80 dark:text-amber-400/80 hover:text-amber-700 dark:hover:text-amber-300`:`text-slate-400 hover:text-white`}`,title:s(D?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,Y.jsx)(b,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:l?(0,Y.jsx)(E,{className:`w-4 h-4`}):(0,Y.jsx)(T,{className:`w-4 h-4`})})]})})]}),l&&(0,Y.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,Y.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,Y.jsx)(Zt,{label:s(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:s(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,Y.jsx)(Zt,{label:s(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:s(`forecast.reorderPointHint`)}),n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Qt,{label:s(`forecast.skuLeadTimeOverride`),hint:s(`forecast.skuLeadTimeHint`),unit:s(`forecast.leadTime`),editing:f,value:e.settings?.lead_time_days??0,inputValue:g,onInputChange:_,onEdit:()=>{_(String(e.settings?.lead_time_days??0)),p(!0)},onSave:()=>{let t=parseInt(g,10);!isNaN(t)&&t>=0&&(A(t,e.settings?.safety_margin_value??14,x),p(!1))},onCancel:()=>p(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`)}),(0,Y.jsx)($t,{value:e.settings?.safety_margin_value??14,unit:x,editing:m,inputValue:v,dailyRateG:e.dailyRateG,onInputChange:y,onUnitChange:e=>S(e),onEdit:()=>{y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`),h(!0)},onSave:()=>{let t=parseInt(v,10);!isNaN(t)&&t>=0&&(A(e.settings?.lead_time_days??0,t,x),h(!1))},onCancel:()=>h(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`),safetyMarginLabel:s(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:s(`forecast.individualSpools`)}),(0,Y.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.remaining`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.used`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.labelWeight`)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.group.spools.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used),n=e.label_weight>0?t/e.label_weight*100:0;return(0,Y.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function Zt({label:e,value:t,hint:n}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,Y.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function Qt({label:e,hint:t,unit:n,editing:r,value:i,inputValue:a,onInputChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,Y.jsx)(`span`,{title:t,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,Y.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function $t({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:l,onCancel:u,isPending:d,saveLabel:f=`Save`,cancelLabel:p=`Cancel`,safetyMarginLabel:m=`Safety Margin`}){let{t:h}=c(),g=t===`g`?e:i===null?null:Math.round(i*e),_=t===`days`?h(`forecast.safetyMarginHintDays`,{approx:g===null?``:h(`forecast.safetyMarginHintDaysApprox`,{g})}):h(`forecast.safetyMarginHintG`,{approx:i===null?``:h(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m}),(0,Y.jsx)(`span`,{title:_,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:t===`g`?1e4:365,value:r,onChange:e=>a(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:d}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`days`),className:`px-2 py-1 transition-colors ${t===`days`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`days`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`g`),className:`px-2 py-1 transition-colors ${t===`g`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`g`})]}),(0,Y.jsx)(`button`,{type:`submit`,disabled:d,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:f}),(0,Y.jsx)(`button`,{type:`button`,onClick:u,disabled:d,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:p})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),g!==null&&t===`days`&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,g,`g`]}),t===`g`&&i!==null&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function en({items:e,forecasts:t,globalLeadTime:n,canWrite:i,onClose:a,onRemove:o,onClear:s}){let{t:u}=c(),f=l(),[p,m]=(0,J.useState)(`list`),h=d({mutationFn:async({id:e,status:t,item:n,avgSpoolG:i})=>{if(await r.updateShoppingListStatus(e,t),t===`received`&&n){let t=i??1e3,a={material:n.material,subtype:n.subtype,brand:n.brand,label_weight:t,core_weight:0,core_weight_catalog_id:null,color_name:n.color_name,rgba:null,extra_colors:null,effect_type:null,nozzle_temp_min:null,nozzle_temp_max:null,note:n.note??null,tag_uid:null,tray_uuid:null,data_origin:`manual`,tag_type:null,cost_per_kg:null,last_scale_weight:null,last_weighed_at:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,added_full:null,last_used:null,encode_time:null,category:`Stock`,low_stock_threshold_pct:null,material_number:null};await r.bulkCreateSpools(a,n.quantity_spools),await r.removeFromShoppingList(e)}},onSuccess:()=>{f.invalidateQueries({queryKey:[`shopping-list`]}),f.invalidateQueries({queryKey:[`spools`]})}}),g=(0,J.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),_=(0,J.useMemo)(()=>e.map(e=>({item:e,forecast:g.get(X(e.material,e.subtype,e.brand,e.color_name))??null})),[e,g]),v=(0,J.useMemo)(()=>_.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[_]);function y(){let t=[u(`forecast.qty`),u(`forecast.material`),u(`inventory.brand`),u(`inventory.subtype`),u(`inventory.color`),`${u(`forecast.weight`)} (g)`,`${u(`forecast.leadTime`)} (d)`,u(`forecast.expectedRestock`),u(`forecast.status`),u(`forecast.note`)],r=e.map(e=>{let t=g.get(X(e.material,e.subtype,e.brand,e.color_name))??null,r=t&&t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,i=Math.round(e.quantity_spools*r),a=t?.effectiveLeadTimeDays??n??0,o=a>0?zt(Z(new Date,a)):``;return[e.quantity_spools,e.material,e.brand??``,e.subtype??``,e.color_name??``,i,a||``,o,e.status,e.note??``].map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`)}),i=[t.join(`,`),...r].join(`
`),a=new Blob([i],{type:`text/csv`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`shopping-list-${new Date().toISOString().slice(0,10)}.csv`,s.click(),setTimeout(()=>URL.revokeObjectURL(o),100)}return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(tt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:u(`forecast.shoppingList`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:u(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,Y.jsxs)(`button`,{onClick:()=>m(`list`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${p===`list`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(oe,{className:`w-3 h-3`}),u(`forecast.listView`)]}),(0,Y.jsxs)(`button`,{onClick:()=>m(`logistics`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${p===`logistics`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(jt,{className:`w-3 h-3`}),u(`forecast.logisticsView`),v.length>0&&(0,Y.jsx)(`span`,{className:`w-3.5 h-3.5 rounded-full bg-red-500 text-white text-[9px] font-bold flex items-center justify-center`,children:v.length})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`button`,{onClick:y,className:`flex items-center gap-1.5 text-xs text-bambu-gray hover:text-white transition-colors px-2 py-1 rounded border border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`,children:[(0,Y.jsx)(Qe,{className:`w-3 h-3`}),u(`forecast.downloadCsv`)]}),i&&(0,Y.jsx)(`button`,{onClick:s,className:`text-xs text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors px-2 py-1 rounded border border-red-200 dark:border-red-500/20 hover:bg-red-50 dark:hover:bg-red-500/10`,children:u(`forecast.clearAll`)})]}),(0,Y.jsx)(`button`,{onClick:a,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]})]}),e.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(oe,{className:`w-8 h-8 mb-2 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:u(`forecast.shoppingListEmpty`)})]}):p===`list`?(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.qty`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.material`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.weight`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.leadTime`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.expectedRestock`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.status`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.note`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.actions`)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.map(e=>{let t=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),r=v.some(t=>t.item.id===e.id),a=g.get(X(e.material,e.subtype,e.brand,e.color_name))??null,s=a&&a.totalSpools>0?a.totalLabelG/a.totalSpools:1e3,c=Math.round(e.quantity_spools*s),l=a?.effectiveLeadTimeDays??n??0,d=l>0?Z(new Date,l):null,f=e.status===`purchased`||e.status===`received`,p=e.status===`received`,m=h.isPending;return(0,Y.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${r&&!f?`bg-red-500/5`:``}`,children:[(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:t}),r&&!f&&(0,Y.jsx)(B,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400 flex-shrink-0`,"aria-label":u(`forecast.stockBreakBefore`)})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:c>=1e3?`${(c/1e3).toFixed(1)}kg`:`${c}g`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l>0?`${l}d`:`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:d?zt(d):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${p?`bg-bambu-green/20 text-bambu-green`:f?`bg-blue-100 dark:bg-blue-400/20 text-blue-700 dark:text-blue-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:u(p?`forecast.received`:f?`forecast.purchased`:`forecast.pending`)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:i&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>h.mutate({id:e.id,status:f?`pending`:`purchased`}),disabled:m||p,title:u(f?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1.5 rounded transition-colors disabled:opacity-30 ${f?`text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300`:`text-blue-600/50 dark:text-blue-400/50 hover:text-blue-600 dark:hover:text-blue-400`}`,children:f?(0,Y.jsx)(Se,{className:`w-4 h-4`}):(0,Y.jsx)(Mt,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>h.mutate({id:e.id,status:`received`,item:e,avgSpoolG:s}),disabled:m||!f||p,title:u(`forecast.markReceived`),className:`p-1.5 rounded transition-colors text-bambu-green/50 hover:text-bambu-green disabled:opacity-30`,children:(0,Y.jsx)(Pt,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>o(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:u(`forecast.remove`),children:(0,Y.jsx)(be,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,Y.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:_.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,Y.jsx)(tn,{item:e,forecast:t,globalLeadTime:n,canWrite:i,onRemove:()=>o(e.id)},e.id))})]})}function tn({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=c(),o=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),s=(0,J.useMemo)(()=>{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let n=t.dailyRateG,r=t.effectiveLeadTimeDays,i=t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,a=e.quantity_spools*i,o=Math.max(0,t.totalRemainingG-n*r),s=o+a,c=Math.ceil(s/n),l=Math.min(r+c+5,365),u=[];for(let e=0;e<=l;e++){let i=Bt(Z(new Date,e));if(e===r)u.push({day:e,label:i,stock:Math.round(o),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG)}),u.push({day:e,label:i,stock:Math.round(s),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG),arrival:!0});else{let a=e{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let e=Math.floor(t.totalRemainingG/t.dailyRateG);return ee>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:44}),(0,Y.jsx)(ce,{contentStyle:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:11},labelStyle:{color:`#9CA3AF`},formatter:(e,t)=>typeof e==`number`?t===`stock`?`${e}g — ${a(`forecast.stock`)}`:t===`rop`?`${e}g — ${a(`forecast.reorderPoint`)}`:t===`safetyStock`?`${e}g — ${a(`forecast.safetyMarginLabel`)}`:`${e}`:``}),(0,Y.jsx)(at,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,Y.jsx)(C,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,Y.jsx)(C,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,Y.jsx)(C,{x:Bt(Z(new Date,s.lt)),stroke:`#3B82F6`,strokeWidth:1.5,strokeDasharray:`4 3`,strokeOpacity:.9,label:{value:`+${s.arrivalG>=1e3?`${(s.arrivalG/1e3).toFixed(1)}kg`:`${Math.round(s.arrivalG)}g`} arrives (d${s.lt})`,position:`insideTopLeft`,fill:`#3B82F6`,fontSize:9}}),l!==null&&(0,Y.jsx)(C,{x:Bt(Z(new Date,l)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),u&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function nn({forecast:e,onClose:t,onAdd:n}){let{t:r}=c(),i=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),[a,o]=(0,J.useState)(`qty`),[s,l]=(0,J.useState)(`1`),[u,d]=(0,J.useState)(`30`),[f,p]=(0,J.useState)(``),m=(0,J.useMemo)(()=>{if(!e.dailyRateG||e.dailyRateG<=0)return null;let t=e.dailyRateG*Number(u),n=e.group.spools.length>0?e.group.spools.reduce((e,t)=>e+t.label_weight,0)/e.group.spools.length:1e3;return Math.ceil(t/n)},[e,u]),h=a===`qty`?parseInt(s,10)||1:m??1;function g(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,quantity_spools:h,note:f||null})}return(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(tt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:g,className:`p-5 space-y-4`,children:[(0,Y.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`qty`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`qty`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byQuantity`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`duration`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`duration`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byDuration`)})]}),a===`qty`?(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:99,value:s,onChange:e=>l(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:365,value:u,onChange:e=>d(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}),e.dailyRateG===null?(0,Y.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:m??0})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,Y.jsx)(`input`,{type:`text`,maxLength:200,value:f,onChange:e=>p(e.target.value),placeholder:r(`forecast.notePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/40 focus:outline-none focus:border-bambu-green`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,Y.jsx)(`button`,{type:`submit`,className:`flex-1 py-2 bg-bambu-green text-white text-sm font-medium rounded-lg hover:bg-bambu-green/80 transition-colors`,children:r(`forecast.addNSpools`,{count:h})}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 text-sm text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded-lg transition-colors`,children:r(`forecast.cancel`)})]})]})]})})}function rn({links:e,onChange:t,currencySymbol:n}){let{t:i}=c(),{showToast:a}=te(),s=l(),d=(0,J.useRef)(null),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(!1),{data:v=[],isLoading:y,isError:b}=u({queryKey:Xe,queryFn:r.getSuppliers});(0,J.useEffect)(()=>{if(!f)return;let e=e=>{d.current&&!d.current.contains(e.target)&&(p(!1),h(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]);let x=(0,J.useMemo)(()=>new Set(e.map(e=>e.supplier_id)),[e]),S=(0,J.useMemo)(()=>v.filter(e=>!x.has(e.id)).filter(e=>e.name.toLowerCase().includes(m.trim().toLowerCase())),[v,x,m]),C=v.some(e=>e.name.toLowerCase()===m.trim().toLowerCase()),w=n=>{t([...e,{supplier_id:n.id,supplier_name:n.name,supplier_article_number:``,quoted_price_per_kg:null,is_purchase_source:!1}]),p(!1),h(``)},E=async()=>{let e=m.trim();if(e){_(!0);try{let t=await r.createSupplier({name:e});await He(s),w(t)}catch(e){console.error(`SupplierSection.createAndAdd failed:`,e),a(i(e instanceof o&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.createFailed`),`error`)}finally{_(!1)}}},D=(n,r)=>{t(e.map(e=>e.supplier_id===n?{...e,...r}:r.is_purchase_source?{...e,is_purchase_source:!1}:e))},O=n=>{t(e.filter(e=>e.supplier_id!==n))};return(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.suppliers.label`)}),e.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2 mb-2`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/10 text-bambu-green`,children:[(0,Y.jsx)(Ft,{className:`w-3 h-3`}),e.supplier_name]}),(0,Y.jsxs)(`label`,{className:`ml-auto flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer`,title:i(`inventory.suppliers.purchaseSourceHelp`),children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`w-3.5 h-3.5 accent-bambu-green`,checked:e.is_purchase_source,onChange:t=>D(e.supplier_id,{is_purchase_source:t.target.checked})}),i(`inventory.suppliers.purchaseSource`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>O(e.supplier_id),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,"aria-label":i(`common.remove`),children:(0,Y.jsx)(he,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`flex-1 min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:i(`inventory.suppliers.articleNumberPlaceholder`),value:e.supplier_article_number,maxLength:100,onChange:t=>D(e.supplier_id,{supplier_article_number:t.target.value})}),(0,Y.jsxs)(`div`,{className:`relative w-28`,children:[(0,Y.jsx)(`span`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:n}),(0,Y.jsx)(`input`,{type:`number`,className:`w-full pl-6 pr-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs text-right placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:i(`inventory.suppliers.pricePlaceholder`),title:i(`inventory.suppliers.priceHelp`),min:0,step:.01,value:e.quoted_price_per_kg??``,onChange:t=>D(e.supplier_id,{quoted_price_per_kg:t.target.value===``?null:parseFloat(t.target.value)})})]})]})]},e.supplier_id))}),(0,Y.jsxs)(`div`,{className:`relative`,ref:d,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-bambu-gray hover:text-white flex items-center justify-between transition-colors focus:outline-none focus:border-bambu-green`,children:[(0,Y.jsx)(`span`,{children:i(`inventory.suppliers.addSupplier`)}),(0,Y.jsx)(T,{className:`w-4 h-4 transition-transform ${f?`rotate-180`:``}`})]}),f&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,Y.jsx)(`input`,{type:`text`,autoFocus:!0,className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:i(`inventory.suppliers.searchPlaceholder`),value:m,onChange:e=>h(e.target.value)})}),(0,Y.jsx)(`div`,{className:`max-h-48 overflow-y-auto py-1`,children:y?(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),i(`common.loading`)]}):b?(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-sm text-red-400 flex items-center gap-2`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),i(`inventory.suppliers.loadFailed`)]}):(0,Y.jsxs)(Y.Fragment,{children:[S.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>w(e),className:`w-full px-3 py-2 text-left text-sm text-white hover:bg-bambu-dark-tertiary`,children:e.name},e.id)),S.length===0&&!m.trim()&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:i(`inventory.suppliers.noneLeft`)}),m.trim()&&!C&&(0,Y.jsxs)(`button`,{type:`button`,onClick:E,disabled:g,className:`w-full px-3 py-2 text-left text-sm text-bambu-green hover:bg-bambu-dark-tertiary flex items-center gap-1.5`,children:[g?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Pe,{className:`w-4 h-4`}),i(`inventory.suppliers.createNew`,{name:m.trim()})]})]})})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`inventory.suppliers.help`)})]})}function an({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=c(),[a,o]=(0,J.useState)(!1),[s,l]=(0,J.useState)(``),u=(0,J.useRef)(null),d=(0,J.useRef)(null),f=(0,J.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,J.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&(o(!1),l(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let p=(0,J.useMemo)(()=>{let t=s.toLowerCase().trim();return t?e.filter(e=>e.name.toLowerCase().includes(t)||(e.material?.toLowerCase().includes(t)??!1)||(e.vendor?.name.toLowerCase().includes(t)??!1)||(e.color_name?.toLowerCase().includes(t)??!1)):e},[e,s]);(0,J.useEffect)(()=>{a&&d.current?.focus()},[a]);let m=()=>{o(!0),l(``)},h=e=>{r(e),o(!1),l(``)};return(0,Y.jsxs)(`div`,{ref:u,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:m,className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-left focus:outline-none focus:border-bambu-green hover:border-bambu-gray transition-colors`,children:[t?(0,Y.jsx)(F,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):f?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Ke(f.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,Y.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[f.vendor?.name?`${f.vendor.name} — `:``,f.name]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(oe,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,Y.jsx)(T,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,Y.jsx)(`input`,{ref:d,type:`text`,value:s,onChange:e=>l(e.target.value),placeholder:i(`inventory.pickFromSpoolmanCatalog`),className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,Y.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,Y.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):p.length===0?(0,Y.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):p.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>h(e),className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors ${e.id===n?`bg-bambu-dark-tertiary`:``}`,children:[(0,Y.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Ke(e.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,Y.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,Y.jsxs)(`span`,{className:`block text-bambu-gray text-xs truncate`,children:[[e.material,e.color_name].filter(Boolean).join(` · `),e.weight?` · ${e.weight}g`:``]})]})]})},e.id))})]})]})}function on(e){let t=(e??``).trim().toUpperCase().slice(0,2);return t===`HH`||t===`HS`?t:null}function sn(e){return e?e===`HH`?`HF`:`S`:null}function cn(e,t){let n=e.nozzles??[];return on(n[(e.printer.nozzle_count??1)>1&&t>0?t:0]?.nozzle_type)??on(n[0]?.nozzle_type)}function ln(e){let t=new Set;for(let n of e.nozzles??[]){let e=(n?.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}for(let n of e.calibrations){let e=(n.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}return Array.from(t).sort((e,t)=>parseFloat(e)-parseFloat(t))}function un(e,t){return(e.printer.nozzle_count??1)>1?[{extruder:1,label:t.left},{extruder:0,label:t.right}]:[{extruder:0,label:t.single}]}function dn({formData:e,printersWithCalibrations:t,filamentOptions:n,modelPresets:r,setModelPresets:i,selectedProfiles:a,setSelectedProfiles:o,selectedGroupId:s,setSelectedGroupId:l,printerModels:u,isLoading:d=!1}){let{t:f}=c(),p=(0,J.useMemo)(()=>{let e=new Map,n=[];for(let r of t){let t=(r.printer.model||``).trim();if(!t){n.push(r);continue}let i=e.get(t);i?i.push(r):e.set(t,[r])}return[...Array.from(e.entries()).map(([e,t])=>({id:`m:${e}`,model:e,printers:t,diameters:Array.from(new Set([...mt,...t.flatMap(ln)])).sort((e,t)=>parseFloat(e)-parseFloat(t))})).sort((e,t)=>e.model.localeCompare(t.model)),...n.map(e=>({id:`p:${e.printer.id}`,model:``,printers:[e],diameters:Array.from(new Set([...mt,...ln(e)])).sort((e,t)=>parseFloat(e)-parseFloat(t))}))]},[t]),m=p.find(e=>e.id===s)??p[0],h=(0,J.useMemo)(()=>{let e=new Map;return(t,r)=>{if(!t)return n;let i=e.get(t);if(i||(i=n.filter(e=>{let n=rt(e.name,u??{});return!n||nt(n,t)}),e.set(t,i)),r&&!i.some(e=>e.code===r)){let e=n.find(e=>e.code===r);if(e)return[e,...i]}return i}},[n,u]),g=[e.brand,e.material,e.subtype].map(e=>e.trim()).filter(Boolean).join(` `),_=/^[0-9A-Fa-f]{6,8}$/.test(e.rgba)?`#${e.rgba.slice(0,6)}`:`var(--bambu-gray, #808080)`,v=e=>un(e,{left:f(`inventory.leftNozzle`),right:f(`inventory.rightNozzle`),single:f(`inventory.nozzle`)}),y=t=>t.printer.connected?t.calibrations.filter(t=>Ct(t,e)):[],b=e=>{let t=0;for(let n of e.printers){let r=y(n);for(let i of v(n))for(let o of e.diameters)r.some(e=>(e.extruder_id??0)===i.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===o)&&(a.get(K(n.printer.id,i.extruder,o))||t++)}return t},x=(e,t,n)=>{i(r=>{let i=new Map(r),a=gt(e,t);return n?i.set(a,{code:n.code,name:n.name}):i.delete(a),i})},S=(e,t,n,r)=>{o(i=>{let a=new Map(i),o=K(e,t,n);return r?a.set(o,r):a.delete(o),a})},C=()=>{let t=n.find(t=>t.code===e.slicer_filament);if(!t)return;let r=t.name.split(`@`)[0].trim().toLowerCase();r&&i(e=>{let t=new Map(e);for(let e of p){if(!e.model)continue;let n=h(e.model,void 0).filter(e=>e.name.toLowerCase().startsWith(r)&&rt(e.name,u??{})!==null);if(n.length!==0)for(let r of e.diameters){let i=n.find(e=>RegExp(`\\b${r.replace(`.`,`\\.`)}\\s*nozzle\\b`,`i`).test(e.name)),a=n.find(e=>!/\b[\d.]+\s*nozzle\b/i.test(e.name)),o=i??a;o&&t.set(gt(e.model,r),{code:o.code,name:o.name})}}return t})};if(t.length===0)return(0,Y.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,Y.jsxs)(`p`,{className:`text-bambu-gray flex items-center justify-center gap-2`,children:[d&&(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),f(d?`common.loading`:`inventory.noPrintersConfigured`)]})});let T=(e,t,n)=>{let i=gt(e,t),a=r.get(i),o=h(e,a?.code);return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Y.jsx)(ct,{ariaLabel:`${e} ${t}mm ${f(`inventory.filamentPreset`)}`,value:a?.code??``,options:o,inheritLabel:n,disabled:!e,onChange:n=>x(e,t,n)})}),(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-1 rounded-full shrink-0 ${a?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:f(a?`inventory.presetOverride`:`inventory.presetInherited`)})]})};return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(g||e.color_name)&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`w-5 h-5 rounded-full border border-white/15 shrink-0`,style:{background:_},"aria-hidden":`true`}),g&&(0,Y.jsx)(`span`,{className:`text-sm text-white truncate`,children:g}),e.color_name&&(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray truncate`,children:e.color_name})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-4`,children:[(0,Y.jsx)(`div`,{role:`tablist`,"aria-label":f(`inventory.printersTab`),"aria-orientation":`vertical`,className:`md:w-52 md:shrink-0 md:self-start md:sticky md:top-0 flex md:flex-col gap-1.5 overflow-x-auto md:overflow-x-visible`,children:p.map(e=>{let t=e===m,n=b(e);return(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,onClick:()=>l(e.id),"aria-selected":t,className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-left transition-colors shrink-0 md:shrink ${t?`bg-bambu-green/10 border-bambu-green/40 text-white`:`bg-transparent border-transparent text-bambu-gray hover:bg-bambu-dark hover:text-white`}`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold truncate`,children:e.model||f(`inventory.unknownModel`)}),(0,Y.jsx)(`div`,{className:`text-[11px] text-bambu-gray`,children:e.printers.length===1?f(`inventory.onePrinter`):f(`inventory.nPrinters`,{n:e.printers.length})})]}),n>0?(0,Y.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray shrink-0`,children:n}):(0,Y.jsx)(w,{className:`w-3.5 h-3.5 text-bambu-green shrink-0`})]},e.id)})}),(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:m&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h4`,{className:`text-base font-semibold text-white truncate`,children:m.model||f(`inventory.unknownModel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m.printers.map(e=>e.printer.name).join(`, `)})]}),e.slicer_filament&&(0,Y.jsxs)(`button`,{type:`button`,onClick:C,title:f(`inventory.autoMatchPresetsHint`),className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors shrink-0`,children:[(0,Y.jsx)(z,{className:`w-3.5 h-3.5`}),f(`inventory.autoMatchPresets`)]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:f(`inventory.filamentPreset`)}),m.model?(0,Y.jsx)(`div`,{className:`space-y-2`,children:m.diameters.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray w-14 shrink-0`,children:[e,`mm`]}),(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:T(m.model,e,f(`inventory.presetUseSpoolDefault`))})]},e))}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:f(`inventory.presetNeedsModel`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:f(`inventory.kProfilesPerPrinter`)}),e.material?m.printers.map(e=>{let t=y(e);return(0,Y.jsxs)(`div`,{className:`p-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(U,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-white truncate`,children:e.printer.name}),(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-0.5 rounded-full shrink-0 ${e.printer.connected?`bg-green-500/20 text-green-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:e.printer.connected?f(`inventory.connected`):f(`inventory.offline`)})]}),e.printer.connected?t.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:f(`inventory.noKProfilesMatch`)}):(0,Y.jsxs)(`div`,{className:`grid gap-x-3 gap-y-1.5 items-center`,style:{gridTemplateColumns:`3.5rem repeat(${v(e).length}, minmax(0, 1fr))`},children:[(0,Y.jsx)(`span`,{}),v(e).map(e=>(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-bambu-gray`,children:e.label},e.extruder)),m.diameters.map(n=>(0,Y.jsxs)(J.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray`,children:[n,`mm`]}),v(e).map(r=>{let i=t.filter(e=>(e.extruder_id??0)===r.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===n),o=K(e.printer.id,r.extruder,n),s=a.get(o);if(i.length===0)return(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray/50 px-2 py-1.5`,title:f(`inventory.noKProfilesMatch`),children:`—`},o);let c=cn(e,r.extruder),l=on(s?.nozzle_id),u=!!(c&&l&&c!==l);return(0,Y.jsxs)(`select`,{title:u?f(`inventory.kProfileFlowMismatch`,{profile:sn(l),fitted:sn(c)}):void 0,"aria-label":`${e.printer.name} ${r.label} ${n}mm`,value:s?String(s.cali_idx):``,onChange:t=>{let a=i.find(e=>String(e.cali_idx)===t.target.value)??null;S(e.printer.id,r.extruder,n,a)},className:`min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border rounded-lg text-sm text-white focus:outline-none focus:border-bambu-green ${u?`border-amber-500/60`:`border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:f(`inventory.kProfileNotSet`)}),i.map(e=>{let t=sn(on(e.nozzle_id));return(0,Y.jsx)(`option`,{value:e.cali_idx,children:`${t?`[${t}] `:``}${e.name||e.filament_id} K=${e.k_value.toFixed(3)}`},e.cali_idx)})]},o)})]},n))]}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:f(`inventory.printerOffline`)})]},e.printer.id)}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:f(`inventory.selectMaterialFirst`)})]})]})})]})]})}function fn(e){let t=H(e);return t?t.toLocaleDateString(`en-GB`,{day:`2-digit`,month:`2-digit`,year:`2-digit`})+` `+t.toLocaleTimeString(`en-GB`,{hour:`2-digit`,minute:`2-digit`}):``}var pn={completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,aborted:`text-yellow-700 dark:text-yellow-400`};function mn({spoolId:e}){let{t}=c(),n=l(),{showToast:i}=te(),{data:a,isLoading:o}=u({queryKey:[`spool-usage`,e],queryFn:()=>r.getSpoolUsageHistory(e)}),s=d({mutationFn:()=>r.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),i(t(`inventory.historyCleared`),`success`)}});return o?(0,Y.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,Y.jsx)(F,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!a||a.length===0?(0,Y.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,Y.jsx)(Oe,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,Y.jsxs)(V,{variant:`ghost`,size:`sm`,onClick:()=>s.mutate(),disabled:s.isPending,className:`text-xs text-bambu-gray hover:text-red-700 dark:hover:text-red-400`,children:[(0,Y.jsx)(be,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,Y.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:a.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:fn(e.created_at)}),e.print_name&&(0,Y.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,Y.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,Y.jsx)(`span`,{className:pn[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var hn={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function gn({isOpen:e,onClose:t,spool:n,mode:i,printersWithCalibrations:a=[],currencySymbol:s,onSpoolsCreated:f,spoolmanMode:p=!1,spoolsQueryKey:m=[`inventory-spools`]}){let{t:h}=c(),g=l(),{showToast:_}=te(),v=()=>Ie(g,m),y=i===`edit`,b=i===`copy`,[x,S]=(0,J.useState)(ut),[C,w]=(0,J.useState)({}),[T,E]=(0,J.useState)(`filament`),[D,O]=(0,J.useState)(!1),[ee,k]=(0,J.useState)(!1),[A,j]=(0,J.useState)(!1),[M,N]=(0,J.useState)(!1),[ne,I]=(0,J.useState)([]),[L,re]=(0,J.useState)(!1),[R,ie]=(0,J.useState)(!1),[ae,oe]=(0,J.useState)(1),[se,z]=(0,J.useState)(!1);(0,J.useEffect)(()=>{z(!1)},[e,n?.id]);let[ce,le]=(0,J.useState)(!1),[ue,de]=(0,J.useState)(!1),[fe,pe]=(0,J.useState)([]),[B,ge]=(0,J.useState)(new Set),[ve,ye]=(0,J.useState)(``),[be,xe]=(0,J.useState)([]),[Se,Ce]=(0,J.useState)([]),[U,we]=(0,J.useState)([]),[Te,Ee]=(0,J.useState)([]),[De,Oe]=(0,J.useState)([]),[Ae,je]=(0,J.useState)([]),[Ne,Pe]=(0,J.useState)([]),[Fe,Le]=(0,J.useState)(!1),[ze,Ve]=(0,J.useState)(new Map),[He,Ue]=(0,J.useState)(new Map),[We,Ge]=(0,J.useState)(``),Ke=a.length>0?a:Ne,qe=ze.size+He.size,{data:Je=[],isLoading:Xe,error:W}=u({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>r.getSpoolmanInventoryFilaments(),enabled:p&&e,staleTime:6e4,retry:!1});(0,J.useEffect)(()=>{je(Tt())},[]),(0,J.useEffect)(()=>{let t=!1;return e&&((async()=>{de(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await r.getCloudStatus()).is_authenticated?{connected:!0,presets:await r.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await r.orcaCloudStatus()).connected?{connected:!0,presets:(await r.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(t)return;let i=e.status===`fulfilled`&&e.value.connected,a=n.status===`fulfilled`&&n.value.connected,o=e.status===`fulfilled`?e.value.presets:[],s=n.status===`fulfilled`?n.value.presets:[];le(i||a),pe([...o,...s]),ge(new Set(s.map(e=>e.setting_id)))}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),le(!1)}finally{t||de(!1)}})(),r.getSpoolCatalog().then(xe).catch(console.error),r.getColorCatalog().then(Oe).catch(console.error),r.getLocalPresets().then(e=>we(e.filament)).catch(console.error),r.getBuiltinFilaments().then(Ee).catch(console.error),r.getLocations().then(e=>Ce(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),a.length===0&&(async()=>{Le(!0);try{let e=await r.getPrinters(),n=await Promise.all(e.map(e=>r.getPrinterStatus(e.id).catch(()=>null))),i=await Promise.all(e.map(async(e,t)=>{let r=n[t],i=r?.connected??!1,a=[];return i&&(a=await wt(e.id,r)),{printer:{...e,connected:i},calibrations:a,nozzles:r?.nozzles}}));t||Pe(i)}catch(e){console.error(`Failed to fetch printer calibrations:`,e)}finally{t||Le(!1)}})()),()=>{t=!0}},[e,a.length]);let Ze=(0,J.useMemo)(()=>Et(fe,new Set,U,Te,B),[fe,U,Te,B]),Qe=(0,J.useMemo)(()=>{let e=St(fe,U),t=De.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[fe,U,De]),$e=(0,J.useMemo)(()=>{let e=De.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...Ot,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[De]),et=(0,J.useMemo)(()=>{let e=[];for(let t of De){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of fe){let n=Dt(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of U){let n=Dt(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[fe,De,U]),tt=(0,J.useMemo)(()=>{let e=new Map;for(let t of et){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[et]),nt=(0,J.useMemo)(()=>{let e=new Map;for(let t of et){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[et]),rt=(0,J.useMemo)(()=>xt(Qe,x.brand),[Qe,x.brand]),it=(0,J.useMemo)(()=>xt($e,x.material),[$e,x.material]),at=(0,J.useMemo)(()=>ht(rt,x.material,nt),[rt,x.material,nt]),ot=(0,J.useMemo)(()=>ht(it,x.brand,tt),[it,x.brand,tt]),ct=(0,J.useMemo)(()=>yt(x.slicer_filament,Ze),[x.slicer_filament,Ze]);(0,J.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(S({material:n.material||``,subtype:n.subtype||``,brand:n.brand||``,color_name:n.color_name_is_synthesized?``:n.color_name||``,rgba:e,extra_colors:n.extra_colors||``,effect_type:n.effect_type||``,label_weight:n.label_weight||1e3,core_weight:n.core_weight??250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:b?0:n.weight_used||0,slicer_filament:n.slicer_filament||``,note:n.note||``,cost_per_kg:n.cost_per_kg??null,category:n.category||``,low_stock_threshold_pct:n.low_stock_threshold_pct??null,material_number:n.material_number||``,location_id:n.location_id??null,last_dried_at:(()=>{let e=b?null:H(n.last_dried_at);return e?_e(e):``})(),spoolman_filament_id:null}),ye(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Map;for(let t of n.k_profiles){if(t.cali_idx===null||t.cali_idx===void 0)continue;let n=(t.nozzle_diameter||``).trim()||`0.4`,r=t.extruder??0;e.set(K(t.printer_id,r,n),{cali_idx:t.cali_idx,filament_id:``,setting_id:t.setting_id||``,name:t.name||``,k_value:t.k_value,n_coef:0,extruder_id:r,nozzle_diameter:n,nozzle_id:t.nozzle_type||``})}Ve(e)}else Ve(new Map);I((n.suppliers??[]).map(e=>({supplier_id:e.supplier_id,supplier_name:e.supplier_name,supplier_article_number:e.supplier_article_number??``,quoted_price_per_kg:e.quoted_price_per_kg,is_purchase_source:b?!1:e.is_purchase_source})))}else S(ut),ye(``),Ve(new Map),I([]);ie(!1),oe(1),w({}),E(`filament`),Ge(``),Ue(new Map),O(!1),N(!1),k(b&&n?.core_weight_is_inherited===!1),j(!1),re(!1)}},[e,n,i,b]),(0,J.useEffect)(()=>{if(!e||!n)return;let t=!1;return(p?r.getSpoolmanFilamentPresets:r.getSpoolFilamentPresets)(n.id).then(e=>{if(t)return;let n=new Map;for(let t of e)n.set(gt(t.printer_model,t.nozzle_diameter||``),{code:t.slicer_filament||``,name:t.slicer_filament_name||``});Ue(n)}).catch(e=>{t||(console.error(`Failed to load filament preset overrides:`,e),_(h(`inventory.filamentPresetsLoadFailed`),`warning`))}),()=>{t=!0}},[e,n?.id,p]),(0,J.useEffect)(()=>{if(!e||!n||A||x.location_id!=null)return;let t=n.storage_location?.trim();if(!t||Se.length===0)return;let r=Se.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&S(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,Se,x.location_id,A]);let pt=(e,t)=>{let n=st.has(e);p&&n&&x.spoolman_filament_id!==null&&_(h(`inventory.spoolmanFilamentUnlinked`),`info`),S(r=>({...r,[e]:t,...p&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&O(!0),e===`core_weight`&&k(!0),e===`location_id`&&j(!0),e===`last_dried_at`&&N(!0),C[e]&&w(t=>({...t,[e]:void 0}))},mt=e=>{let t=e.material||``,n=e.name||``,r=t&&n.startsWith(t)?n.slice(t.length).trim():n,i=(e.color_hex??``).replace(`#`,``).toUpperCase(),a=/^[0-9A-F]{6}(?:[0-9A-F]{2})?$/.test(i)?i:`808080`,o=a.length===8?a:`${a}FF`;S(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:o,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),_(h(`inventory.spoolmanFilamentSelected`),`success`)},vt=e=>{je(t=>_t(e,t))},Ct=d({mutationFn:e=>p?r.createSpoolmanInventorySpool(e):r.createSpool(e),onSuccess:async e=>{e?.id&&(!await Kt(e.id)||!await Gt(e.id))||(await v(),f&&f([e]),_(h(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.saveFailed`),`error`)}}),At=d({mutationFn:({data:e,qty:t})=>p?r.bulkCreateSpoolmanInventorySpools(e,t):r.bulkCreateSpools(e,t),onSuccess:async e=>{let n=p&&`created`in e?e:null,r=n?n.created:e;if(ze.size>0||He.size>0)for(let e of r)await Kt(e.id);if(Wt)for(let e of r)await Gt(e.id);await v(),f&&f(r),n&&n.failed_count>0?_(h(`inventory.spoolsPartiallyCreated`,{created:r.length,total:n.requested_count}),`warning`):_(h(`inventory.spoolsCreated`,{count:r.length}),`success`),t()},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.saveFailed`),`error`)}}),jt=d({mutationFn:e=>p?r.updateSpoolmanInventorySpool(n.id,e):r.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&(!await Kt(n.id)||!await Gt(n.id))||(await v(),_(h(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.saveFailed`),`error`)}}),Mt=d({mutationFn:()=>p?r.updateSpoolmanInventorySpool(n.id,hn):r.updateSpool(n.id,hn),onSuccess:async()=>{await v(),_(h(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.tagClearFailed`),`error`)}}),{data:Nt,isLoading:Pt}=u({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),enabled:e&&y&&!p}),{data:Ft,isLoading:It}=u({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:e&&y&&p}),Lt=(()=>{if(n)return p?Ft?.find(e=>e.spoolman_spool_id===n.id):Nt?.find(e=>e.spool_id===n.id)})(),Rt=p?It:Pt,{data:X}=u({queryKey:[`inventory-spools`],queryFn:()=>r.getSpools(!0),enabled:e}),{data:Z}=u({queryKey:[`settings`],queryFn:r.getSettings,enabled:e}),{data:zt}=u({queryKey:[`slicerPrinterModels`],queryFn:r.getSlicerPrinterModels,enabled:e,staleTime:1/0}),Bt=(()=>{let e=new Set;for(let t of X??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),Vt=(()=>{let e=new Set;for(let t of X??[]){let n=t.material_number?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0}))})(),Ht=Z?.low_stock_threshold??20,Ut=d({mutationFn:async()=>{if(!Lt)throw Error(`No assignment`);if(p){if(!n)throw Error(`No spool`);await r.unassignSpoolmanSlot(n.id);return}await r.unassignSpool(Lt.printer_id,Lt.ams_id,Lt.tray_id)},onSuccess:async()=>{p?(await g.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),await g.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})):await g.invalidateQueries({queryKey:[`spool-assignments`]}),_(h(`inventory.unassignSuccess`,`Spool unassigned`),`success`),t()},onError:e=>{_(e.message,`error`)}}),Wt=L||b,Gt=async e=>{if(!Wt)return!0;let t=p?r.setSpoolmanSpoolSuppliers:r.setSpoolSuppliers;try{return await t(e,ne.map(e=>({supplier_id:e.supplier_id,supplier_article_number:e.supplier_article_number.trim()||null,quoted_price_per_kg:e.quoted_price_per_kg,is_purchase_source:e.is_purchase_source}))),!0}catch(e){return console.error(`SpoolFormModal.saveSupplierLinks failed:`,e),_(h(`inventory.suppliers.saveFailed`),`error`),!1}},Kt=async e=>{let t=p?r.saveSpoolmanKProfiles:r.saveSpoolKProfiles,n=p?r.saveSpoolmanFilamentPresets:r.saveSpoolFilamentPresets,i=[];for(let[e,t]of ze){let[n,r,a]=e.split(`:`);i.push({printer_id:parseInt(n),extruder:parseInt(r),nozzle_diameter:a||`0.4`,nozzle_type:on(t.nozzle_id),k_value:t.k_value,name:t.name||null,cali_idx:t.cali_idx,setting_id:t.setting_id||null})}let a=[];for(let[e,t]of He){let{model:n,diameter:r}=bt(e);n&&a.push({printer_model:n,nozzle_diameter:r,slicer_filament:t.code||null,slicer_filament_name:t.name||null})}try{await t(e,i)}catch(e){return console.error(`Failed to save K-profiles:`,e),_(h(`inventory.kProfileSaveFailed`),`warning`),!1}try{await n(e,a)}catch(e){return console.error(`Failed to save filament preset overrides:`,e),_(h(`inventory.filamentPresetSaveFailed`),`warning`),!1}return!0};if((0,J.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&!se&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t,se]),!e)return null;let qt=()=>{let e=dt(x,R,p,i);if(!e.isValid){w(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&E(`filament`);return}let t=ct?.displayName||ve||null,n={material:x.material||null,subtype:x.subtype||null,brand:x.brand||null,color_name:x.color_name||null,rgba:x.rgba||null,extra_colors:x.extra_colors||null,effect_type:x.effect_type||null,label_weight:x.label_weight,...p?ee?{core_weight:x.core_weight}:{}:{core_weight:x.core_weight,core_weight_catalog_id:x.core_weight_catalog_id},slicer_filament:x.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:x.note||null,cost_per_kg:x.cost_per_kg,category:x.category.trim()||null,low_stock_threshold_pct:x.low_stock_threshold_pct,material_number:x.material_number.trim()||null,...p?{spoolman_filament_id:x.spoolman_filament_id}:{}};(!y||D)&&(n.weight_used=x.weight_used),(!y||A)&&(n.location_id=x.location_id),y&&M&&(n.last_dried_at=x.last_dried_at?new Date(x.last_dried_at).toISOString():null),y?jt.mutate(n):ae>1?At.mutate({data:n,qty:ae}):Ct.mutate(n)},Jt=Ct.isPending||At.isPending||jt.isPending||Mt.isPending||Ut.isPending;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,Y.jsxs)(`div`,{className:`relative w-full max-w-5xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[h(y?`inventory.editSpool`:b?`inventory.copySpool`:`inventory.addSpool`),y&&n&&(0,Y.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),i===`create`&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:h(`inventory.quickAdd`)})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ie(!R),R||E(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${R?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,Y.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${R?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,Y.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsxs)(`button`,{onClick:()=>E(`filament`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${T===`filament`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(q,{className:`w-4 h-4`}),h(`inventory.filamentInfoTab`)]}),!R&&(0,Y.jsxs)(`button`,{onClick:()=>E(`appearance`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${T===`appearance`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(Be,{className:`w-4 h-4`}),h(`inventory.colorAndCostTab`)]}),!R&&(0,Y.jsxs)(`button`,{onClick:()=>E(`printers`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${T===`printers`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4`}),h(`inventory.printersTab`),qe>0&&(0,Y.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:qe})]})]}),(0,Y.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:T===`filament`?(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[p&&!y&&(0,Y.jsx)(`div`,{children:W?(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 px-1`,children:h(`inventory.spoolmanCatalogLoadFailed`)}):(0,Y.jsx)(an,{filaments:Je,isLoading:Xe,selectedId:x.spoolman_filament_id,onSelect:mt})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:h(`inventory.filamentInfo`)}),(0,Y.jsx)(G,{formData:x,updateField:pt,cloudAuthenticated:ce,loadingCloudPresets:ue,presetInputValue:ve,setPresetInputValue:ye,selectedPresetOption:ct,filamentOptions:Ze,availableBrands:rt,availableMaterials:it,suggestedBrands:at,suggestedMaterials:ot,quickAdd:R,detailsRequired:!R&&!p&&i===`create`,quantity:ae,onQuantityChange:oe,errors:C})]})]}):T===`appearance`?(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:h(`inventory.color`)}),(0,Y.jsx)(lt,{formData:x,updateField:pt,recentColors:Ae,onColorUsed:vt,catalogColors:De})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:h(`inventory.additional`)}),(0,Y.jsx)(ft,{formData:x,updateField:pt,spoolCatalog:be,currencySymbol:s,availableCategories:Bt,availableMaterialNumbers:Vt,availableLocations:Se,showLastDried:y,onCreateLocation:async e=>{try{let t=await r.createLocation({name:e});return Ce(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await Ye(g),{id:t.id,name:t.name}}catch(e){return console.error(e),_((e instanceof Error?e.message:h(`locations.saveFailed`))||h(`locations.saveFailed`),`error`),null}},globalLowStockThreshold:Ht,spoolmanMode:p})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(rn,{links:ne,onChange:e=>{I(e),re(!0)},currencySymbol:s})}),y&&n&&!p&&(0,Y.jsx)(`div`,{children:(0,Y.jsx)(mn,{spoolId:n.id})})]}):(0,Y.jsx)(dn,{formData:x,printersWithCalibrations:Ke,filamentOptions:Ze,modelPresets:He,setModelPresets:Ue,selectedProfiles:ze,setSelectedProfiles:Ve,selectedGroupId:We,setSelectedGroupId:Ge,printerModels:zt,isLoading:Fe})}),(0,Y.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[y&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>Mt.mutate(),disabled:Jt||!(n?.tag_uid||n?.tray_uuid),children:[(0,Y.jsx)(ke,{className:`w-4 h-4`}),h(`inventory.clearRfid`,`Clear RFID Tag`)]}),Lt?(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>Ut.mutate(),disabled:Jt||Rt,children:[(0,Y.jsx)(me,{className:`w-4 h-4`}),h(`inventory.unassignSpool`,`Unassign`)]}):(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>z(!0),disabled:Jt||Rt,children:[(0,Y.jsx)(P,{className:`w-4 h-4`}),h(`inventory.assignSpool`,`Assign Spool`)]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:t,children:h(`common.cancel`)}),(0,Y.jsx)(V,{onClick:qt,disabled:Jt,children:Jt?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),h(`common.saving`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Me,{className:`w-4 h-4`}),h(y?`common.save`:b?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]}),y&&n&&(0,Y.jsx)(kt,{isOpen:se,onClose:()=>z(!1),spool:n,printerId:null,variant:`dialog`,spoolmanMode:p})]})}var Q=[{value:`ams_holder_74x33`,i18nKey:`amsHolderSmall`,fallbackLabel:`AMS holder — small (74 × 33 mm)`,fallbackHint:`Single label per page; matches the printable label from MakerWorld model 752566 (AMS Filament Label Holder).`},{value:`ams_holder_75x55`,i18nKey:`amsHolderLarge`,fallbackLabel:`AMS holder — large (75 × 55 mm)`,fallbackHint:`Single label per page; fits the cardstock-insert variant of the AMS Filament Label Holder. Roomy enough for swatch, brand, material, ID, and QR code.`},{value:`box_40x30`,i18nKey:`box40x30`,fallbackLabel:`Box label (40 × 30 mm)`,fallbackHint:`Single label per page; common DK/Brother roll size, good for filament-bag and storage-bin labels.`},{value:`box_62x29`,i18nKey:`box`,fallbackLabel:`Box label (62 × 29 mm)`,fallbackHint:`Single label per page; sized for Brother PT/QL and Dymo small labels.`},{value:`avery_l7160`,i18nKey:`averyL7160`,fallbackLabel:`Avery L7160 — A4 sheet (38.1 × 63.5 mm × 21)`,fallbackHint:`EU sheet stock; 21 labels per A4 page.`},{value:`avery_5160`,i18nKey:`avery5160`,fallbackLabel:`Avery 5160 — US Letter sheet (25.4 × 66.7 mm × 30)`,fallbackHint:`US sheet stock; 30 labels per Letter page.`}],_n={avery_l7160:21,avery_5160:30},vn=[203,300,600],yn={brand:{i18nKey:`brand`,fallback:`Brand`},material:{i18nKey:`material`,fallback:`Material and subtype`},hex:{i18nKey:`hex`,fallback:`Colour code`},name:{i18nKey:`name`,fallback:`Colour or filament name`},location:{i18nKey:`location`,fallback:`Storage location`},material_number:{i18nKey:`materialNumber`,fallback:`Material number`},temps:{i18nKey:`temps`,fallback:`Nozzle temperature`},weight:{i18nKey:`weight`,fallback:`Net weight`},note:{i18nKey:`note`,fallback:`Note`},added:{i18nKey:`added`,fallback:`Date added`},qr:{i18nKey:`qr`,fallback:`QR code`},spool_id:{i18nKey:`spoolId`,fallback:`Spool ID`}},bn=`bambuddy-label-print-options`,xn={template:Q[0].value,fields:{},monochrome:!1,format:`pdf`,dpi:300};function Sn(){let e;try{e=JSON.parse(localStorage.getItem(bn)??`null`)}catch{return xn}if(!e||typeof e!=`object`)return xn;let t=e,n=Q.map(e=>e.value),r={};if(t.fields&&typeof t.fields==`object`)for(let[e,i]of Object.entries(t.fields))!n.includes(e)||!Array.isArray(i)||(r[e]=i.filter(e=>a.includes(e)));return{template:n.includes(t.template)?t.template:xn.template,fields:r,monochrome:t.monochrome===!0,format:t.format===`png`?`png`:`pdf`,dpi:vn.includes(t.dpi)?t.dpi:xn.dpi}}function Cn(e){try{localStorage.setItem(bn,JSON.stringify(e))}catch{}}function wn(e,t){return e.fields[t]??i}function Tn(e){let t=window.URL.createObjectURL(e);if(!window.open(t,`_blank`)){let e=document.createElement(`a`);e.href=t,e.download=`bambuddy-labels.pdf`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}setTimeout(()=>window.URL.revokeObjectURL(t),6e4)}function En(e,t){let n=window.URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`bambuddy-labels-${t}.${e.type===`application/zip`?`zip`:`png`}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>window.URL.revokeObjectURL(n),6e4)}function Dn(e){return Ke(e)}function On(e){return Ve(e.color_name,e.rgba,e.color_name_is_synthesized)}function $(e){return`${On(e)??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function kn(e){return[On(e),e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function An(e){if(!e)return[1,0];let t=e.replace(/^#/,``).slice(0,6);if(t.length!==6)return[1,0];let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);if([n,r,i].some(Number.isNaN))return[1,0];let a=n/255,o=r/255,s=i/255,c=Math.max(a,o,s),l=Math.min(a,o,s),u=(c+l)/2,d=c-l;if((d===0?0:d/(1-Math.abs(2*u-1)))<.1)return[1,u];let f=0;return f=c===a?(o-s)/d%6:c===o?(s-a)/d+2:(a-o)/d+4,f*=60,f<0&&(f+=360),[0,f]}function jn({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:o,spoolmanMode:s}){let{t:l}=c(),u=Je(),{showToast:d}=te(),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(new Set),[g,_]=(0,J.useState)(``),[v,y]=(0,J.useState)(``),[b,x]=(0,J.useState)(`id`),[S,C]=(0,J.useState)(xn),[w,T]=(0,J.useState)(`1`),[E,D]=(0,J.useState)(null),[O,ee]=(0,J.useState)(!1),[k,A]=(0,J.useState)(null),j=(0,J.useRef)(null);(0,J.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));h(new Set(o.filter(t=>e.has(t)))),_(``),y(``),x(`id`),C(Sn()),T(`1`),p(!1)}},[e]);let M=(0,J.useMemo)(()=>{let e=[...n];return b===`color`?(e.sort((e,t)=>{let n=An(e.rgba),r=An(t.rgba);return n[0]===r[0]?n[1]===r[1]?e.id-t.id:n[1]-r[1]:n[0]-r[0]}),e):(e.sort((e,t)=>e.id-t.id),e)},[n,b]),N=(0,J.useMemo)(()=>{let e=new Set;for(let t of M)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[M]),P=(0,J.useMemo)(()=>{let e=g.trim().toLowerCase();return M.filter(t=>!(v&&(t.material||``).toUpperCase()!==v||e&&!kn(t).includes(e)))},[M,g,v,u]),ne=P.length>0&&P.every(e=>m.has(e.id)),I=S.template,L=wn(S,I),re=L.join(`,`),R=M.find(e=>m.has(e.id))?.id??null;function ie(e){j.current&&window.URL.revokeObjectURL(j.current),j.current=e,D(e)}if((0,J.useEffect)(()=>{if(!e||R===null){ie(null),A(null),ee(!1);return}let t=new AbortController;ee(!0);let n=window.setTimeout(async()=>{let e={spool_id:R,template:I,monochrome:S.monochrome,fields:re?re.split(`,`):[]};try{let n=s?await r.previewSpoolmanSpoolLabel(e,t.signal):await r.previewSpoolLabel(e,t.signal);if(t.signal.aborted)return;ie(window.URL.createObjectURL(n)),A(null)}catch(e){if(t.signal.aborted)return;ie(null),A(e instanceof Error?e.message:String(e))}finally{t.signal.aborted||ee(!1)}},250);return()=>{window.clearTimeout(n),t.abort()}},[e,R,I,re,S.monochrome,s]),(0,J.useEffect)(()=>()=>{j.current&&window.URL.revokeObjectURL(j.current)},[]),!e)return null;let ae=m.size,oe=ae===0,z=_n[I],ce=Number(w),le=z===void 0||Number.isInteger(ce)&&ce>=1&&ce<=z,ue=Q.find(e=>e.value===I)??Q[0];function de(e){C(t=>{let n={...t,...e};return Cn(n),n})}function fe(e){let t=a.filter(t=>e.includes(t));de({fields:{...S.fields,[I]:t}})}function pe(e){fe(L.includes(e)?L.filter(t=>t!==e):[...L,e])}function B(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function me(){h(e=>{let t=new Set(e);for(let e of P)t.add(e.id);return t})}function ge(){h(e=>{let t=new Set(e);for(let e of P)t.delete(e.id);return t})}function H(){h(new Set)}async function _e(){if(oe||f||!le)return;let e={spool_ids:M.filter(e=>m.has(e.id)).map(e=>e.id),template:I,monochrome:S.monochrome,starting_position:z===void 0?1:ce,fields:L,format:S.format,dpi:S.dpi};p(!0);try{let n=s?await r.printSpoolmanSpoolLabels(e):await r.printSpoolLabels(e);S.format===`pdf`?Tn(n):En(n,I),t()}catch(e){d(l(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{p(!1)}}let ve=e=>`px-2 py-0.5 text-xs rounded-full border transition ${e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`;return(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,Y.jsxs)(`div`,{"data-testid":`label-template-picker-panel`,className:`relative w-full max-w-5xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-clip flex flex-col my-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:l(`inventory.labels.title`,`Print spool labels`)}),ae>0&&(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,l(`inventory.labels.selectedCount`,`{{count}} selected`,{count:ae}),`)`]})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":l(`common.close`,`Close`),children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto md:overflow-hidden grid grid-cols-1 md:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col min-h-0 md:border-r border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(se,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:l(`inventory.labels.searchPlaceholder`,`Search name, brand, or #ID`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),N.length>1&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:l(`inventory.labels.filterByMaterial`,`Material:`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${v===``?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:l(`inventory.labels.allMaterials`,`All`)}),N.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${v===e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:e},e))]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:l(`inventory.labels.sortBy.label`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>x(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${b===`id`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:l(`inventory.labels.sortBy.id`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>x(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${b===`color`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:l(`inventory.labels.sortBy.color`)})]})]}),(0,Y.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:ne?ge:me,disabled:P.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:ne?l(`inventory.labels.deselectVisible`,`Deselect visible`):l(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:P.length})}),(0,Y.jsx)(`button`,{type:`button`,onClick:H,disabled:ae===0,className:`text-bambu-gray hover:text-white hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:l(`inventory.labels.clearAll`,`Clear all`)})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0 max-h-72 md:max-h-none`,children:P.length===0?(0,Y.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:M.length===0?l(`inventory.labels.noSpoolsToShow`,`No spools to show. Adjust your filter and try again.`):l(`inventory.labels.noMatches`,`No spools match the current search or filter.`)}):(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:P.map(e=>{let t=m.has(e.id);return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary/50 cursor-pointer`,children:[t?(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(Ee,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>B(e.id),className:`sr-only`}),(0,Y.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:Dn(e.rgba)}),(0,Y.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:$(e)}),(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})})]}),(0,Y.jsxs)(`div`,{className:`md:overflow-y-auto p-4 space-y-4 border-t md:border-t-0 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`label-template`,className:`text-sm font-medium text-white`,children:l(`inventory.labels.template`,`Label size`)}),(0,Y.jsx)(`select`,{id:`label-template`,"data-testid":`label-template-select`,value:I,onChange:e=>de({template:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:Q.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:l(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel)},e.value))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.templates.${ue.i18nKey}.hint`,ue.fallbackHint)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-white`,children:R===null?l(`inventory.labels.preview`,`Preview`):l(`inventory.labels.previewOf`,`Preview of #{{id}}`,{id:R})}),(0,Y.jsxs)(`div`,{"data-testid":`label-preview`,className:`relative flex items-center justify-center min-h-40 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[R===null?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray text-center`,children:l(`inventory.labels.previewNoSelection`,`Select a spool to see its label.`)}):k?(0,Y.jsx)(`span`,{className:`text-sm text-red-400 text-center`,children:l(`inventory.labels.previewError`,`Could not render the preview: {{msg}}`,{msg:k})}):E?(0,Y.jsx)(`img`,{src:E,alt:l(`inventory.labels.previewAlt`,`Label preview`),className:`max-h-56 max-w-full object-contain bg-white shadow`}):null,O&&(0,Y.jsx)(F,{className:`absolute top-2 right-2 w-4 h-4 animate-spin text-bambu-green`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.previewHint`,`Lines that don't fit on this label size are left out.`)})]}),(0,Y.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-white`,children:l(`inventory.labels.content`,`Print on the label`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>fe(i),className:`text-xs text-bambu-green hover:underline`,children:l(`inventory.labels.resetFields`,`Reset to default`)})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1`,children:a.map(e=>{let t=L.includes(e),{i18nKey:n,fallback:r}=yn[e];return(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 py-0.5 cursor-pointer select-none`,children:[t?(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(Ee,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`input`,{type:`checkbox`,"data-testid":`label-field-${e}`,checked:t,onChange:()=>pe(e),className:`sr-only`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.labels.fields.${n}`,r)})]},e)})})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer select-none`,children:[S.monochrome?(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(Ee,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`input`,{type:`checkbox`,checked:S.monochrome,onChange:e=>de({monochrome:e.target.checked}),className:`sr-only`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.labels.monochrome`,`Monochrome (black & white printer)`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.monochromeHint`,`Drops the colour swatch and widens the text`)})]}),z!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`label`,{htmlFor:`label-starting-position`,className:`text-sm text-white whitespace-nowrap pt-1.5`,children:l(`inventory.labels.startingPosition`,`Starting label position`)}),(0,Y.jsx)(`input`,{id:`label-starting-position`,"data-testid":`label-starting-position`,type:`number`,min:1,max:z,step:1,value:w,onChange:e=>T(e.target.value),"aria-describedby":`label-starting-position-help`,className:`w-20 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,Y.jsx)(`div`,{id:`label-starting-position-help`,"data-testid":`label-starting-position-status`,className:`text-xs pt-1.5 ${le?`text-bambu-gray`:`text-red-400`}`,children:le?ce===1?l(`inventory.labels.startingPositionFirst`,`Printing starts at position 1.`):l(`inventory.labels.startingPositionSkipped`,`Positions 1 through {{lastPosition}} will be left blank on the first sheet.`,{lastPosition:ce-1}):l(`inventory.labels.startingPositionInvalid`,`Enter a whole number from 1 to {{capacity}}.`,{capacity:z})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white mr-1`,children:l(`inventory.labels.format`,`Output:`)}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`label-format-pdf`,"aria-pressed":S.format===`pdf`,onClick:()=>de({format:`pdf`}),className:ve(S.format===`pdf`),children:`PDF`}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`label-format-png`,"aria-pressed":S.format===`png`,onClick:()=>de({format:`png`}),className:ve(S.format===`png`),children:`PNG`}),S.format===`png`&&(0,Y.jsx)(`select`,{"data-testid":`label-dpi-select`,"aria-label":l(`inventory.labels.dpi`,`Resolution`),value:S.dpi,onChange:e=>de({dpi:Number(e.target.value)}),className:`ml-2 px-2 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:outline-none focus:border-bambu-green`,children:vn.map(e=>(0,Y.jsxs)(`option`,{value:e,children:[e,` dpi`]},e))})]}),S.format===`png`&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.pngHint`,`For label printer software that takes images. Match your printer's resolution; several labels come as a ZIP.`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-3 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:t,disabled:f,children:l(`common.cancel`,`Cancel`)}),(0,Y.jsxs)(V,{"data-testid":`label-print-button`,onClick:_e,disabled:oe||f||!le,children:[f?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):S.format===`pdf`?(0,Y.jsx)(U,{className:`w-4 h-4`}):(0,Y.jsx)(Qe,{className:`w-4 h-4`}),S.format===`pdf`?l(`inventory.labels.createPdf`,`Create PDF`):l(`inventory.labels.downloadPng`,`Download PNG`)]})]})]})]})}function Mn({onClose:e,onImported:t}){let{t:n}=c(),[i,a]=(0,J.useState)(null),[o,s]=(0,J.useState)(!1),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(!1),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)(null),_=(0,J.useRef)(null),v=async e=>{a(e),u(null),g(null),f(!0);try{u(await r.importSpoolsCsvPreview(e))}catch(e){g(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{f(!1)}},y=e=>{let t=e.target.files?.[0];t&&v(t)},b=e=>{e.preventDefault(),s(!1);let t=e.dataTransfer.files?.[0];t&&v(t)},x=async()=>{if(i){m(!0),g(null);try{t((await r.importSpoolsCsv(i)).created)}catch(e){g(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),m(!1)}}},S=e=>e===`valid`?(0,Y.jsx)(A,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,Y.jsx)(D,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,Y.jsx)(We,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),C=l?.valid_count??0;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-3xl border border-bambu-dark-tertiary flex flex-col max-h-[90vh]`,children:[(0,Y.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,Y.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,Y.jsx)(he,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,Y.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),s(!0)},onDragLeave:e=>{e.preventDefault(),s(!1)},onDrop:b,onClick:()=>_.current?.click(),className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${o?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,Y.jsx)(Ge,{className:`w-9 h-9 mx-auto mb-2 ${o?`text-bambu-green`:`text-bambu-gray`}`}),i?(0,Y.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,Y.jsx)($e,{className:`w-4 h-4`}),` `,i.name]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`inventory.csv.dragHint`,`Header: material (required), brand, subtype, color_name, rgba, …`)})]})]}),(0,Y.jsx)(`input`,{ref:_,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:y}),d&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),h&&(0,Y.jsxs)(`div`,{className:`p-3 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg flex items-start gap-3`,children:[(0,Y.jsx)(D,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300 break-words`,children:h})]}),l&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,Y.jsx)(`span`,{className:`px-2 py-1 rounded bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400`,children:n(`inventory.csv.validCount`,`{{count}} valid`,{count:l.valid_count})}),(0,Y.jsx)(`span`,{className:`px-2 py-1 rounded bg-red-50 dark:bg-red-500/10 text-red-700 dark:text-red-400`,children:n(`inventory.csv.errorCount`,`{{count}} error`,{count:l.error_count})}),(0,Y.jsx)(`span`,{className:`px-2 py-1 rounded bg-bambu-dark text-bambu-gray`,children:n(`inventory.csv.skippedCount`,`{{count}} skipped`,{count:l.skipped_count})})]}),l.warnings.length>0&&(0,Y.jsx)(`div`,{className:`p-3 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg space-y-1`,children:l.warnings.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-300`,children:e},t))}),l.rows.length>0&&(0,Y.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,Y.jsx)(`tbody`,{children:l.rows.map(e=>(0,Y.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[S(e.status),e.status===`error`&&e.reason&&(0,Y.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400 break-words`,children:e.reason})]})}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,Y.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:Ke(e.rgba)}),(0,Y.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,Y.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,Y.jsx)(je,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,Y.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,Y.jsx)(B,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,Y.jsx)(`span`,{title:n(`inventory.csv.duplicateExisting`,`A spool with this material, brand and color already exists — it will still be imported as a new spool`),children:(0,Y.jsx)(M,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,Y.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:e,disabled:p,children:n(`common.cancel`)}),(0,Y.jsx)(V,{onClick:x,disabled:!l||C===0||p,children:p?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`w-4 h-4 mr-2 animate-spin`}),n(`inventory.csv.importing`,`Importing…`)]}):C>0?n(`inventory.csv.importValidRows`,`Import {{count}} valid rows`,{count:C}):n(`inventory.csv.noValidRows`,`No valid rows`)})]})]})})}function Nn({open:e,onClose:t}){let{t:n}=c(),{showToast:i}=te(),a=l(),{data:s=[],isLoading:d,isError:f}=u({queryKey:Xe,queryFn:r.getSuppliers,enabled:e}),[p,m]=(0,J.useState)(``),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)(``),[x,S]=(0,J.useState)(``),[C,T]=(0,J.useState)(``),[E,D]=(0,J.useState)(``),[O,ee]=(0,J.useState)(!1),[k,A]=(0,J.useState)(null);if((0,J.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let j=s.filter(e=>e.name.toLowerCase().includes(p.toLowerCase())),M=()=>{b(``),S(``),T(``),D(``)},N=()=>({name:y.trim(),website:x.trim()||null,customer_number:C.trim()||null,note:E.trim()||null}),P=async()=>{if(!y.trim()){i(n(`inventory.suppliers.nameRequired`),`error`);return}ee(!0);try{await r.createSupplier(N()),await He(a),g(!1),M(),i(n(`inventory.suppliers.added`),`success`)}catch(e){console.error(`SuppliersModal.handleAdd failed:`,e),i(n(e instanceof o&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.addFailed`),`error`)}finally{ee(!1)}},ne=e=>{v(e.id),b(e.name),S(e.website??``),T(e.customer_number??``),D(e.note??``)},I=()=>{v(null),M()},L=async e=>{if(!y.trim()){i(n(`inventory.suppliers.nameRequired`),`error`);return}ee(!0);try{await r.updateSupplier(e,N()),await He(a),I(),i(n(`inventory.suppliers.updated`),`success`)}catch(e){console.error(`SuppliersModal.handleUpdate failed:`,e),i(n(e instanceof o&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.updateFailed`),`error`)}finally{ee(!1)}},re=async()=>{if(k)try{await r.deleteSupplier(k.id),await He(a),i(n(`inventory.suppliers.deleted`),`success`)}catch(e){console.error(`SuppliersModal.handleDelete failed:`,e),e instanceof o&&e.status===409?i(n(`inventory.suppliers.deleteBlocked`,{count:k.spool_count}),`error`):i(n(`inventory.suppliers.deleteFailed`),`error`)}finally{A(null)}},R=(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.namePlaceholder`),value:y,maxLength:200,onChange:e=>b(e.target.value)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.websitePlaceholder`),value:x,maxLength:500,onChange:e=>S(e.target.value)}),(0,Y.jsx)(`input`,{type:`text`,className:`w-40 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.customerNumberPlaceholder`),value:C,maxLength:100,onChange:e=>T(e.target.value)})]}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.notePlaceholder`),value:E,maxLength:500,onChange:e=>D(e.target.value)})]});return(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:t}),(0,Y.jsxs)(`div`,{className:`relative w-full max-w-3xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`suppliers-modal-title`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ft,{className:`w-5 h-5 text-bambu-gray`}),(0,Y.jsx)(`h2`,{id:`suppliers-modal-title`,className:`text-lg font-semibold text-white`,children:n(`inventory.suppliers.title`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,s.length,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{g(!0),v(null),M()},className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(Pe,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`common.add`)})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,"aria-label":n(`common.close`),children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-6 py-4 space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`inventory.suppliers.description`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(se,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.search`),value:p,onChange:e=>m(e.target.value)})]}),h&&(0,Y.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary space-y-3`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:n(`inventory.suppliers.addNew`)}),R,(0,Y.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,Y.jsx)(`button`,{onClick:()=>{g(!1),M()},className:`px-3 py-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:n(`common.cancel`)}),(0,Y.jsxs)(`button`,{onClick:P,disabled:O,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1`,children:[O?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(w,{className:`w-4 h-4`}),n(`common.add`)]})]})]}),d?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(F,{className:`w-5 h-5 animate-spin mr-2`}),n(`common.loading`)]}):f?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-8 text-sm text-red-400`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),n(`inventory.suppliers.loadFailed`)]}):(0,Y.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:n(`common.name`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium hidden sm:table-cell`,children:n(`inventory.suppliers.customerNumber`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-20`,children:n(`inventory.suppliers.spools`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,Y.jsx)(`tbody`,{children:j.length===0?(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:4,className:`px-4 py-8 text-center text-bambu-gray`,children:n(p?`inventory.suppliers.noMatch`:`inventory.suppliers.empty`)})}):j.map(e=>(0,Y.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark align-top`,children:_===e.id?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-4 py-2`,colSpan:3,children:R}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>L(e.id),disabled:O,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:O?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(w,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:I,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`td`,{className:`px-4 py-2 text-white`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:e.name}),e.website&&(0,Y.jsx)(`a`,{href:e.website,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green`,title:e.website,children:(0,Y.jsx)(xe,{className:`w-3.5 h-3.5`})})]}),e.note&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.note})]}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-bambu-gray hidden sm:table-cell`,children:e.customer_number||`-`}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-right font-mono text-bambu-gray`,children:e.spool_count}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>{ne(e),g(!1)},className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,Y.jsx)(ye,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>A(e),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,Y.jsx)(be,{className:`w-4 h-4`})})]})})]})},e.id))})]})})]})]}),k&&(0,Y.jsx)(Fe,{title:n(`inventory.suppliers.deleteTitle`),message:k.spool_count>0?n(`inventory.suppliers.deleteConfirmReferenced`,{name:k.name,count:k.spool_count}):n(`inventory.suppliers.deleteConfirm`,{name:k.name}),confirmText:n(`common.delete`),variant:`danger`,onConfirm:re,onCancel:()=>A(null)})]})}var Pn=[{id:`material`,type:`searchable`,labelKey:`inventory.material`},{id:`subtype`,type:`searchable`,labelKey:`inventory.subtype`},{id:`brand`,type:`searchable`,labelKey:`inventory.brand`},{id:`color_name`,type:`text`,labelKey:`inventory.colorName`},{id:`rgba`,type:`color`,labelKey:`inventory.color`,pattern:`^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$`},{id:`location_id`,type:`searchableClosed`,labelKey:`inventory.storageLocation`},{id:`slicer_filament_name`,type:`searchable`,labelKey:`inventory.slicerFilamentName`},{id:`slicer_filament`,type:`searchable`,labelKey:`inventory.slicerFilament`},{id:`cost_per_kg`,type:`number`,labelKey:`inventory.costPerKg`,min:0,step:.01},{id:`note`,type:`textarea`,labelKey:`inventory.note`},{id:`label_weight`,type:`number`,labelKey:`inventory.labelWeight`,min:1,step:1},{id:`core_weight`,type:`number`,labelKey:`inventory.coreWeight`,min:0,step:1},{id:`category`,type:`searchable`,labelKey:`inventory.category`,internalOnly:!0},{id:`low_stock_threshold_pct`,type:`number`,labelKey:`inventory.lowStockThresholdOverride`,min:1,max:99,step:1,internalOnly:!0},{id:`material_number`,type:`searchable`,labelKey:`inventory.materialNumber`,internalOnly:!0}];function Fn({value:e,onChange:t,options:n,allowCustom:r,placeholderKey:i,disabled:a}){let{t:o}=c(),s=(0,J.useRef)(null),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(``);(0,J.useEffect)(()=>{if(!l)return;let e=e=>{s.current&&!s.current.contains(e.target)&&(u(!1),f(``))},t=e=>{e.key===`Escape`&&(u(!1),f(``))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]);let p=l?d:n.find(t=>t.value===e)?.label??e,m=(0,J.useMemo)(()=>{if(!l)return n;let e=d.trim().toLowerCase();return e?n.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):n},[l,d,n]),h=l&&d.trim()&&!n.some(e=>e.value.toLowerCase()===d.trim().toLowerCase());return(0,Y.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,Y.jsx)(`input`,{type:`text`,disabled:a,value:p,onChange:e=>{f(e.target.value),u(!0),r&&t(e.target.value)},onFocus:()=>{u(!0),f(``)},placeholder:i?o(i):void 0,className:`w-full px-3 py-2 pr-9 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(T,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),l&&(0,Y.jsxs)(`div`,{className:`absolute z-50 left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:[m.length===0&&!r&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}),m.map(n=>(0,Y.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e===n.value?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(n.value),u(!1),f(``)},children:n.label},n.value)),r&&h&&(0,Y.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(d.trim()),u(!1),f(``)},children:o(`inventory.bulk.useCustom`,{value:d.trim()})})]})]})}function In(...e){let t=new Set;for(let n of e)for(let e of n){let n=e?.trim();n&&t.add(n)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function Ln({isOpen:e,selectedCount:t,isPending:n,availableLocations:i,availableMaterials:a,availableSubtypes:o,availableBrands:s,availableCategories:l,availableMaterialNumbers:d,availableSlicerFilaments:f,availableSlicerFilamentNames:p,spoolmanMode:m=!1,onClose:h,onApply:g}){let{t:_}=c(),v=(0,J.useMemo)(()=>Pn.filter(e=>!(m&&e.internalOnly)),[m]),{data:y=[]}=u({queryKey:[`bulk-edit-cloud-presets`],enabled:e,staleTime:300*1e3,queryFn:async()=>{let e=[];try{if((await r.getCloudStatus()).is_authenticated){let t=await r.getFilamentPresets();e.push(...t)}}catch{}try{if((await r.orcaCloudStatus()).connected){let t=await r.orcaCloudListProfiles();e.push(...t.filament)}}catch{}return e}}),{data:b}=u({queryKey:[`bulk-edit-local-presets`],enabled:e,staleTime:300*1e3,queryFn:r.getLocalPresets}),{data:x=[]}=u({queryKey:[`builtin-filaments`],enabled:e,staleTime:300*1e3,queryFn:r.getBuiltinFilaments}),S=(0,J.useMemo)(()=>Et(y,new Set,b?.filament??[],x),[y,b,x]),[C,w]=(0,J.useState)({}),T=(0,J.useMemo)(()=>In(Ot,a).map(e=>({value:e,label:e})),[a]),E=(0,J.useMemo)(()=>In(pt,o).map(e=>({value:e,label:e})),[o]),D=(0,J.useMemo)(()=>In(vt,s).map(e=>({value:e,label:e})),[s]),O=(0,J.useMemo)(()=>In(l).map(e=>({value:e,label:e})),[l]),ee=(0,J.useMemo)(()=>In(d).map(e=>({value:e,label:e})),[d]),k=(0,J.useMemo)(()=>{let e=S.map(e=>({value:e.code,label:e.displayName})),t=f.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[S,f]),te=(0,J.useMemo)(()=>{let e=S.map(e=>({value:e.displayName,label:e.displayName})),t=p.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[S,p]),A=(0,J.useMemo)(()=>i.map(e=>({value:String(e.id),label:e.name})),[i]);if(!e)return null;let j=(e,t)=>{w(n=>({...n,[e]:t}))},M=e=>{w(t=>{let n={...t};return delete n[e],n})},N=(()=>{let e={};for(let t of v){let n=C[t.id];if(n===void 0)continue;let r=typeof n==`string`?n.trim():n;if(!(r===``||r===null))if(t.type===`number`){let n=Number(r);Number.isFinite(n)&&(e[t.id]=n)}else if(t.id===`location_id`){let n=Number(r);Number.isFinite(n)&&n>0&&(e[t.id]=n)}else if(t.id===`rgba`){let n=String(r).replace(/^#/,``),i=n.length===6?`${n}FF`:n;/^[0-9A-Fa-f]{8}$/.test(i)&&(e[t.id]=i.toUpperCase())}else e[t.id]=String(r)}return e})(),P=Object.keys(N).length>0,ne=v.some(e=>{let t=C[e.id];return t===void 0||t.trim()===``?!1:N[e.id]===void 0}),I=e=>e===`material`?T:e===`subtype`?E:e===`brand`?D:e===`category`?O:e===`material_number`?ee:e===`slicer_filament`?k:e===`slicer_filament_name`?te:e===`location_id`?A:[],L=e=>{let t=C[e.id]??``;if(e.type===`searchable`||e.type===`searchableClosed`)return(0,Y.jsx)(Fn,{value:t,onChange:t=>{t===``?M(e.id):j(e.id,t)},options:I(e.id),allowCustom:e.type===`searchable`,disabled:n});if(e.type===`textarea`)return(0,Y.jsx)(`textarea`,{disabled:n,value:t,onChange:t=>j(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none resize-none min-h-[60px]`});if(e.type===`color`){let r=t.trim().replace(/^#/,``),i=r.length===6?`${r}FF`:r,a=t.trim()!==``&&!/^[0-9A-Fa-f]{8}$/.test(i);return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`color`,disabled:n,value:`#${(t||`808080`).replace(/^#/,``).slice(0,6)}`,onChange:t=>j(e.id,t.target.value.replace(/^#/,``).toUpperCase()),className:`h-9 w-12 rounded cursor-pointer`}),(0,Y.jsx)(`input`,{type:`text`,disabled:n,value:t,onChange:t=>j(e.id,t.target.value.replace(/^#/,``).toUpperCase()),placeholder:`RRGGBB or RRGGBBAA`,className:`flex-1 px-3 py-2 bg-bambu-dark border rounded-lg text-white placeholder-bambu-gray/50 focus:outline-none ${a?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,pattern:e.pattern})]}),a&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:_(`inventory.bulk.invalidHex`)})]})}return(0,Y.jsx)(`input`,{type:e.type===`number`?`number`:`text`,disabled:n,value:t,onChange:t=>j(e.id,t.target.value),min:e.min,max:e.max,step:e.step,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`})};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50`,onClick:n?void 0:h,children:(0,Y.jsxs)(`div`,{className:`w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-5 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:_(`inventory.bulk.editTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:_(`inventory.bulk.editSubtitle`,{count:t})})]}),(0,Y.jsx)(`button`,{onClick:h,disabled:n,className:`p-1 text-bambu-gray hover:text-white transition-colors`,"aria-label":_(`common.close`),children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),(0,Y.jsx)(`p`,{className:`px-5 pt-4 text-xs text-bambu-gray`,children:_(`inventory.bulk.editHint`)}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5 space-y-3`,children:v.map(e=>{let t=C[e.id]!==void 0;return(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md p-2 transition-colors ${t?`bg-bambu-green/5 border border-bambu-green/30`:`border border-transparent`}`,children:[(0,Y.jsx)(`div`,{className:`pt-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,checked:t,onChange:t=>{t.target.checked?j(e.id,``):M(e.id)},"aria-label":_(`inventory.bulk.toggleField`)})}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(e.labelKey)}),L(e)]})]},e.id)})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-5 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:_(`inventory.bulk.changeCount`,{count:Object.keys(N).length})}),(0,Y.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:h,disabled:n,children:_(`common.cancel`)}),(0,Y.jsx)(V,{onClick:()=>g(N),disabled:!P||n||ne,children:n?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`w-4 h-4 mr-2 animate-spin`}),_(`inventory.bulk.applyPending`)]}):_(`inventory.bulk.applyButton`,{count:t})})]})]})]})})}function Rn(e){let t=e[0],n=0,r=0,i=0;for(let t of e)n+=t.label_weight,r+=t.weight_used,i+=t.core_weight;return{...t,label_weight:n,weight_used:r,core_weight:i}}function zn(e){let t=new Set;for(let n of e)if(typeof n==`string`){let e=n.trim();e&&t.add(e)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function Bn(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}|${e.last_dried_at||``}`}var Vn=`bambuddy-inventory-columns`,Hn=`none`.padStart(65,`_`);function Un(e){return(e||``).toLowerCase().replace(/\d+/g,e=>e.padStart(64,`0`))}var Wn=[{id:`id`,label:`#`,visible:!0},{id:`added_time`,label:`Added`,visible:!0},{id:`encode_time`,label:`Encoded`,visible:!1},{id:`last_used_time`,label:`Last Used`,visible:!1},{id:`rgba`,label:`Color`,visible:!0},{id:`material`,label:`Material`,visible:!0},{id:`subtype`,label:`Subtype`,visible:!0},{id:`color_name`,label:`Color Name`,visible:!1},{id:`brand`,label:`Brand`,visible:!0},{id:`slicer_filament`,label:`Slicer Filament`,visible:!1},{id:`location`,label:`Location`,visible:!0},{id:`storage_location`,label:`Storage Location`,visible:!1},{id:`temperature`,label:`Temperature`,visible:!1},{id:`humidity`,label:`Humidity`,visible:!1},{id:`last_dried`,label:`Last Dried`,visible:!0},{id:`battery`,label:`Battery`,visible:!1},{id:`label_weight`,label:`Label`,visible:!0},{id:`net`,label:`Net`,visible:!0},{id:`gross`,label:`Gross`,visible:!1},{id:`added_full`,label:`Full`,visible:!1},{id:`used`,label:`Used`,visible:!1},{id:`printed_total`,label:`Printed Total`,visible:!1},{id:`printed_since_weight`,label:`Printed Since Weight`,visible:!1},{id:`note`,label:`Note`,visible:!1},{id:`material_number`,label:`Material No.`,visible:!1},{id:`suppliers`,label:`Suppliers`,visible:!1},{id:`pa_k`,label:`PA(K)`,visible:!0},{id:`tag_id`,label:`Tag ID`,visible:!1},{id:`data_origin`,label:`Data Origin`,visible:!1},{id:`tag_type`,label:`Linked Tag Type`,visible:!1},{id:`stock`,label:`Stock`,visible:!1},{id:`remaining`,label:`Remaining`,visible:!0},{id:`spool_name`,label:`Spool`,visible:!1},{id:`cost_per_kg`,label:`Cost/kg`,visible:!1},{id:`weight_check`,label:`Weight Check`,visible:!1}];function Gn(){try{let e=localStorage.getItem(Vn);if(e){let t=JSON.parse(e),n=new Set(Wn.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=[...t.filter(e=>n.has(e.id))];for(let e of Wn){if(r.has(e.id))continue;let t=Wn.indexOf(e),n=i.length;for(let e=t-1;e>=0;e--){let t=i.findIndex(t=>t.id===Wn[e].id);if(t!==-1){n=t+1;break}}i.splice(n,0,e)}return i}}catch{}return Wn.map(e=>({...e}))}function Kn(e){try{localStorage.setItem(Vn,JSON.stringify(e))}catch{}}function qn(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var Jn={PLA:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,ABS:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,PETG:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,TPU:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,ASA:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,PA:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,PC:`bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400`,PET:`bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400`};function Yn(e){let t=[];return e.last_dried_temp!=null&&t.push(`${e.last_dried_temp}°C`),e.last_dried_hours!=null&&t.push(`${Number(e.last_dried_hours.toFixed(1))}h`),t.join(` · `)}function Xn(e,t=`system`){if(!e)return`-`;let n=H(e);return n?ge(n,t):`-`}var Zn={id:()=>`#`,added_time:()=>`Added`,encode_time:()=>`Encoded`,last_used_time:()=>`Last Used`,rgba:e=>e(`inventory.color`),material:e=>e(`inventory.material`),subtype:e=>e(`inventory.subtype`),color_name:e=>e(`inventory.colorName`),brand:e=>e(`inventory.brand`),slicer_filament:e=>e(`inventory.slicerFilament`),location:()=>`Location`,storage_location:e=>e(`inventory.storageLocation`),temperature:e=>e(`inventory.temperature`),humidity:e=>e(`inventory.humidity`),last_dried:e=>e(`inventory.lastDried`),battery:e=>e(`inventory.battery`),label_weight:e=>e(`inventory.labelWeight`),net:e=>e(`inventory.net`),gross:()=>`Gross`,added_full:()=>`Full`,used:e=>e(`inventory.weightUsed`),printed_total:()=>`Printed Total`,printed_since_weight:()=>`Printed Since Weight`,note:e=>e(`inventory.note`),material_number:e=>e(`inventory.materialNumber`),suppliers:e=>e(`inventory.suppliers.label`),pa_k:()=>`PA(K)`,tag_id:()=>`Tag ID`,data_origin:()=>`Data Origin`,tag_type:()=>`Linked Tag Type`,stock:e=>e(`inventory.stock`),remaining:e=>e(`inventory.remaining`),spool_name:e=>e(`inventory.spoolName`),cost_per_kg:e=>e(`inventory.costPerKg`),weight_check:e=>e(`inventory.weightCheck`)},Qn={id:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Xn(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Xn(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?Xn(e.last_used,t):`Never`}),last_dried:({spool:e,dateFormat:t})=>{if(!e.last_dried_at)return(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let n=Yn(e);return(0,Y.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,Y.jsx)(`div`,{children:Xn(e.last_dried_at,t)}),n&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray/60`,children:n})]})},rgba:({spool:e})=>(0,Y.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,Y.jsx)(Ze,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Ve(e.color_name,e.rgba,e.color_name_is_synthesized)||`-`}),brand:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:e.slicer_filament||void 0,children:e.slicer_filament_name||e.slicer_filament||`-`}),location:({spool:e,assignmentMap:t})=>{let n=t[e.id];if(!n)return(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let r=n.printer_name||`Printer ${n.printer_id}`,i=n.ams_id===254||n.ams_id===255,a=!i&&n.ams_id>=128;return(0,Y.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:[r,` `,Ce(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:e.storage_location}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),temperature:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`temperature`):void 0;return s?(0,Y.jsx)(`span`,{title:s.name,className:`text-sm ${ur(s,r,i,a,o)}`,children:lr(s,n)}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},humidity:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`humidity`):void 0;return s?(0,Y.jsx)(`span`,{title:s.name,className:`text-sm ${ur(s,r,i,a,o)}`,children:lr(s,n)}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},battery:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`battery`):void 0;return s?(0,Y.jsx)(`span`,{title:s.name,className:`text-sm ${ur(s,r,i,a,o)}`,children:lr(s,n)}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},label_weight:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:qn(e.label_weight)}),net:({remaining:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:qn(e)}),gross:({spool:e,remaining:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:qn(t+e.core_weight)}),added_full:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?qn(e.weight_used):`-`}),printed_total:()=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),material_number:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.material_number||`-`}),suppliers:({spool:e})=>{let t=e.suppliers??[];return t.length===0?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 max-w-[220px]`,children:[...t].sort((e,t)=>Number(t.is_purchase_source)-Number(e.is_purchase_source)).map(e=>(0,Y.jsx)(`span`,{title:e.supplier_article_number||void 0,className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium ${e.is_purchase_source?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-gray/10 text-bambu-gray`}`,children:e.supplier_name},e.id))})},pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green`,children:`K`}),tag_id:({spool:e})=>{let t=e.tag_uid||e.tray_uuid;return t?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray font-mono`,title:t,children:t.length>12?`${t.slice(0,6)}...${t.slice(-4)}`:t}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:t(`inventory.stock`)}),remaining:({remaining:e,pct:t})=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${t>50?`bg-bambu-green`:t>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(t,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e),`g`]})]}),spool_name:({spool:e,catalogMap:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:(e.core_weight_catalog_id==null?void 0:t[e.core_weight_catalog_id])?.name||`-`}),cost_per_kg:({spool:e,currencySymbol:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.cost_per_kg==null?`-`:`${t}${e.cost_per_kg.toFixed(2)}`}),weight_check:({spool:e,onSyncWeight:t})=>{let n=e.last_scale_weight;if(n==null)return(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,title:`No scale measurement`,children:`-`});let r=e.core_weight||0,i=Math.max(0,e.label_weight-e.weight_used)+r,a,o;n0?`+${Math.round(a)}`:`${Math.round(a)}`,c=o?`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (within tolerance)`:`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (mismatch!)`;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium ${o?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,title:c,children:[(0,Y.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,Y.jsx)(w,{className:`w-3 h-3`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(B,{className:`w-3 h-3`}),t&&(0,Y.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),n.preventDefault(),t(e)},className:`p-1 hover:bg-bambu-green/20 rounded transition-colors text-bambu-green`,title:`Sync: trust scale weight and reset tracking`,children:(0,Y.jsx)(we,{className:`w-3.5 h-3.5`})})]})]})}},$n={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,last_dried:e=>e.last_dried_at||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),rgba:e=>W(e.rgba),brand:e=>(e.brand||``).toLowerCase(),slicer_filament:e=>(e.slicer_filament_name||e.slicer_filament||``).toLowerCase(),location:(e,t)=>{let n=t[e.id];if(!n)return``;let r=n.ams_id===254||n.ams_id===255,i=!r&&n.ams_id>=128,a=n.ams_label?` (${n.ams_label})`:``;return`${n.printer_name||``} ${Ce(n.ams_id,n.tray_id,i,r)}${a}`},storage_location:e=>(e.storage_location||``).toLowerCase(),label_weight:e=>e.label_weight,net:e=>Math.max(0,e.label_weight-e.weight_used),gross:e=>Math.max(0,e.label_weight-e.weight_used)+e.core_weight,used:e=>e.weight_used,remaining:e=>e.label_weight>0?Math.max(0,e.label_weight-e.weight_used)/e.label_weight:0,note:e=>(e.note||``).toLowerCase(),material_number:e=>Un(e.material_number),suppliers:e=>{let t=e.suppliers??[];return((t.find(e=>e.is_purchase_source)??t[0])?.supplier_name||``).toLowerCase()},data_origin:e=>(e.data_origin||``).toLowerCase(),tag_type:e=>(e.tag_type||``).toLowerCase(),stock:e=>+!!e.slicer_filament,spool_name:e=>e.core_weight_catalog_id??0,cost_per_kg:e=>e.cost_per_kg??0,weight_check:e=>{if(e.last_scale_weight==null)return-1;let t=Math.max(0,e.label_weight-e.weight_used)+e.core_weight;return Math.abs(e.last_scale_weight-t)},temperature:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`temperature`)?.value??-1/0,humidity:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`humidity`)?.value??-1/0,battery:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`battery`)?.value??-1/0},er=`bambuddy-inventory-sort`;function tr(){try{let e=localStorage.getItem(er);if(e)return JSON.parse(e)}catch{}return null}function nr(e){try{e?localStorage.setItem(er,JSON.stringify(e)):localStorage.removeItem(er)}catch{}}function rr(){let{data:e}=u({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,Y.jsx)(ir,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function ir({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=c(),i=Je(),a=l(),{showToast:p}=te(),{hasPermission:h,loading:g}=et(),b=!g&&h(`inventory:forecast_read`),[x,C]=Ne(),[w,E]=(0,J.useState)(null),D=(0,J.useRef)(!1),[O,A]=(0,J.useState)(null),[M,P]=(0,J.useState)(null),[L,ie]=(0,J.useState)(!1),[z,ce]=(0,J.useState)(!1),[ue,de]=(0,J.useState)(!1),[fe,pe]=(0,J.useState)(!1),[me,ge]=(0,J.useState)(`active`),[H,_e]=(0,J.useState)(`all`),[ye,xe]=(0,J.useState)(``),[Ce,we]=(0,J.useState)(``),[Ee,ke]=(0,J.useState)(``),[Ae,je]=(0,J.useState)(``),[Me,Re]=(0,J.useState)(``),[Be,He]=(0,J.useState)(``),[We,Ke]=(0,J.useState)(`all`),[Ye,Xe]=(0,J.useState)(``),[W,Ze]=(0,J.useState)(`table`),[$e,tt]=(0,J.useState)(tr),[nt,rt]=(0,J.useState)(Gn),[at,ot]=(0,J.useState)(!1),[st,ct]=(0,J.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[lt,ut]=(0,J.useState)(new Set),[G,dt]=(0,J.useState)(new Set),[ft,pt]=(0,J.useState)(!1),[K,mt]=(0,J.useState)(null),ht=(0,J.useCallback)(e=>{dt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),gt=(0,J.useCallback)(()=>dt(new Set),[]);(0,J.useEffect)(()=>{dt(new Set)},[me,H,ye,Ce,Ee,Ae,Me,Be,We,Ye]);let[_t,vt]=(0,J.useState)(0),[yt,bt]=(0,J.useState)(()=>{try{let e=localStorage.getItem(`bambuddy-inventory-pageSize`);if(e){let t=Number(e);if([15,30,50,100,-1].includes(t))return t}}catch{}return 15}),{data:xt}=u({queryKey:[`settings`],queryFn:r.getSettings}),St=xt?.date_format||`system`,Ct=(xt?.location_sensor_poll_interval||120)*1e3,{colorize:wt,aboveColor:Tt,belowColor:Et,optimalColor:Dt}=R(),Ot=e?[`spoolman-inventory-spools`]:[`inventory-spools`],kt=()=>Ie(a,Ot),{data:q,isLoading:jt}=u({queryKey:Ot,queryFn:()=>e?r.getSpoolmanInventorySpools(!0):r.getSpools(!0),refetchInterval:3e4}),Mt=(0,J.useCallback)(async()=>{ce(!0);try{await r.exportSpoolsCsv()}catch(e){p(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{ce(!1)}},[p,n]),Pt=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:Lt=[]}=u({queryKey:qe,queryFn:r.getLocations}),Rt=x.get(`location_id`),X=Rt===`__none__`?`__none__`:Rt&&/^\d+$/.test(Rt)&&Number(Rt)>0?Rt:``,Z=x.get(`spool`),zt=Z&&/^\d+$/.test(Z)&&Number(Z)>0?Number(Z):null,Bt=q?.find(e=>e.id===zt)??null,Vt=(0,J.useCallback)(()=>{D.current=!0,C(e=>(e.delete(`spool`),e),{replace:!0})},[C]),{data:Ht,isError:Ut,error:Gt}=u({queryKey:e?[`spoolman-inventory-spool`,zt]:[`inventory-spool`,zt],queryFn:()=>e?r.getSpoolmanInventorySpool(zt):r.getSpool(zt),enabled:t&&zt!==null&&Bt===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof o&&t.status===404)});(0,J.useEffect)(()=>{if(!D.current){if(t&&zt&&Bt){Vt(),E({spool:Bt,mode:`edit`});return}if(Ht){Vt(),E({spool:Ht,mode:`edit`});return}Ut&&(Vt(),p(n(Gt instanceof o&&Gt.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,zt,Bt,Ht,Ut,Gt,Vt,p,n]);let{data:Kt}=u({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),refetchInterval:3e4}),{data:qt=[],isError:Jt}=u({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),Yt=(0,J.useRef)(!1);(0,J.useEffect)(()=>{Jt&&!Yt.current?(Yt.current=!0,p(n(`inventory.spoolmanUnreachable`),`error`)):Jt||(Yt.current=!1)},[Jt,p,n]);let{data:Xt}=u({queryKey:[`spool-catalog`],queryFn:()=>r.getSpoolCatalog()}),Zt=d({mutationFn:t=>e?r.deleteSpoolmanInventorySpool(t):r.deleteSpool(t),onSuccess:()=>{kt(),p(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof o&&e.status===404?p(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof o&&e.status===503?p(n(`inventory.spoolmanUnreachable`),`error`):p(n(`inventory.deleteFailed`),`error`)}}),Qt=d({mutationFn:t=>e?r.archiveSpoolmanInventorySpool(t):r.archiveSpool(t),onSuccess:()=>{kt(),p(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof o&&e.status===404?p(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof o&&e.status===503?p(n(`inventory.spoolmanUnreachable`),`error`):p(n(`inventory.archiveFailed`),`error`)}}),$t=d({mutationFn:t=>e?r.restoreSpoolmanInventorySpool(t):r.restoreSpool(t),onSuccess:()=>{kt(),p(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof o&&e.status===404?p(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof o&&e.status===503?p(n(`inventory.spoolmanUnreachable`),`error`):p(n(`inventory.restoreFailed`),`error`)}}),en=d({mutationFn:t=>e?r.resetSpoolmanInventorySpoolConsumedCounter(t):r.resetSpoolConsumedCounter(t),onSuccess:()=>{a.invalidateQueries({queryKey:Ot}),p(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{p(n(`inventory.resetConsumedCounterFailed`),`error`)}}),tn=d({mutationFn:t=>e?r.bulkResetSpoolmanInventorySpoolConsumedCounter(t):r.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{a.invalidateQueries({queryKey:Ot}),p(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`),mt(null),gt()},onError:()=>{p(n(`inventory.resetConsumedCounterFailed`),`error`)}}),nn=e=>(e.not_found?.length??0)+(e.errors?.length??0),rn=d({mutationFn:async({ids:t,update:n})=>e?r.bulkUpdateSpoolmanInventorySpools(t,n):r.bulkUpdateSpools(t,n),onSuccess:e=>{kt();let t=nn(e);if(e.updated===0){p(n(`inventory.bulk.updateAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.updatePartial`,{ok:e.updated,failed:t}),`warning`):p(n(`inventory.bulk.updateSuccess`,{count:e.updated}),`success`),pt(!1),gt()},onError:e=>{p(e.message||n(`inventory.bulk.updateFailed`),`error`)}}),an=d({mutationFn:async t=>e?r.bulkDeleteSpoolmanInventorySpools(t):r.bulkDeleteSpools(t),onSuccess:e=>{kt();let t=nn(e);if(e.deleted===0){p(n(`inventory.bulk.deleteAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.deletePartial`,{ok:e.deleted,failed:t}),`warning`):p(n(`inventory.bulk.deleteSuccess`,{count:e.deleted}),`success`),mt(null),gt()},onError:e=>{p(e.message||n(`inventory.bulk.deleteFailed`),`error`)}}),on=d({mutationFn:async t=>e?r.bulkArchiveSpoolmanInventorySpools(t):r.bulkArchiveSpools(t),onSuccess:e=>{kt();let t=nn(e);if(e.archived===0&&t>0){p(n(`inventory.bulk.archiveAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.archivePartial`,{ok:e.archived,failed:t}),`warning`):p(n(`inventory.bulk.archiveSuccess`,{count:e.archived}),`success`),mt(null),gt()},onError:e=>{p(e.message||n(`inventory.bulk.archiveFailed`),`error`)}}),sn=d({mutationFn:async t=>e?r.bulkRestoreSpoolmanInventorySpools(t):r.bulkRestoreSpools(t),onSuccess:e=>{kt();let t=nn(e);if(e.restored===0&&t>0){p(n(`inventory.bulk.restoreAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.restorePartial`,{ok:e.restored,failed:t}),`warning`):p(n(`inventory.bulk.restoreSuccess`,{count:e.restored}),`success`),mt(null),gt()},onError:e=>{p(e.message||n(`inventory.bulk.restoreFailed`),`error`)}}),cn=(0,J.useMemo)(()=>(q??[]).map(e=>e.id),[q]),ln=async t=>{if(t.last_scale_weight!=null)try{e?await r.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await s.updateSpoolWeight(t.id,t.last_scale_weight),a.invalidateQueries({queryKey:Ot}),p(`Synced "${[t.brand,t.material,Ve(t.color_name,t.rgba,t.color_name_is_synthesized)].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof o&&e.status===404,r=e instanceof o&&e.status===503;p(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},un=xt?.low_stock_threshold??20,[dn,fn]=(0,J.useState)(!1),[pn,mn]=(0,J.useState)(un.toString());(0,J.useEffect)(()=>{dn||mn(un.toString())},[un,dn]);let hn=d({mutationFn:e=>r.updateSettings({low_stock_threshold:e}),onSuccess:()=>{a.invalidateQueries({queryKey:[`settings`]}),p(n(`common.saved`),`success`),fn(!1)},onError:()=>{p(n(`inventory.lowStockThresholdError`),`error`)}}),Q=(0,J.useMemo)(()=>{if(!q)return null;let e=0,t=0,n=0,r=0,i={};for(let a of q){if(t+=Math.max(0,a.weight_used-(a.weight_used_baseline??0)),a.archived_at)continue;r++;let o=Math.max(0,a.label_weight-a.weight_used);e+=o,(a.label_weight>0?o/a.label_weight*100:0)<(a.low_stock_threshold_pct??un)&&n++;let s=a.material||`Unknown`;i[s]||(i[s]={count:0,weight:0}),i[s].count++,i[s].weight+=o}return{totalWeight:e,totalConsumed:t,lowStock:n,byMaterial:i,totalSpools:r}},[q,un]),_n=(Kt?.length??0)+(e?qt.length:0),vn=Le(xt?.currency||`USD`),yn=(0,J.useMemo)(()=>{let e={};for(let t of Kt||[])e[t.spool_id]={printer_id:t.printer_id,printer_name:t.printer_name,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null};for(let t of qt)typeof t?.spoolman_spool_id!=`number`||t.spoolman_spool_id<=0||typeof t.printer_id!=`number`||typeof t.ams_id!=`number`||typeof t.tray_id!=`number`||e[t.spoolman_spool_id]||(e[t.spoolman_spool_id]={printer_id:t.printer_id,printer_name:t.printer_name??null,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null});return e},[Kt,qt]),bn=(0,J.useMemo)(()=>{let e={};for(let t of Xt||[])e[t.id]=t;return e},[Xt]),{data:xn}=u({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),Sn=(0,J.useMemo)(()=>new Set((xn??[]).map(e=>e.location_id)),[xn]),Cn=(0,J.useMemo)(()=>{let e=new Set;for(let t of q||[])t.location_id&&Sn.has(t.location_id)&&e.add(t.location_id);return Array.from(e)},[q,Sn]),wn=W===`cards`||W===`table`&&nt.some(e=>e.visible&&(e.id===`temperature`||e.id===`humidity`||e.id===`battery`)),Tn=f({queries:Cn.map(e=>({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>r.getLocationHASensorReadings(e,!1),refetchInterval:Ct,enabled:wn}))}),En=(0,J.useMemo)(()=>{let e={};return Cn.forEach((t,n)=>{let r=Tn[n]?.data;r&&(e[t]=r)}),e},[Cn,Tn]),Dn=(0,J.useMemo)(()=>Q?Object.entries(Q.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[Q]),On=(0,J.useMemo)(()=>{let e=q||[];if(e=me===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),H===`used`?e=e.filter(e=>e.weight_used>0):H===`new`?e=e.filter(e=>e.weight_used===0):H===`lowstock`&&(e=e.filter(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(e.label_weight>0?t/e.label_weight*100:0)<(e.low_stock_threshold_pct??un)})),ye&&(e=e.filter(e=>e.material===ye)),Ce&&(e=e.filter(e=>e.brand===Ce)),Ee&&(e=Ee===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===Ee)),Ae&&(e=Ae===Hn?e.filter(e=>!e.material_number?.trim()):e.filter(e=>e.material_number===Ae)),Me)if(Me===`__none__`)e=e.filter(e=>(e.suppliers??[]).length===0);else{let t=Number(Me);e=e.filter(e=>(e.suppliers??[]).some(e=>e.supplier_id===t))}if(Be){let t=Number(Be);e=e.filter(e=>e.core_weight_catalog_id===t)}if(X)if(X===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(X),n=Lt.find(e=>e.id===t)?.name?.trim().toLowerCase();e=e.filter(e=>e.location_id==null?n?(e.storage_location||``).trim().toLowerCase()===n:!1:e.location_id===t)}return We===`stock`?e=e.filter(e=>!e.slicer_filament):We===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),Ye&&(e=At(e,Ye)),e},[q,me,H,ye,Ce,Ee,Ae,Me,Be,We,X,Ye,un,Lt,i]),$=()=>vt(0),kn=(0,J.useCallback)(e=>{C(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),$()},[C]),An=[...new Set(q?.map(e=>e.material)||[])].sort(),Pn=[...new Set(q?.map(e=>e.brand).filter(Boolean)||[])].sort(),Fn=[...new Set(q?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),In=(q??[]).some(e=>!e.category),Vn=[...new Set(q?.map(e=>e.material_number?.trim()).filter(Boolean)||[])].sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),Un=(q??[]).some(e=>!e.material_number?.trim()),Yn=(0,J.useMemo)(()=>{let e=new Map;for(let t of q??[])for(let n of t.suppliers??[])e.set(n.supplier_id,n.supplier_name);return[...e.entries()].map(([e,t])=>({id:e,name:t})).sort((e,t)=>e.name.localeCompare(t.name))},[q]),Xn=(q??[]).some(e=>(e.suppliers??[]).length===0),Qn=[...new Set(q?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(bn[e]?.name||``).toLowerCase(),r=(bn[t]?.name||``).toLowerCase();return n.localeCompare(r)}),er=(q??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),rr=me!==`active`||H!==`all`||!!ye||!!Ce||!!Ee||!!Ae||!!Me||!!Be||!!X||We!==`all`||!!Ye,ir=e=>{rt(e),Kn(e)},sr=(0,J.useMemo)(()=>nt.filter(e=>e.visible).map(e=>e.id),[nt]),cr=e=>{$n[e]&&(tt(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},nr(n),n}),$())},lr=(0,J.useMemo)(()=>{if(!$e)return On;let e=$n[$e.column];return e?[...On].sort((t,n)=>{let r=e(t,yn,En),i=e(n,yn,En);return ri?$e.direction===`asc`?1:-1:0}):On},[On,$e,yn,En]),ur=(0,J.useMemo)(()=>{if(!st)return lr.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of lr)if(!(t.weight_used>0||yn[t.id])){let n=Bn(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of lr){if(r.weight_used>0||yn[r.id]){t.push({type:`single`,spool:r});continue}let i=Bn(r);if(n.has(i))continue;n.add(i);let a=e.get(i);a.length===1?t.push({type:`single`,spool:a[0]}):t.push({type:`group`,key:i,spools:a,representative:a[0]})}return t},[lr,st,yn]),dr=yt===-1,hr=ur.length,gr=dr?hr||1:yt,_r=Math.max(1,Math.ceil(hr/gr)),vr=dr?0:Math.min(_t,_r-1),yr=dr?ur:ur.slice(vr*gr,(vr+1)*gr),br=()=>{let e=!st;ct(e),ut(new Set),$();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},xr=e=>{ut(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Sr=e=>{bt(e),vt(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,Y.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,Y.jsx)(oe,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(V,{variant:`secondary`,disabled:e,onClick:()=>ie(!0),title:Pt,children:[(0,Y.jsx)(Ge,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,Y.jsxs)(V,{variant:`secondary`,disabled:e||z,onClick:Mt,title:Pt,children:[z?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Qe,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>de(!0),children:[(0,Y.jsx)(ae,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>pe(!0),children:[(0,Y.jsx)(Ft,{className:`w-4 h-4`}),n(`inventory.suppliers.title`)]}),(0,Y.jsxs)(V,{variant:`secondary`,disabled:On.length===0,onClick:()=>P(G.size>0?[...G]:On.map(e=>e.id)),title:On.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):G.size>0?n(`inventory.labels.selectedTitle`,`Print labels for the {{count}} selected spools`,{count:G.size}):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:On.length}),children:[(0,Y.jsx)(U,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,Y.jsxs)(V,{onClick:()=>E({spool:null,mode:`create`}),children:[(0,Y.jsx)(Pe,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),Q&&!jt&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(oe,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold text-white`,children:qn(Q.totalWeight,!0)}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[Q.totalSpools,` `,Q.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(le,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),Q.totalConsumed>0&&cn.length>0&&(0,Y.jsx)(`button`,{onClick:()=>A({type:`reset-all-consumed-counters`}),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:n(`inventory.resetAllConsumedCountersTooltip`),"aria-label":n(`inventory.resetAllConsumedCounters`),children:(0,Y.jsx)(S,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold text-white`,children:qn(Q.totalConsumed,!0)}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(ze,{className:`w-4 h-4 text-green-600 dark:text-green-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:Dn.map(([e,t])=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${Jn[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,Y.jsx)(`span`,{className:`opacity-70`,children:qn(t.weight,!0)})]},e))})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(U,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold text-white`,children:_n}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(B,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold ${Q.lowStock>0?`text-yellow-700 dark:text-yellow-400`:`text-white`}`,children:Q.lowStock}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:dn?(0,Y.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(pn);!isNaN(t)&&t>=.1&&t<=99.9?hn.mutate(t):p(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,Y.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:pn,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&mn(t)},className:`px-1.5 py-1 rounded border border-bambu-dark-tertiary text-xs text-white bg-bambu-dark-secondary focus:outline-none focus:border-bambu-green w-14 text-center`,onWheel:e=>e.currentTarget.blur(),disabled:hn.isPending}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,Y.jsx)(V,{type:`submit`,size:`sm`,disabled:hn.isPending,children:n(`common.save`)}),(0,Y.jsx)(V,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>fn(!1),disabled:hn.isPending,children:n(`common.cancel`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,un,`%`]}),(0,Y.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{mn(un.toString()),fn(!0)},children:(0,Y.jsx)(I,{className:`w-4 h-4`})})]})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 max-w-md ${W===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,Y.jsx)(se,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,Y.jsx)(`input`,{type:`text`,value:Ye,onChange:e=>{Xe(e.target.value),$()},placeholder:n(`inventory.search`),className:`w-full pl-10 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),Ye&&(0,Y.jsx)(`button`,{onClick:()=>{Xe(``),$()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[W===`table`&&(0,Y.jsxs)(`button`,{onClick:()=>ot(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-bambu-gray border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,title:n(`inventory.configureColumns`),children:[(0,Y.jsx)(j,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),W!==`forecast`&&(0,Y.jsxs)(`button`,{onClick:br,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${st?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,title:n(`inventory.groupSimilar`),children:[(0,Y.jsx)(Nt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,Y.jsxs)(`button`,{onClick:()=>Ze(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${W===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(It,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>Ze(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${W===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>b&&Ze(`forecast`),disabled:!b,title:b?void 0:n(`forecast.noReadAccess`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${W===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[b?(0,Y.jsx)(m,{className:`w-4 h-4`}):(0,Y.jsx)(ne,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${W===`forecast`?`hidden`:``}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{ge(`active`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${me===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(oe,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,Y.jsxs)(`button`,{onClick:()=>{ge(`archived`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${me===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(Te,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,Y.jsx)(`button`,{onClick:()=>{_e(`all`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,Y.jsxs)(`button`,{onClick:()=>{_e(`used`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${H===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(Oe,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,Y.jsx)(`button`,{onClick:()=>{_e(`new`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,Y.jsxs)(`button`,{onClick:()=>{_e(`lowstock`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${H===`lowstock`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(B,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,Y.jsx)(`button`,{onClick:()=>{Ke(`all`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${We===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,Y.jsx)(`button`,{onClick:()=>{Ke(`stock`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${We===`stock`?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.stock`)}),(0,Y.jsx)(`button`,{onClick:()=>{Ke(`configured`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${We===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,Y.jsxs)(`select`,{value:ye,onChange:e=>{xe(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${ye?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.material`)}),An.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`select`,{value:Ce,onChange:e=>{we(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ce?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),Pn.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(Fn.length>0||Ee)&&(0,Y.jsxs)(`select`,{value:Ee,onChange:e=>{ke(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ee?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.category`)}),Fn.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),In&&(0,Y.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),(Vn.length>0||Ae)&&(0,Y.jsxs)(`select`,{value:Ae,onChange:e=>{je(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ae?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.materialNumber`)}),Vn.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),Un&&(0,Y.jsx)(`option`,{value:Hn,children:n(`inventory.materialNumberNone`)})]}),(Yn.length>0||Me)&&(0,Y.jsxs)(`select`,{value:Me,onChange:e=>{Re(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Me?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.suppliers.label`)}),Yn.map(e=>(0,Y.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),Xn&&(0,Y.jsx)(`option`,{value:`__none__`,children:n(`inventory.suppliers.none`)})]}),Qn.length>0&&(0,Y.jsxs)(`select`,{value:Be,onChange:e=>{He(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Be?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),Qn.map(e=>(0,Y.jsx)(`option`,{value:e,children:bn[e]?.name||`#${e}`},e))]}),(Lt.length>0||X)&&(0,Y.jsxs)(`select`,{value:X,onChange:e=>{kn(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${X?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),Lt.map(e=>(0,Y.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),er&&(0,Y.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),rr&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,Y.jsxs)(`button`,{onClick:()=>{ge(`active`),_e(`all`),xe(``),we(``),ke(``),je(``),Re(``),He(``),Ke(`all`),Xe(``),C(e=>(e.delete(`location_id`),e),{replace:!0}),$()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,Y.jsx)(he,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),W!==`forecast`&&(0,Y.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[lr.length,` `,lr.length===1?n(`inventory.spool`):n(`inventory.spools`),st&&hr0&&W!==`forecast`&&(0,Y.jsxs)(`div`,{className:`sticky top-2 z-10 mb-4 flex items-center gap-2 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg backdrop-blur-sm`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-green font-medium`,children:n(`inventory.bulk.selectionCount`,{count:G.size})}),(0,Y.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>pt(!0),children:[(0,Y.jsx)(I,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.edit`)]}),(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>P([...G]),children:[(0,Y.jsx)(U,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.printLabels`)]}),(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>mt(`reset-consumed-counter`),children:[(0,Y.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.resetUsage`)]}),me===`archived`?(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>mt(`restore`),children:[(0,Y.jsx)(Se,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.restore`)]}):(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>mt(`archive`),children:[(0,Y.jsx)(Te,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.archive`)]}),(0,Y.jsxs)(V,{size:`sm`,variant:`danger`,onClick:()=>mt(`delete`),children:[(0,Y.jsx)(be,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.delete`)]}),(0,Y.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,onClick:gt,title:n(`inventory.bulk.clearSelection`),"aria-label":n(`inventory.bulk.clearSelection`),children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]})]}),jt?(0,Y.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,Y.jsx)(F,{className:`w-8 h-8 text-bambu-green animate-spin`})}):W===`forecast`?(0,Y.jsx)(Wt,{spools:q||[]}):W===`cards`?yr.length>0?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:yr.map(e=>{if(e.type===`group`){let{key:t,spools:r,representative:i}=e,a=r.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),o=ve({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=lt.has(t);return(0,Y.jsxs)(`div`,{className:`col-span-full`,children:[(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-green/30 hover:border-bambu-green transition-colors cursor-pointer`,onClick:()=>xr(t),children:[(0,Y.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,Y.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Ve(i.color_name,i.rgba,i.color_name_is_synthesized)||`-`})}),(0,Y.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(T,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:qn(a)}),(0,Y.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:n(`inventory.groupedSpools`,{count:r.length})})]})]})]}),s&&(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mt-2 ml-4`,children:r.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,Y.jsx)(or,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>E({spool:e,mode:`edit`}),onPrintLabel:()=>P([e.id]),onCopy:()=>E({spool:e,mode:`copy`}),t:n,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt,dateFormat:St},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,Y.jsx)(or,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>E({spool:t,mode:`edit`}),onPrintLabel:()=>P([t.id]),onCopy:()=>E({spool:t,mode:`copy`}),t:n,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt,dateFormat:St},t.id)})}),(0,Y.jsx)(ar,{pageIndex:vr,pageSize:yt,totalRows:hr,totalPages:_r,onPageChange:vt,onPageSizeChange:Sr,t:n})]}):(0,Y.jsx)(mr,{hasFilters:rr,onAddSpool:()=>E({spool:null,mode:`create`}),t:n}):yr.length>0?(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`w-10 px-3 py-3`,children:(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":n(`inventory.bulk.selectAllVisible`),checked:yr.length>0&&yr.every(e=>(e.type===`group`?e.spools.map(e=>e.id):[e.spool.id]).every(e=>G.has(e))),onChange:e=>{if(e.target.checked){let e=new Set(G);for(let t of yr){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.add(t)}dt(e)}else{let e=new Set(G);for(let t of yr){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.delete(t)}dt(e)}}})}),sr.map(e=>{let t=!!$n[e],r=$e?.column===e;return(0,Y.jsx)(`th`,{className:`text-left py-3 px-4 text-xs font-medium uppercase tracking-wide select-none ${e===`remaining`?`min-w-[150px]`:``} ${t?`cursor-pointer hover:text-bambu-green transition-colors`:``} ${r?`text-bambu-green`:`text-bambu-gray`}`,onClick:t?()=>cr(e):void 0,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[Zn[e]?.(n)??e,t&&(r?$e.direction===`asc`?(0,Y.jsx)(y,{className:`w-3 h-3`}):(0,Y.jsx)(_,{className:`w-3 h-3`}):(0,Y.jsx)(v,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,Y.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,Y.jsx)(`tbody`,{children:yr.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=lt.has(t),a=Rn(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,Y.jsx)(pr,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>xr(t),selectedIds:G,onToggleSelected:ht,onToggleGroupSelected:(e,t)=>{dt(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r})},onEdit:e=>E({spool:e,mode:`edit`}),onCopy:e=>E({spool:e,mode:`copy`}),onArchive:e=>A({type:`archive`,spoolId:e}),onDelete:e=>A({type:`delete`,spoolId:e}),onPrintLabel:e=>P([e]),onResetConsumedCounter:e=>A({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:sr,assignmentMap:yn,catalogMap:bn,locationReadingsMap:En,currencySymbol:vn,dateFormat:St,t:n,onSyncWeight:ln,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,Y.jsx)(fr,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,isSelected:G.has(t.id),onToggleSelected:()=>ht(t.id),onEdit:()=>E({spool:t,mode:`edit`}),onCopy:()=>E({spool:t,mode:`copy`}),onRestore:()=>$t.mutate(t.id),onArchive:()=>A({type:`archive`,spoolId:t.id}),onDelete:()=>A({type:`delete`,spoolId:t.id}),onPrintLabel:()=>P([t.id]),onResetConsumedCounter:()=>A({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:sr,assignmentMap:yn,catalogMap:bn,locationReadingsMap:En,currencySymbol:vn,dateFormat:St,t:n,onSyncWeight:ln,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt},t.id)})})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-bambu-dark-tertiary/50 border-t border-bambu-dark-tertiary text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:dr?`${hr} ${n(hr===1?`inventory.spool`:`inventory.spools`)}`:(0,Y.jsxs)(Y.Fragment,{children:[n(`inventory.showing`),` `,vr*gr+1,` `,n(`inventory.to`),` `,Math.min((vr+1)*gr,hr),` `,n(`inventory.of`),` `,hr,` `,n(`inventory.spools`)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,Y.jsxs)(`select`,{value:yt,onChange:e=>Sr(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),(0,Y.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!dr&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>vt(0),disabled:vr===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`First page`,children:(0,Y.jsx)(ee,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>vt(e=>Math.max(0,e-1)),disabled:vr===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(Ue,{className:`w-4 h-4`})}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,vr+1,` `,n(`inventory.of`),` `,_r]}),(0,Y.jsx)(`button`,{onClick:()=>vt(e=>Math.min(_r-1,e+1)),disabled:vr>=_r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(De,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>vt(_r-1),disabled:vr>=_r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`Last page`,children:(0,Y.jsx)(k,{className:`w-4 h-4`})})]})]})]})]}):(0,Y.jsx)(mr,{hasFilters:rr,onAddSpool:()=>E({spool:null,mode:`create`}),t:n}),w!==null&&(0,Y.jsx)(gn,{isOpen:!0,onClose:()=>E(null),spool:w.spool,mode:w.mode,currencySymbol:vn,spoolmanMode:e,spoolsQueryKey:Ot}),O&&(0,Y.jsx)(Fe,{title:O.type===`delete`?n(`common.delete`):O.type===`archive`?n(`inventory.archive`):O.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:O.type===`delete`?n(`inventory.deleteConfirm`):O.type===`archive`?n(`inventory.archiveConfirm`):O.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:cn.length}),confirmText:O.type===`delete`?n(`common.delete`):O.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:O.type===`archive`?`warning`:`danger`,onConfirm:()=>{O.type===`delete`?Zt.mutate(O.spoolId):O.type===`archive`?Qt.mutate(O.spoolId):O.type===`reset-consumed-counter`?en.mutate(O.spoolId):tn.mutate(cn),A(null)},onCancel:()=>A(null)}),(0,Y.jsx)(it,{isOpen:at,onClose:()=>ot(!1),columns:nt,defaultColumns:Wn,onSave:ir}),(0,Y.jsx)(jn,{isOpen:M!==null,onClose:()=>P(null),availableSpools:On,initialSelectedIds:M??[],spoolmanMode:e}),(0,Y.jsx)(Ln,{isOpen:ft,selectedCount:G.size,isPending:rn.isPending,availableLocations:Lt.map(e=>({id:e.id,name:e.name})),availableMaterials:zn((q??[]).map(e=>e.material)),availableSubtypes:zn((q??[]).map(e=>e.subtype)),availableBrands:zn((q??[]).map(e=>e.brand)),availableCategories:zn((q??[]).map(e=>e.category)),availableMaterialNumbers:zn((q??[]).map(e=>e.material_number)),availableSlicerFilaments:zn((q??[]).map(e=>e.slicer_filament)),availableSlicerFilamentNames:zn((q??[]).map(e=>e.slicer_filament_name)),spoolmanMode:e,onClose:()=>pt(!1),onApply:e=>rn.mutate({ids:[...G],update:e})}),K&&(0,Y.jsx)(Fe,{title:n(K===`delete`?`inventory.bulk.deleteTitle`:K===`archive`?`inventory.bulk.archiveTitle`:K===`restore`?`inventory.bulk.restoreTitle`:`inventory.bulk.resetUsageTitle`),message:n(K===`delete`?`inventory.bulk.deleteMessage`:K===`archive`?`inventory.bulk.archiveMessage`:K===`restore`?`inventory.bulk.restoreMessage`:`inventory.bulk.resetUsageMessage`,{count:G.size}),confirmText:n(K===`delete`?`common.delete`:K===`archive`?`inventory.archive`:K===`restore`?`inventory.restore`:`inventory.resetConsumedCounter`),variant:K===`delete`?`danger`:`warning`,isLoading:an.isPending||on.isPending||sn.isPending||tn.isPending,onConfirm:()=>{let e=[...G];K===`delete`?an.mutate(e):K===`archive`?on.mutate(e):K===`restore`?sn.mutate(e):tn.mutate(e)},onCancel:()=>mt(null)}),L&&(0,Y.jsx)(Mn,{onClose:()=>ie(!1),onImported:e=>{ie(!1),a.invalidateQueries({queryKey:Ot}),p(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,Y.jsx)(re,{open:ue,onClose:()=>de(!1),onPickLocation:e=>kn(String(e))}),(0,Y.jsx)(Nn,{open:fe,onClose:()=>pe(!1)})]})}function ar({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,Y.jsxs)(Y.Fragment,{children:[o(`inventory.showing`),` `,e*c+1,` `,o(`inventory.to`),` `,Math.min((e+1)*c,n),` `,o(`inventory.of`),` `,n,` `,o(`inventory.spools`)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,Y.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),(0,Y.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(ee,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(Ue,{className:`w-4 h-4`})}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,Y.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(De,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(k,{className:`w-4 h-4`})})]})]})]})}function or({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o,colorizeLocationSensors:s,locationSensorAboveColor:c,locationSensorBelowColor:l,locationSensorOptimalColor:u,dateFormat:d}){let f=ve({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``}`,onClick:r,children:[(0,Y.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:f,children:[(0,Y.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Ve(e.color_name,e.rgba,e.color_name_is_synthesized)||`-`}),a&&(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`p-1.5 bg-black/20 hover:bg-black/40 text-white rounded-full transition-colors`,title:o(`inventory.copySpool`),children:(0,Y.jsx)(M,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,Y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),i()},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,title:o(`inventory.labels.printOne`),"aria-label":o(`inventory.labels.printOne`),children:(0,Y.jsx)(U,{className:`w-4 h-4`})}),(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,Y.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,Y.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[e.last_dried_at&&(0,Y.jsxs)(`div`,{className:`col-span-2`,children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.lastDried`),`: `]}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:[Xn(e.last_dried_at,d),Yn(e)].filter(Boolean).join(` · `)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:qn(e.label_weight)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?qn(e.weight_used):`-`})]})]}),e.location_id&&(0,Y.jsx)(dr,{locationId:e.location_id,locationName:e.storage_location??null,isLast:!e.note,colorize:s,aboveColor:c,belowColor:l,optimalColor:u}),e.note&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-3 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}var sr={temperature:0,humidity:1,battery:2};function cr(e){return e===`humidity`?`mr-[2px]`:e===`battery`?`mr-[3px]`:``}function lr(e,t){return h(e,t,{decimals:2})}function ur(e,t,n,r,i){return t&&L(ie(e),n,r,i)||`text-bambu-gray`}function dr({locationId:e,locationName:t,isLast:n,colorize:i,aboveColor:a,belowColor:o,optimalColor:s}){let{t:l}=c(),{data:d}=u({queryKey:[`settings`],queryFn:r.getSettings}),f=(d?.location_sensor_poll_interval||120)*1e3,{data:p}=u({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),m=(p??[]).some(t=>t.location_id===e),{data:h}=u({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>r.getLocationHASensorReadings(e,!1),refetchInterval:f,enabled:m}),_=h?.filter(e=>e.show_on_card);if(!_?.length)return null;let v=_.find(e=>e.device_class===`battery`),y=_.filter(e=>e.device_class!==`battery`).sort((e,t)=>(sr[e.device_class??``]??99)-(sr[t.device_class??``]??99));return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-3 border-t border-bambu-dark-tertiary text-xs text-bambu-gray ${n?`-mb-1`:``}`,children:[t&&(0,Y.jsx)(`span`,{className:`truncate`,children:t}),(0,Y.jsx)(`span`,{className:`text-bambu-gray/40`,children:`|`}),(0,Y.jsx)(`div`,{className:`flex items-center gap-3`,children:y.map((e,t)=>{let n=g(e),r=t===0?`ml-[-3.6px]`:``;return(0,Y.jsxs)(`span`,{title:e.name,className:`flex items-center gap-[3px]`,children:[(0,Y.jsx)(n,{className:`w-3 h-3 ${cr(e.device_class)} ${r}`}),(0,Y.jsx)(`span`,{className:ur(e,i,a,o,s),children:lr(e,l)})]},e.id)})}),v&&(()=>{let e=g(v);return(0,Y.jsxs)(`span`,{title:v.name,className:`flex items-center gap-[3px] ml-auto`,children:[(0,Y.jsx)(e,{className:`w-3 h-3 ${cr(v.device_class)}`}),(0,Y.jsx)(`span`,{className:ur(v,i,a,o,s),children:lr(v,l)})]},v.id)})()]})}function fr({spool:e,remaining:t,pct:n,isSelected:r,onToggleSelected:i,onEdit:a,onCopy:o,onRestore:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:C,locationSensorOptimalColor:w}){return(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``} ${r?`bg-bambu-green/10`:``}`,onClick:a,children:[(0,Y.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:i&&(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectRow`),checked:!!r,onChange:i})}),f.map(r=>(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:Qn[r]?.({spool:e,remaining:t,pct:n,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:C,locationSensorOptimalColor:w})},r)),(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`common.edit`),children:(0,Y.jsx)(I,{className:`w-4 h-4`})}),o&&(0,Y.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.copySpool`),children:(0,Y.jsx)(M,{className:`w-4 h-4`})}),u&&(0,Y.jsx)(`button`,{onClick:u,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`inventory.labels.printOne`),children:(0,Y.jsx)(U,{className:`w-4 h-4`})}),d&&e.weight_used>0&&(0,Y.jsx)(`button`,{onClick:d,className:`p-1.5 text-bambu-gray hover:text-orange-600 dark:hover:text-orange-400 rounded transition-colors`,title:v(`inventory.resetConsumedCounterTooltip`),children:(0,Y.jsx)(S,{className:`w-4 h-4`})}),e.archived_at?(0,Y.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.restore`),children:(0,Y.jsx)(Se,{className:`w-4 h-4`})}):(0,Y.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 rounded transition-colors`,title:v(`inventory.archive`),children:(0,Y.jsx)(Te,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:v(`common.delete`),children:(0,Y.jsx)(be,{className:`w-4 h-4`})})]})})]})}function pr({spools:e,headerSpool:t,remaining:n,pct:r,isExpanded:i,onToggle:a,onEdit:o,onCopy:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C,selectedIds:w,onToggleSelected:E,onToggleGroupSelected:D}){let O=!!w&&e.every(e=>w.has(e.id));return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer bg-bambu-green/5`,onClick:a,children:[(0,Y.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:D&&(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectGroup`),checked:O,onChange:t=>D(e.map(e=>e.id),t.target.checked)})}),f.map((a,o)=>(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(T,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),Qn[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})]}):a===`id`?(0,Y.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:v(`inventory.groupedSpools`,{count:e.length})}):Qn[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})},a)),(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.map(e=>`#${e.id}`).join(`, `)})})]}),i&&e.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,Y.jsx)(fr,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,isSelected:w?.has(e.id),onToggleSelected:E?()=>E(e.id):void 0,onEdit:()=>o(e),onCopy:s?()=>s(e):void 0,onRestore:()=>{},onArchive:()=>c(e.id),onDelete:()=>l(e.id),onPrintLabel:u?()=>u(e.id):void 0,onResetConsumedCounter:d?()=>d(e.id):void 0,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C},e.id)})]})}function mr({hasFilters:e,onAddSpool:t,t:n}){return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,Y.jsxs)(`div`,{className:`relative mb-6`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,Y.jsxs)(`div`,{className:`relative flex items-center justify-center w-24 h-24 rounded-2xl bg-gradient-to-br from-bambu-dark-secondary to-bambu-dark-tertiary border border-bambu-dark-tertiary shadow-lg`,children:[(0,Y.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,Y.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,Y.jsx)(se,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,Y.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,Y.jsx)(`div`,{className:`absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-bambu-green flex items-center justify-center shadow-md`,children:(0,Y.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,Y.jsxs)(V,{onClick:t,children:[(0,Y.jsx)(oe,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}export{rr as default};
\ No newline at end of file
diff --git a/static/assets/LibraryTrashPage-C41Ue4qA.js b/static/assets/LibraryTrashPage-ULJ14l58.js
similarity index 99%
rename from static/assets/LibraryTrashPage-C41Ue4qA.js
rename to static/assets/LibraryTrashPage-ULJ14l58.js
index 53be3bdab..47dca904c 100644
--- a/static/assets/LibraryTrashPage-C41Ue4qA.js
+++ b/static/assets/LibraryTrashPage-ULJ14l58.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as c}from"./arrow-left-MSgMxOFV.js";import{n as l}from"./ToastContext-VFOrCCoA.js";import{t as u}from"./loader-circle-CB4leTZa.js";import{t as d}from"./file-DDkFXH-b.js";import{t as f}from"./Button-pwVKPiYn.js";import{v as p}from"./date-G9KUauqz.js";import{At as m,Gt as h,Rn as g,Ut as _,Vn as v,_t as y,yt as b}from"./index-Bw-_P2Fg.js";var x=e(n(),1),S=t();function C(e){let t=p(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function w(e){let t=p(e);return t?t.toLocaleString():e}function T(){let{t:e}=i(),t=v(),n=a(),{showToast:p}=l(),{hasPermission:T,authEnabled:E}=b(),[D,O]=(0,x.useState)(null),[k,A]=(0,x.useState)(new Set),j=!E||T(`library:purge`),M=o({queryKey:[`library-trash`],queryFn:()=>r.listLibraryTrash(200,0)}),N=o({queryKey:[`library-trash-settings`],queryFn:()=>r.getLibraryTrashSettings(),enabled:j}),[P,F]=(0,x.useState)(null);(0,x.useEffect)(()=>{N.data&&P===null&&F(N.data.retention_days)},[N.data,P]);let I=s({mutationFn:e=>{let t=N.data;return r.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{p(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>p(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),L=s({mutationFn:e=>r.restoreLibraryTrash(e),onSuccess:()=>{p(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>p(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),R=s({mutationFn:e=>r.hardDeleteLibraryTrash(e),onSuccess:()=>{p(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),z=s({mutationFn:()=>r.emptyLibraryTrash(),onSuccess:t=>{p(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),B=s({mutationFn:e=>Promise.all(e.map(e=>r.restoreLibraryTrash(e))),onSuccess:(t,r)=>{p(e(`libraryTrash.toast.bulkRestored`,{count:r.length}),`success`),A(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>p(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),V=s({mutationFn:e=>Promise.all(e.map(e=>r.hardDeleteLibraryTrash(e))),onSuccess:(t,r)=>{p(e(`libraryTrash.toast.bulkPurged`,{count:r.length}),`success`),A(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),H=(0,x.useMemo)(()=>M.data?.items??[],[M.data?.items]),U=M.data?.retention_days??30,W=(0,x.useMemo)(()=>H.reduce((e,t)=>e+t.file_size,0),[H]),G=H.length>0&&H.every(e=>k.has(e.id)),K=k.size>0&&!G,q=e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,S.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,S.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,S.jsxs)(g,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,S.jsx)(c,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,S.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(j?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:U})})]}),H.length>0&&(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>O({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,S.jsx)(m,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),j&&N.data&&(0,S.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,S.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,S.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:P??N.data.retention_days,onChange:e=>F(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,S.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>P!=null&&I.mutate(P),disabled:I.isPending||P==null||P===N.data.retention_days,className:`ml-auto`,children:[(0,S.jsx)(_,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),M.isLoading?(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,S.jsx)(u,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):H.length===0?(0,S.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,S.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,S.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:H.length,size:d(W)})}),k.size>0&&(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,S.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:k.size})}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>B.mutate(Array.from(k)),disabled:B.isPending,children:[(0,S.jsx)(h,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>O({type:`bulkDelete`,count:k.size}),disabled:V.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,S.jsx)(m,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,S.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,S.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:G,ref:e=>{e&&(e.indeterminate=K)},onChange:()=>{A(e=>e.size===H.length?new Set:new Set(H.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),j&&(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,S.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:H.map(t=>(0,S.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,S.jsx)(`td`,{className:`px-3 py-2`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:k.has(t.id),onChange:()=>q(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:d(t.file_size)}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:w(t.deleted_at)}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,S.jsx)(`span`,{title:w(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:C(t.auto_purge_at)})})}),j&&(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,S.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,S.jsxs)(`button`,{onClick:()=>L.mutate(t.id),disabled:L.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,S.jsx)(h,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,S.jsxs)(`button`,{onClick:()=>O({type:`delete`,id:t.id,filename:t.filename}),disabled:R.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,S.jsx)(m,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),D&&(0,S.jsx)(y,{onCancel:()=>O(null),onConfirm:()=>{D&&(D.type===`delete`?R.mutate(D.id):D.type===`bulkDelete`?V.mutate(Array.from(k)):z.mutate(),O(null))},title:D.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):D.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:D.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:D.filename}):D.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:D.count}):e(`libraryTrash.confirm.emptyBody`,{count:H.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),M.isError&&(0,S.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[M.error?.message??e(`libraryTrash.loadError`),(0,S.jsx)(f,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}export{T as LibraryTrashPage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as c}from"./arrow-left-MSgMxOFV.js";import{n as l}from"./ToastContext-VFOrCCoA.js";import{t as u}from"./loader-circle-CB4leTZa.js";import{t as d}from"./file-DDkFXH-b.js";import{t as f}from"./Button-pwVKPiYn.js";import{v as p}from"./date-G9KUauqz.js";import{At as m,Gt as h,Rn as g,Ut as _,Vn as v,_t as y,yt as b}from"./index-ggB_TpPo.js";var x=e(n(),1),S=t();function C(e){let t=p(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function w(e){let t=p(e);return t?t.toLocaleString():e}function T(){let{t:e}=i(),t=v(),n=a(),{showToast:p}=l(),{hasPermission:T,authEnabled:E}=b(),[D,O]=(0,x.useState)(null),[k,A]=(0,x.useState)(new Set),j=!E||T(`library:purge`),M=o({queryKey:[`library-trash`],queryFn:()=>r.listLibraryTrash(200,0)}),N=o({queryKey:[`library-trash-settings`],queryFn:()=>r.getLibraryTrashSettings(),enabled:j}),[P,F]=(0,x.useState)(null);(0,x.useEffect)(()=>{N.data&&P===null&&F(N.data.retention_days)},[N.data,P]);let I=s({mutationFn:e=>{let t=N.data;return r.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{p(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>p(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),L=s({mutationFn:e=>r.restoreLibraryTrash(e),onSuccess:()=>{p(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>p(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),R=s({mutationFn:e=>r.hardDeleteLibraryTrash(e),onSuccess:()=>{p(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),z=s({mutationFn:()=>r.emptyLibraryTrash(),onSuccess:t=>{p(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),B=s({mutationFn:e=>Promise.all(e.map(e=>r.restoreLibraryTrash(e))),onSuccess:(t,r)=>{p(e(`libraryTrash.toast.bulkRestored`,{count:r.length}),`success`),A(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>p(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),V=s({mutationFn:e=>Promise.all(e.map(e=>r.hardDeleteLibraryTrash(e))),onSuccess:(t,r)=>{p(e(`libraryTrash.toast.bulkPurged`,{count:r.length}),`success`),A(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),H=(0,x.useMemo)(()=>M.data?.items??[],[M.data?.items]),U=M.data?.retention_days??30,W=(0,x.useMemo)(()=>H.reduce((e,t)=>e+t.file_size,0),[H]),G=H.length>0&&H.every(e=>k.has(e.id)),K=k.size>0&&!G,q=e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,S.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,S.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,S.jsxs)(g,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,S.jsx)(c,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,S.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(j?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:U})})]}),H.length>0&&(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>O({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,S.jsx)(m,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),j&&N.data&&(0,S.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,S.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,S.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:P??N.data.retention_days,onChange:e=>F(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,S.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>P!=null&&I.mutate(P),disabled:I.isPending||P==null||P===N.data.retention_days,className:`ml-auto`,children:[(0,S.jsx)(_,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),M.isLoading?(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,S.jsx)(u,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):H.length===0?(0,S.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,S.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,S.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:H.length,size:d(W)})}),k.size>0&&(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,S.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:k.size})}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>B.mutate(Array.from(k)),disabled:B.isPending,children:[(0,S.jsx)(h,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>O({type:`bulkDelete`,count:k.size}),disabled:V.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,S.jsx)(m,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,S.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,S.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:G,ref:e=>{e&&(e.indeterminate=K)},onChange:()=>{A(e=>e.size===H.length?new Set:new Set(H.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),j&&(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,S.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:H.map(t=>(0,S.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,S.jsx)(`td`,{className:`px-3 py-2`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:k.has(t.id),onChange:()=>q(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:d(t.file_size)}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:w(t.deleted_at)}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,S.jsx)(`span`,{title:w(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:C(t.auto_purge_at)})})}),j&&(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,S.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,S.jsxs)(`button`,{onClick:()=>L.mutate(t.id),disabled:L.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,S.jsx)(h,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,S.jsxs)(`button`,{onClick:()=>O({type:`delete`,id:t.id,filename:t.filename}),disabled:R.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,S.jsx)(m,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),D&&(0,S.jsx)(y,{onCancel:()=>O(null),onConfirm:()=>{D&&(D.type===`delete`?R.mutate(D.id):D.type===`bulkDelete`?V.mutate(Array.from(k)):z.mutate(),O(null))},title:D.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):D.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:D.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:D.filename}):D.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:D.count}):e(`libraryTrash.confirm.emptyBody`,{count:H.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),M.isError&&(0,S.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[M.error?.message??e(`libraryTrash.loadError`),(0,S.jsx)(f,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}export{T as LibraryTrashPage};
\ No newline at end of file
diff --git a/static/assets/LoginPage-YsL4u_Va.js b/static/assets/LoginPage-DuZTbhAO.js
similarity index 99%
rename from static/assets/LoginPage-YsL4u_Va.js
rename to static/assets/LoginPage-DuZTbhAO.js
index 9e4353a61..051c52346 100644
--- a/static/assets/LoginPage-YsL4u_Va.js
+++ b/static/assets/LoginPage-DuZTbhAO.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./useQuery-CCy0EwsM.js";import{t as o}from"./useMutation-qh3Iyscy.js";import{n as s}from"./ToastContext-VFOrCCoA.js";import{t as ee}from"./shield-CfkeOiiL.js";import{t as te}from"./smartphone-DOKM2tP4.js";import{t as ne}from"./x-Dctff5l9.js";import{i as re,n as ie,t as ae}from"./Card-OUAj0Ayh.js";import{t as c}from"./Button-pwVKPiYn.js";import{Bn as oe,Vn as se,Wn as ce,in as le,ln as ue,vt as de,yt as fe}from"./index-Bw-_P2Fg.js";var l=e(n(),1),u=t(),d=`auth_remember_me`,f=`auth_post_login_redirect`;function p(e){return e?`persistent`:`session`}function pe(){try{let e=sessionStorage.getItem(d)===`1`;return sessionStorage.removeItem(d),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function m(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function h(e){let t=m(e);if(t)try{sessionStorage.setItem(f,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function me(){try{let e=sessionStorage.getItem(f);return sessionStorage.removeItem(f),m(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function he({provider:e,onClick:t,disabled:n}){let{t:a}=i(),[o,s]=(0,l.useState)(!1);return(0,u.jsxs)(`button`,{type:`button`,onClick:t,disabled:n,className:`w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50`,children:[e.has_icon&&!o?(0,u.jsx)(`img`,{src:r.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>s(!0)}):(0,u.jsx)(ee,{className:`w-5 h-5 text-bambu-green`}),a(`login.twoFA.signInWith`,{provider:e.name})]})}function g(){let e=se(),t=oe(),[n]=ce(),{t:f}=i(),{login:g,loginWithToken:_,user:v,loading:ge}=fe(),{showToast:y}=s(),{mode:_e}=de();function b(){let e=t.state?.from;if(e?.pathname){let t=m(`${e.pathname}${e.search??``}`);if(t)return t}return me()??`/`}let[x,ve]=(0,l.useState)(``),[S,ye]=(0,l.useState)(``),[be,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)(``),[E,D]=(0,l.useState)(`credentials`),[O,k]=(0,l.useState)(``),[A,j]=(0,l.useState)([]),[M,N]=(0,l.useState)(`totp`),[P,F]=(0,l.useState)(``),[I,L]=(0,l.useState)(!1),xe=(0,l.useRef)(null),[R,z]=(0,l.useState)(!1),[Se,B]=(0,l.useState)(``),[V,H]=(0,l.useState)(``),[U,W]=(0,l.useState)(``),{data:G}=a({queryKey:[`advancedAuthStatus`],queryFn:()=>r.getAdvancedAuthStatus()}),{data:K}=a({queryKey:[`oidcProviders`],queryFn:()=>r.getOIDCProviders()}),[Ce,we]=(0,l.useState)(!1);(0,l.useEffect)(()=>{!ge&&v&&E===`credentials`&&e(`/`,{replace:!0})},[ge,v,E,e]);let Te=(0,l.useRef)(!1);(0,l.useEffect)(()=>{if(Te.current||n.get(`fallback`)===`local`||!G||!G.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;Te.current=!0;let e=G.autologin_provider_id,i=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([r.getOIDCAuthorizeUrl(e),i]).then(e=>{let n=t.state?.from;n?.pathname&&h(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url}).catch(()=>{we(!0)})},[G,n,t.state]);let q=G?.local_login_enabled!==!1,Ee=Ce&&G?.autologin_provider_id!=null;(0,l.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(B(n),D(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,l.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,a=n.get(`oidc_error`);if(!i&&!a)return;let o=pe();if(a){y({oidc_provider_error:f(`login.oidcErrors.providerError`),missing_parameters:f(`login.oidcErrors.missingParameters`),invalid_state:f(`login.oidcErrors.invalidState`),state_expired:f(`login.oidcErrors.stateExpired`),provider_not_found:f(`login.oidcErrors.providerNotFound`),discovery_failed:f(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:f(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:f(`login.oidcErrors.networkError`),token_exchange_bad_response:f(`login.oidcErrors.badResponse`),no_id_token:f(`login.oidcErrors.noIdToken`),token_validation_failed:f(`login.oidcErrors.validationFailed`),nonce_mismatch:f(`login.oidcErrors.nonceMismatch`),missing_sub_claim:f(`login.oidcErrors.missingSubClaim`),no_linked_account:f(`login.oidcErrors.noLinkedAccount`),account_inactive:f(`login.oidcErrors.accountInactive`),user_resolution_failed:f(`login.oidcErrors.userResolutionFailed`),internal_error:f(`login.oidcErrors.internalError`)}[a]??(a.startsWith(`token_exchange_`)?f(`login.oidcErrors.tokenExchangeFailed`):f(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&r.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){z(o),k(t.pre_auth_token);let n=t.two_fa_methods??[];j(n),n.includes(`totp`)?N(`totp`):n.includes(`email`)?N(`email`):N(`backup`),D(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(_(t.access_token,t.user,p(o)),y(f(`login.loginSuccess`)),e(b(),{replace:!0})):(y(f(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),y(f(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let J=o({mutationFn:()=>g(x,S,p(R)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){k(t.pre_auth_token);let e=t.two_fa_methods??[];j(e),e.includes(`totp`)?N(`totp`):e.includes(`email`)?N(`email`):N(`backup`),D(`2fa`)}else t.access_token&&t.user&&(y(f(`login.loginSuccess`)),e(b(),{replace:!0}))},onError:e=>{y(e.message||f(`login.loginFailed`),`error`)}}),Y=o({mutationFn:e=>r.forgotPassword({email:e}),onSuccess:e=>{y(e.message,`success`),C(!1),T(``)},onError:e=>{y(e.message,`error`)}}),X=o({mutationFn:()=>r.forgotPasswordConfirm(Se,V),onSuccess:e=>{y(e.message,`success`),D(`credentials`),B(``),H(``),W(``)},onError:e=>{y(e.message||f(`login.resetPassword.resetFailed`),`error`)}}),Z=o({mutationFn:()=>r.sendEmailOTP(O),onSuccess:e=>{L(!0),e.pre_auth_token&&k(e.pre_auth_token),y(e.message,`success`)},onError:e=>{y(e.message||f(`login.twoFA.sendCodeFailed`),`error`)}}),Q=o({mutationFn:()=>r.verify2FA({pre_auth_token:O,code:P,method:M}),onSuccess:t=>{t.access_token&&t.user?(_(t.access_token,t.user,p(R)),y(f(`login.loginSuccess`)),e(b(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),y(f(`login.loginFailed`),`error`))},onError:e=>{y(e.message||f(`login.twoFA.invalidCode`),`error`),F(``)}}),De=o({mutationFn:e=>r.getOIDCAuthorizeUrl(e),onSuccess:e=>{try{R?sessionStorage.setItem(d,`1`):sessionStorage.removeItem(d)}catch(e){console.warn(`setItem/removeItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&h(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{y(e.message||f(`login.oidcLoginFailed`),`error`)}}),Oe=e=>{if(e.preventDefault(),!x||!S){y(f(`login.enterCredentials`),`error`);return}J.mutate()},ke=e=>{if(e.preventDefault(),!P.trim()){y(f(`login.twoFA.enterCode`),`error`);return}Q.mutate()},Ae=e=>{if(e.preventDefault(),!w){y(f(`login.enterEmail`),`error`);return}Y.mutate(w)},$=e=>{N(e),F(``),L(!1),setTimeout(()=>xe.current?.focus(),0)};return E===`reset-password`?(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,u.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,u.jsx)(ue,{className:`w-7 h-7 text-bambu-green`})})}),(0,u.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:f(`login.resetPassword.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.resetPassword.subtitle`)})]}),(0,u.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),V!==U){y(f(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(V.length<8){y(f(`login.resetPassword.passwordTooShort`),`error`);return}X.mutate()},className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.resetPassword.newPassword`)}),(0,u.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:V,onChange:e=>H(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.resetPassword.confirmPassword`)}),(0,u.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:U,onChange:e=>W(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,u.jsx)(`button`,{type:`submit`,disabled:X.isPending||!V||!U,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:X.isPending?f(`login.resetPassword.saving`):f(`login.resetPassword.submit`)})]}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>{D(`credentials`),B(``),H(``),W(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.resetPassword.backToLogin`)})})]})}):E===`2fa`?(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,u.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,u.jsx)(ee,{className:`w-7 h-7 text-bambu-green`})})}),(0,u.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:f(`login.twoFA.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.twoFA.subtitle`)})]}),A.length>1&&(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[A.includes(`totp`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`totp`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(te,{className:`w-4 h-4`}),f(`login.twoFA.methodAuthenticator`)]}),A.includes(`email`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`email`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(le,{className:`w-4 h-4`}),f(`login.twoFA.methodEmail`)]}),A.includes(`backup`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`backup`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(ue,{className:`w-4 h-4`}),f(`login.twoFA.methodBackup`)]})]}),(0,u.jsxs)(`form`,{onSubmit:ke,className:`space-y-4`,children:[M===`totp`&&(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`login.twoFA.instructionsTotp`)}),M===`email`&&(0,u.jsxs)(`div`,{className:`space-y-3`,children:[(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(I?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!I&&(0,u.jsx)(c,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>Z.mutate(),disabled:Z.isPending,children:Z.isPending?f(`login.twoFA.sendingCode`):f(`login.twoFA.sendCodeButton`)}),I&&(0,u.jsx)(`button`,{type:`button`,onClick:()=>{L(!1),Z.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.twoFA.resendCode`)})]}),M===`backup`&&(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`login.twoFA.instructionsBackup`)}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:f(M===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,u.jsx)(`input`,{ref:xe,id:`twofa-code`,type:`text`,inputMode:M===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:P,onChange:e=>F(e.target.value.trim()),disabled:M===`email`&&!I,className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40`,placeholder:f(M===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:M===`backup`?8:6,autoFocus:!0})]}),(0,u.jsx)(`button`,{type:`submit`,disabled:Q.isPending||!P.trim()||M===`email`&&!I,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:Q.isPending?f(`login.twoFA.verifyingButton`):f(`login.twoFA.verifyButton`)})]}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>{D(`credentials`),k(``),F(``),L(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.twoFA.backToLogin`)})})]})}):(0,u.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,u.jsx)(`img`,{src:_e===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,u.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:f(`login.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.subtitle`)})]}),Ee&&(0,u.jsx)(`div`,{className:`mt-6 rounded-lg border border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:f(`login.autologinFailed`)}),!q&&(0,u.jsx)(`div`,{className:`mt-6 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 px-4 py-3 text-sm text-bambu-gray`,children:f(`login.localDisabledNotice`)}),q&&(0,u.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:Oe,children:[(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:G?.advanced_auth_enabled?f(`login.usernameOrEmail`):f(`login.username`)}),(0,u.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:x,onChange:e=>ve(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:G?.advanced_auth_enabled?f(`login.usernameOrEmailPlaceholder`):f(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.password`)||`Password`}),(0,u.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:S,onChange:e=>ye(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,u.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:f(`login.rememberMe`)})]}),(0,u.jsx)(`div`,{children:(0,u.jsx)(`button`,{type:`submit`,disabled:J.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:J.isPending?f(`login.signingIn`):f(`login.signIn`)})}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>C(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.forgotPassword`)})})]}),K&&K.length>0&&(0,u.jsxs)(`div`,{className:`space-y-3`,children:[q&&(0,u.jsxs)(`div`,{className:`relative`,children:[(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,u.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,u.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,u.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:f(`login.twoFA.orContinueWith`)})})]}),!q&&(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,u.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:f(`login.rememberMe`)})]}),(0,u.jsx)(`div`,{className:`space-y-2`,children:K.map(e=>(0,u.jsx)(he,{provider:e,onClick:()=>De.mutate(e.id),disabled:De.isPending},e.id))})]})]}),be&&(0,u.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>C(!1),children:(0,u.jsxs)(ae,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,u.jsx)(re,{children:(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(le,{className:`w-5 h-5 text-bambu-green`}),(0,u.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:f(`login.forgotPasswordTitle`)})]}),(0,u.jsx)(c,{variant:`ghost`,size:`sm`,onClick:()=>{C(!1),T(``)},children:(0,u.jsx)(ne,{className:`w-5 h-5`})})]})}),(0,u.jsx)(ie,{children:G?.advanced_auth_enabled?(0,u.jsxs)(`form`,{onSubmit:Ae,className:`space-y-4`,children:[(0,u.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:f(`login.forgotPasswordEmailMessage`)}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.emailAddress`)}),(0,u.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:w,onChange:e=>T(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.emailPlaceholder`)})]}),(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[(0,u.jsx)(c,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{C(!1),T(``)},children:f(`login.cancel`)}),(0,u.jsx)(c,{type:`submit`,className:`flex-1`,disabled:Y.isPending,children:Y.isPending?f(`login.sending`):f(`login.sendResetEmail`)})]})]}):(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsx)(`p`,{className:`text-bambu-gray`,children:f(`login.forgotPasswordMessage`)}),(0,u.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,u.jsx)(`p`,{className:`text-sm text-white font-medium`,children:f(`login.howToReset`)}),(0,u.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,u.jsx)(`li`,{children:f(`login.resetStep1`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep2`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep3`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep4`)})]})]}),(0,u.jsx)(c,{variant:`secondary`,className:`w-full`,onClick:()=>C(!1),children:f(`login.gotIt`)})]})})]})})]})}export{g as LoginPage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./useQuery-CCy0EwsM.js";import{t as o}from"./useMutation-qh3Iyscy.js";import{n as s}from"./ToastContext-VFOrCCoA.js";import{t as ee}from"./shield-CfkeOiiL.js";import{t as te}from"./smartphone-DOKM2tP4.js";import{t as ne}from"./x-Dctff5l9.js";import{i as re,n as ie,t as ae}from"./Card-OUAj0Ayh.js";import{t as c}from"./Button-pwVKPiYn.js";import{Bn as oe,Vn as se,Wn as ce,in as le,ln as ue,vt as de,yt as fe}from"./index-ggB_TpPo.js";var l=e(n(),1),u=t(),d=`auth_remember_me`,f=`auth_post_login_redirect`;function p(e){return e?`persistent`:`session`}function pe(){try{let e=sessionStorage.getItem(d)===`1`;return sessionStorage.removeItem(d),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function m(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function h(e){let t=m(e);if(t)try{sessionStorage.setItem(f,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function me(){try{let e=sessionStorage.getItem(f);return sessionStorage.removeItem(f),m(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function he({provider:e,onClick:t,disabled:n}){let{t:a}=i(),[o,s]=(0,l.useState)(!1);return(0,u.jsxs)(`button`,{type:`button`,onClick:t,disabled:n,className:`w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50`,children:[e.has_icon&&!o?(0,u.jsx)(`img`,{src:r.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>s(!0)}):(0,u.jsx)(ee,{className:`w-5 h-5 text-bambu-green`}),a(`login.twoFA.signInWith`,{provider:e.name})]})}function g(){let e=se(),t=oe(),[n]=ce(),{t:f}=i(),{login:g,loginWithToken:_,user:v,loading:ge}=fe(),{showToast:y}=s(),{mode:_e}=de();function b(){let e=t.state?.from;if(e?.pathname){let t=m(`${e.pathname}${e.search??``}`);if(t)return t}return me()??`/`}let[x,ve]=(0,l.useState)(``),[S,ye]=(0,l.useState)(``),[be,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)(``),[E,D]=(0,l.useState)(`credentials`),[O,k]=(0,l.useState)(``),[A,j]=(0,l.useState)([]),[M,N]=(0,l.useState)(`totp`),[P,F]=(0,l.useState)(``),[I,L]=(0,l.useState)(!1),xe=(0,l.useRef)(null),[R,z]=(0,l.useState)(!1),[Se,B]=(0,l.useState)(``),[V,H]=(0,l.useState)(``),[U,W]=(0,l.useState)(``),{data:G}=a({queryKey:[`advancedAuthStatus`],queryFn:()=>r.getAdvancedAuthStatus()}),{data:K}=a({queryKey:[`oidcProviders`],queryFn:()=>r.getOIDCProviders()}),[Ce,we]=(0,l.useState)(!1);(0,l.useEffect)(()=>{!ge&&v&&E===`credentials`&&e(`/`,{replace:!0})},[ge,v,E,e]);let Te=(0,l.useRef)(!1);(0,l.useEffect)(()=>{if(Te.current||n.get(`fallback`)===`local`||!G||!G.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;Te.current=!0;let e=G.autologin_provider_id,i=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([r.getOIDCAuthorizeUrl(e),i]).then(e=>{let n=t.state?.from;n?.pathname&&h(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url}).catch(()=>{we(!0)})},[G,n,t.state]);let q=G?.local_login_enabled!==!1,Ee=Ce&&G?.autologin_provider_id!=null;(0,l.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(B(n),D(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,l.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,a=n.get(`oidc_error`);if(!i&&!a)return;let o=pe();if(a){y({oidc_provider_error:f(`login.oidcErrors.providerError`),missing_parameters:f(`login.oidcErrors.missingParameters`),invalid_state:f(`login.oidcErrors.invalidState`),state_expired:f(`login.oidcErrors.stateExpired`),provider_not_found:f(`login.oidcErrors.providerNotFound`),discovery_failed:f(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:f(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:f(`login.oidcErrors.networkError`),token_exchange_bad_response:f(`login.oidcErrors.badResponse`),no_id_token:f(`login.oidcErrors.noIdToken`),token_validation_failed:f(`login.oidcErrors.validationFailed`),nonce_mismatch:f(`login.oidcErrors.nonceMismatch`),missing_sub_claim:f(`login.oidcErrors.missingSubClaim`),no_linked_account:f(`login.oidcErrors.noLinkedAccount`),account_inactive:f(`login.oidcErrors.accountInactive`),user_resolution_failed:f(`login.oidcErrors.userResolutionFailed`),internal_error:f(`login.oidcErrors.internalError`)}[a]??(a.startsWith(`token_exchange_`)?f(`login.oidcErrors.tokenExchangeFailed`):f(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&r.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){z(o),k(t.pre_auth_token);let n=t.two_fa_methods??[];j(n),n.includes(`totp`)?N(`totp`):n.includes(`email`)?N(`email`):N(`backup`),D(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(_(t.access_token,t.user,p(o)),y(f(`login.loginSuccess`)),e(b(),{replace:!0})):(y(f(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),y(f(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let J=o({mutationFn:()=>g(x,S,p(R)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){k(t.pre_auth_token);let e=t.two_fa_methods??[];j(e),e.includes(`totp`)?N(`totp`):e.includes(`email`)?N(`email`):N(`backup`),D(`2fa`)}else t.access_token&&t.user&&(y(f(`login.loginSuccess`)),e(b(),{replace:!0}))},onError:e=>{y(e.message||f(`login.loginFailed`),`error`)}}),Y=o({mutationFn:e=>r.forgotPassword({email:e}),onSuccess:e=>{y(e.message,`success`),C(!1),T(``)},onError:e=>{y(e.message,`error`)}}),X=o({mutationFn:()=>r.forgotPasswordConfirm(Se,V),onSuccess:e=>{y(e.message,`success`),D(`credentials`),B(``),H(``),W(``)},onError:e=>{y(e.message||f(`login.resetPassword.resetFailed`),`error`)}}),Z=o({mutationFn:()=>r.sendEmailOTP(O),onSuccess:e=>{L(!0),e.pre_auth_token&&k(e.pre_auth_token),y(e.message,`success`)},onError:e=>{y(e.message||f(`login.twoFA.sendCodeFailed`),`error`)}}),Q=o({mutationFn:()=>r.verify2FA({pre_auth_token:O,code:P,method:M}),onSuccess:t=>{t.access_token&&t.user?(_(t.access_token,t.user,p(R)),y(f(`login.loginSuccess`)),e(b(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),y(f(`login.loginFailed`),`error`))},onError:e=>{y(e.message||f(`login.twoFA.invalidCode`),`error`),F(``)}}),De=o({mutationFn:e=>r.getOIDCAuthorizeUrl(e),onSuccess:e=>{try{R?sessionStorage.setItem(d,`1`):sessionStorage.removeItem(d)}catch(e){console.warn(`setItem/removeItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&h(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{y(e.message||f(`login.oidcLoginFailed`),`error`)}}),Oe=e=>{if(e.preventDefault(),!x||!S){y(f(`login.enterCredentials`),`error`);return}J.mutate()},ke=e=>{if(e.preventDefault(),!P.trim()){y(f(`login.twoFA.enterCode`),`error`);return}Q.mutate()},Ae=e=>{if(e.preventDefault(),!w){y(f(`login.enterEmail`),`error`);return}Y.mutate(w)},$=e=>{N(e),F(``),L(!1),setTimeout(()=>xe.current?.focus(),0)};return E===`reset-password`?(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,u.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,u.jsx)(ue,{className:`w-7 h-7 text-bambu-green`})})}),(0,u.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:f(`login.resetPassword.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.resetPassword.subtitle`)})]}),(0,u.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),V!==U){y(f(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(V.length<8){y(f(`login.resetPassword.passwordTooShort`),`error`);return}X.mutate()},className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.resetPassword.newPassword`)}),(0,u.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:V,onChange:e=>H(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.resetPassword.confirmPassword`)}),(0,u.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:U,onChange:e=>W(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,u.jsx)(`button`,{type:`submit`,disabled:X.isPending||!V||!U,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:X.isPending?f(`login.resetPassword.saving`):f(`login.resetPassword.submit`)})]}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>{D(`credentials`),B(``),H(``),W(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.resetPassword.backToLogin`)})})]})}):E===`2fa`?(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,u.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,u.jsx)(ee,{className:`w-7 h-7 text-bambu-green`})})}),(0,u.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:f(`login.twoFA.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.twoFA.subtitle`)})]}),A.length>1&&(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[A.includes(`totp`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`totp`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(te,{className:`w-4 h-4`}),f(`login.twoFA.methodAuthenticator`)]}),A.includes(`email`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`email`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(le,{className:`w-4 h-4`}),f(`login.twoFA.methodEmail`)]}),A.includes(`backup`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`backup`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(ue,{className:`w-4 h-4`}),f(`login.twoFA.methodBackup`)]})]}),(0,u.jsxs)(`form`,{onSubmit:ke,className:`space-y-4`,children:[M===`totp`&&(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`login.twoFA.instructionsTotp`)}),M===`email`&&(0,u.jsxs)(`div`,{className:`space-y-3`,children:[(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(I?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!I&&(0,u.jsx)(c,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>Z.mutate(),disabled:Z.isPending,children:Z.isPending?f(`login.twoFA.sendingCode`):f(`login.twoFA.sendCodeButton`)}),I&&(0,u.jsx)(`button`,{type:`button`,onClick:()=>{L(!1),Z.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.twoFA.resendCode`)})]}),M===`backup`&&(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`login.twoFA.instructionsBackup`)}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:f(M===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,u.jsx)(`input`,{ref:xe,id:`twofa-code`,type:`text`,inputMode:M===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:P,onChange:e=>F(e.target.value.trim()),disabled:M===`email`&&!I,className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40`,placeholder:f(M===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:M===`backup`?8:6,autoFocus:!0})]}),(0,u.jsx)(`button`,{type:`submit`,disabled:Q.isPending||!P.trim()||M===`email`&&!I,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:Q.isPending?f(`login.twoFA.verifyingButton`):f(`login.twoFA.verifyButton`)})]}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>{D(`credentials`),k(``),F(``),L(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.twoFA.backToLogin`)})})]})}):(0,u.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,u.jsx)(`img`,{src:_e===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,u.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:f(`login.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.subtitle`)})]}),Ee&&(0,u.jsx)(`div`,{className:`mt-6 rounded-lg border border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:f(`login.autologinFailed`)}),!q&&(0,u.jsx)(`div`,{className:`mt-6 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 px-4 py-3 text-sm text-bambu-gray`,children:f(`login.localDisabledNotice`)}),q&&(0,u.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:Oe,children:[(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:G?.advanced_auth_enabled?f(`login.usernameOrEmail`):f(`login.username`)}),(0,u.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:x,onChange:e=>ve(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:G?.advanced_auth_enabled?f(`login.usernameOrEmailPlaceholder`):f(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.password`)||`Password`}),(0,u.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:S,onChange:e=>ye(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,u.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:f(`login.rememberMe`)})]}),(0,u.jsx)(`div`,{children:(0,u.jsx)(`button`,{type:`submit`,disabled:J.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:J.isPending?f(`login.signingIn`):f(`login.signIn`)})}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>C(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.forgotPassword`)})})]}),K&&K.length>0&&(0,u.jsxs)(`div`,{className:`space-y-3`,children:[q&&(0,u.jsxs)(`div`,{className:`relative`,children:[(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,u.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,u.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,u.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:f(`login.twoFA.orContinueWith`)})})]}),!q&&(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,u.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:f(`login.rememberMe`)})]}),(0,u.jsx)(`div`,{className:`space-y-2`,children:K.map(e=>(0,u.jsx)(he,{provider:e,onClick:()=>De.mutate(e.id),disabled:De.isPending},e.id))})]})]}),be&&(0,u.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>C(!1),children:(0,u.jsxs)(ae,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,u.jsx)(re,{children:(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(le,{className:`w-5 h-5 text-bambu-green`}),(0,u.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:f(`login.forgotPasswordTitle`)})]}),(0,u.jsx)(c,{variant:`ghost`,size:`sm`,onClick:()=>{C(!1),T(``)},children:(0,u.jsx)(ne,{className:`w-5 h-5`})})]})}),(0,u.jsx)(ie,{children:G?.advanced_auth_enabled?(0,u.jsxs)(`form`,{onSubmit:Ae,className:`space-y-4`,children:[(0,u.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:f(`login.forgotPasswordEmailMessage`)}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.emailAddress`)}),(0,u.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:w,onChange:e=>T(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.emailPlaceholder`)})]}),(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[(0,u.jsx)(c,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{C(!1),T(``)},children:f(`login.cancel`)}),(0,u.jsx)(c,{type:`submit`,className:`flex-1`,disabled:Y.isPending,children:Y.isPending?f(`login.sending`):f(`login.sendResetEmail`)})]})]}):(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsx)(`p`,{className:`text-bambu-gray`,children:f(`login.forgotPasswordMessage`)}),(0,u.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,u.jsx)(`p`,{className:`text-sm text-white font-medium`,children:f(`login.howToReset`)}),(0,u.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,u.jsx)(`li`,{children:f(`login.resetStep1`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep2`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep3`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep4`)})]})]}),(0,u.jsx)(c,{variant:`secondary`,className:`w-full`,onClick:()=>C(!1),children:f(`login.gotIt`)})]})})]})})]})}export{g as LoginPage};
\ No newline at end of file
diff --git a/static/assets/MaintenancePage-BewPZHCP.js b/static/assets/MaintenancePage-BVrgPrym.js
similarity index 99%
rename from static/assets/MaintenancePage-BewPZHCP.js
rename to static/assets/MaintenancePage-BVrgPrym.js
index fee59f9d9..91d646067 100644
--- a/static/assets/MaintenancePage-BewPZHCP.js
+++ b/static/assets/MaintenancePage-BVrgPrym.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as c}from"./createLucideIcon-Yo2YoYjm.js";import{t as l}from"./box-BIRPxdgi.js";import{n as u,t as d}from"./fan-DSlOeWAh.js";import{t as f}from"./calendar-DiVEdzUw.js";import{t as p}from"./check-D1Pn8T1J.js";import{a as m,i as h}from"./info-DcT0QU8O.js";import{n as g}from"./ToastContext-VFOrCCoA.js";import{t as _}from"./cog-pa-nvQzt.js";import{t as v}from"./droplet-PpnaB65N.js";import{t as y}from"./funnel-BtI48m95.js";import{t as ee}from"./loader-circle-CB4leTZa.js";import{t as b}from"./pen-line-DYnjxVtS.js";import{t as x}from"./sparkles-AUof3WTI.js";import{t as S}from"./target-PpftuQXz.js";import{n as C,t as w}from"./wind-CsHQYbhI.js";import{t as T}from"./timer-BYBW_ysJ.js";import{t as E}from"./triangle-alert-gIik0G2C.js";import{n as D,t as O}from"./Card-OUAj0Ayh.js";import{t as k}from"./Button-pwVKPiYn.js";import{At as te,Cn as A,Gt as j,Jt as ne,Kt as M,Lt as re,On as N,Vt as P,Zt as ie,_t as ae,bn as F,bt as I,cn as L,xt as R,yt as oe}from"./index-Bw-_P2Fg.js";import{t as z}from"./Toggle-CwMiiK0g.js";var B=c(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),V=c(`ruler`,[[`path`,{d:`M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z`,key:`icamh8`}],[`path`,{d:`m14.5 12.5 2-2`,key:`inckbg`}],[`path`,{d:`m11.5 9.5 2-2`,key:`fmmyf7`}],[`path`,{d:`m8.5 6.5 2-2`,key:`vc6u1g`}],[`path`,{d:`m17.5 15.5 2-2`,key:`wo5hmg`}]]),H=e(n(),1);function U(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var W=t(),G={Droplet:v,Flame:F,Ruler:V,Sparkles:x,Square:re,Cable:u,Wrench:R,Calendar:f,Timer:T,Cog:_,Fan:d,Zap:I,Wind:w,Thermometer:C,Layers:L,Box:l,Target:S,RefreshCw:M,Settings:P,Filter:y,CircleDot:B};function K(e){return e&&G[e]||R}function q(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function J(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function Y({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=K(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-700 dark:text-red-400`:e.is_warning?`text-amber-700 dark:text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,W.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,W.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,W.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,W.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,W.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,W.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,W.jsx)(f,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||U(e.maintenance_type_name,e.printer_model);return t?(0,W.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,W.jsx)(A,{className:`w-3.5 h-3.5`})}):null})()]}),(0,W.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,W.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,W.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,W.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,W.jsx)(E,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,W.jsx)(N,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,W.jsx)(p,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:q(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:q(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:q(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:q(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:q(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:q(e.hours_until_due,`hours`,i)})})()]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,W.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,W.jsx)(z,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,W.jsxs)(k,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,W.jsx)(j,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function X({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(!1),[u,d]=(0,H.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),g=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),_=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,W.jsxs)(O,{className:`overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`p-5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,W.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,W.jsx)(E,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,W.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,W.jsx)(N,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,W.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,W.jsx)(p,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,W.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,W.jsx)(h,{className:`w-4 h-4`}):(0,W.jsx)(m,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,W.jsx)(T,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,W.jsx)(k,{size:`sm`,onClick:_,children:a(`common.save`)}),(0,W.jsx)(k,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,W.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,W.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,W.jsx)(b,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,W.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,W.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),g&&(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 rounded-lg ${g.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,W.jsx)(K(g.maintenance_type_icon),{className:`w-4 h-4 ${g.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-sm font-medium ${g.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:g.maintenance_type_name}),(0,W.jsx)(`div`,{className:`text-xs ${g.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:g.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,W.jsx)(D,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,W.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,W.jsx)(Y,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function Z({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[p,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(`hours`),[ee,x]=(0,H.useState)(!1),[S,C]=(0,H.useState)(``),[w,E]=(0,H.useState)(`100`),[A,j]=(0,H.useState)(`hours`),[M,re]=(0,H.useState)(`Wrench`),[P,F]=(0,H.useState)(``),[I,L]=(0,H.useState)(new Set),[R,oe]=(0,H.useState)(null),[z,B]=(0,H.useState)(null),V=(0,H.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),U=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],q=t=>{if(!e)return[];let n=new Set(U(t).map(e=>e.printerId));return V.filter(e=>!n.has(e.id))},[Y,X]=(0,H.useState)(null),[Z,Q]=(0,H.useState)(``),[$,se]=(0,H.useState)(``),[ce,le]=(0,H.useState)(`hours`),[ue,de]=(0,H.useState)(`Wrench`),[fe,pe]=(0,H.useState)(``),me=e=>{X(e),Q(e.name),se(e.default_interval_hours.toString()),le(e.interval_type||`hours`),de(e.icon||`Wrench`),pe(e.wiki_url||``)},he=()=>{Y&&Z.trim()&&parseFloat($)>0&&(i(Y.id,{name:Z.trim(),default_interval_hours:parseFloat($),interval_type:ce,icon:ue,wiki_url:fe.trim()||null}),X(null))},ge=(e,t,r)=>{let i=parseFloat(g);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:v===r?null:v}),h(null)},_e=e=>{e.preventDefault(),S.trim()&&parseFloat(w)>0&&I.size>0&&(r({name:S.trim(),default_interval_hours:parseFloat(w),interval_type:A,icon:M,wiki_url:P.trim()||null},Array.from(I)),C(``),E(`100`),j(`hours`),F(``),L(new Set),x(!1))},ve=e=>{L(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ye=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],be=t.filter(e=>e.is_system),xe=t.filter(e=>!e.is_system);return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(k,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,W.jsxs)(k,{onClick:()=>x(!ee),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,W.jsx)(ie,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),ee&&(0,W.jsx)(O,{className:`mb-6`,children:(0,W.jsx)(D,{className:`py-4`,children:(0,W.jsxs)(`form`,{onSubmit:_e,children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,W.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,W.jsx)(`input`,{type:`text`,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 text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,W.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),e.target.value===`days`?E(`30`):E(`100`)},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`,children:[(0,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:A===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,W.jsx)(`input`,{type:`number`,value:w,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,W.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,W.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(G).map(e=>{let t=G[e];return(0,W.jsx)(`button`,{type:`button`,onClick:()=>re(e),className:`p-2 rounded-lg transition-colors ${M===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,W.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,W.jsxs)(`div`,{className:`mt-4`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,W.jsx)(`input`,{type:`url`,value:P,onChange:e=>F(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,W.jsxs)(`div`,{className:`mt-4`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:V.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>ve(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${I.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),I.size===0&&(0,W.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,W.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,W.jsx)(k,{type:`button`,variant:`secondary`,onClick:()=>{x(!1),L(new Set)},children:d(`common.cancel`)}),(0,W.jsx)(k,{type:`submit`,disabled:!S.trim()||I.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[be.map(e=>{let t=K(e.icon),n=e.interval_type||`hours`;return(0,W.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,W.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,W.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.default_interval_hours,n,d)]})]}),(0,W.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&B(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,W.jsx)(te,{className:`w-4 h-4`})})]})},e.id)}),xe.map(e=>{let t=K(e.icon),n=e.interval_type||`hours`;if(Y?.id===e.id)return(0,W.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(`input`,{type:`text`,value:Z,onChange:e=>Q(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(`select`,{value:ce,onChange:e=>le(e.target.value),className:`flex-1 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`,children:[(0,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,W.jsx)(`input`,{type:`number`,value:$,onChange:e=>se(e.target.value),className:`w-24 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`,min:`1`})]}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(G).map(e=>{let t=G[e];return(0,W.jsx)(`button`,{type:`button`,onClick:()=>de(e),className:`p-1.5 rounded transition-colors ${ue===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,W.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,W.jsx)(`input`,{type:`url`,value:fe,onChange:e=>pe(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(k,{size:`sm`,onClick:he,disabled:!Z.trim(),children:d(`common.save`)}),(0,W.jsx)(k,{size:`sm`,variant:`secondary`,onClick:()=>X(null),children:d(`common.cancel`)})]})]})},e.id);let r=U(e.id),i=q(e.id),o=R===e.id;return(0,W.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,W.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,W.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,W.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.default_interval_hours,n,d)]})]}),(0,W.jsxs)(`button`,{onClick:()=>oe(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-300 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-400/50 dark:bg-orange-400/10 dark:text-orange-400 dark:hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,W.jsx)(ne,{className:`w-3 h-3`}),(0,W.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,W.jsx)(m,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,W.jsx)(`button`,{onClick:()=>me(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,W.jsx)(b,{className:`w-4 h-4`})}),(0,W.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,W.jsx)(te,{className:`w-4 h-4`})})]}),o&&(0,W.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,W.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,W.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,W.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-600 dark:hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,W.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),ye.length>0&&(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,W.jsx)(`div`,{className:`space-y-4`,children:ye.map(e=>(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`py-4`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=K(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=p===e.id;return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,W.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[v===`days`?(0,W.jsx)(f,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,W.jsx)(T,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,W.jsxs)(`select`,{value:v,onChange:e=>y(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,W.jsx)(`input`,{type:`number`,value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ge(e.id,i,a),t.key===`Escape`&&h(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,W.jsx)(k,{size:`sm`,onClick:()=>ge(e.id,i,a),children:`OK`})]}):(0,W.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(h(e.id),_(e.interval_hours.toString()),y(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.interval_hours,o,d),(0,W.jsx)(b,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),ye.length===0&&(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`text-center py-12`,children:[(0,W.jsx)(N,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,W.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),z&&(0,W.jsx)(ae,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:z.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(z.id),B(null)},onCancel:()=>B(null)})]})}function Q(){let{t:e}=i(),t=a(),{showToast:n}=g(),{hasPermission:c}=oe(),[l,u]=(0,H.useState)(`status`),{data:d,isLoading:f}=o({queryKey:[`maintenanceOverview`],queryFn:r.getMaintenanceOverview}),{data:p}=o({queryKey:[`maintenanceTypes`],queryFn:r.getMaintenanceTypes}),m=s({mutationFn:({id:e,notes:t})=>r.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),h=s({mutationFn:({id:e,data:t})=>r.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),_=s({mutationFn:({id:e,data:t})=>r.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),v=s({mutationFn:r.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),y=s({mutationFn:r.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),b=s({mutationFn:({printerId:e,hours:t})=>r.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),x=s({mutationFn:({printerId:e,typeId:t})=>r.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),S=s({mutationFn:r.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),C=e=>{m.mutate({id:e})},w=(e,t)=>{h.mutate({id:e,data:{enabled:t}})},T=(e,t)=>{b.mutate({printerId:e,hours:t})};if(f)return(0,W.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,W.jsx)(ee,{className:`w-8 h-8 text-bambu-green animate-spin`})});let E=d?.reduce((e,t)=>e+t.due_count,0)||0,k=d?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,W.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,W.jsxs)(`div`,{className:`mb-6`,children:[(0,W.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,W.jsx)(R,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,W.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:l===`status`?(0,W.jsxs)(W.Fragment,{children:[E>0&&(0,W.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:E})}),E>0&&k>0&&` · `,k>0&&(0,W.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:k})}),E===0&&k===0&&(0,W.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,W.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,W.jsx)(`button`,{onClick:()=>u(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${l===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,W.jsx)(`button`,{onClick:()=>u(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${l===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),l===`status`?(0,W.jsx)(`div`,{className:`space-y-6`,children:d&&d.length>0?[...d].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,W.jsx)(X,{overview:t,onPerform:C,onToggle:w,onSetHours:T,hasPermission:c,t:e},t.printer_id)):(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`text-center py-16`,children:[(0,W.jsx)(R,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,W.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,W.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,W.jsx)(Z,{overview:d,types:p||[],onUpdateInterval:(e,t)=>h.mutate({id:e,data:t}),onAddType:async(i,a)=>{let o=await r.createMaintenanceType(i);for(let e of a)await r.assignMaintenanceType(e,o.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>_.mutate({id:e,data:t}),onDeleteType:e=>v.mutate(e),onRestoreDefaults:()=>y.mutate(),isRestoringDefaults:y.isPending,onAssignType:(e,t)=>x.mutate({printerId:e,typeId:t}),onRemoveItem:e=>S.mutate(e),hasPermission:c,t:e})]})}export{Q as MaintenancePage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as c}from"./createLucideIcon-Yo2YoYjm.js";import{t as l}from"./box-BIRPxdgi.js";import{n as u,t as d}from"./fan-DSlOeWAh.js";import{t as f}from"./calendar-DiVEdzUw.js";import{t as p}from"./check-D1Pn8T1J.js";import{a as m,i as h}from"./info-DcT0QU8O.js";import{n as g}from"./ToastContext-VFOrCCoA.js";import{t as _}from"./cog-pa-nvQzt.js";import{t as v}from"./droplet-PpnaB65N.js";import{t as y}from"./funnel-BtI48m95.js";import{t as ee}from"./loader-circle-CB4leTZa.js";import{t as b}from"./pen-line-DYnjxVtS.js";import{t as x}from"./sparkles-AUof3WTI.js";import{t as S}from"./target-PpftuQXz.js";import{n as C,t as w}from"./wind-CsHQYbhI.js";import{t as T}from"./timer-BYBW_ysJ.js";import{t as E}from"./triangle-alert-gIik0G2C.js";import{n as D,t as O}from"./Card-OUAj0Ayh.js";import{t as k}from"./Button-pwVKPiYn.js";import{At as te,Cn as A,Gt as j,Jt as ne,Kt as M,Lt as re,On as N,Vt as P,Zt as ie,_t as ae,bn as F,bt as I,cn as L,xt as R,yt as oe}from"./index-ggB_TpPo.js";import{t as z}from"./Toggle-CwMiiK0g.js";var B=c(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),V=c(`ruler`,[[`path`,{d:`M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z`,key:`icamh8`}],[`path`,{d:`m14.5 12.5 2-2`,key:`inckbg`}],[`path`,{d:`m11.5 9.5 2-2`,key:`fmmyf7`}],[`path`,{d:`m8.5 6.5 2-2`,key:`vc6u1g`}],[`path`,{d:`m17.5 15.5 2-2`,key:`wo5hmg`}]]),H=e(n(),1);function U(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var W=t(),G={Droplet:v,Flame:F,Ruler:V,Sparkles:x,Square:re,Cable:u,Wrench:R,Calendar:f,Timer:T,Cog:_,Fan:d,Zap:I,Wind:w,Thermometer:C,Layers:L,Box:l,Target:S,RefreshCw:M,Settings:P,Filter:y,CircleDot:B};function K(e){return e&&G[e]||R}function q(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function J(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function Y({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=K(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-700 dark:text-red-400`:e.is_warning?`text-amber-700 dark:text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,W.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,W.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,W.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,W.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,W.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,W.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,W.jsx)(f,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||U(e.maintenance_type_name,e.printer_model);return t?(0,W.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,W.jsx)(A,{className:`w-3.5 h-3.5`})}):null})()]}),(0,W.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,W.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,W.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,W.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,W.jsx)(E,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,W.jsx)(N,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,W.jsx)(p,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:q(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:q(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:q(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:q(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:q(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:q(e.hours_until_due,`hours`,i)})})()]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,W.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,W.jsx)(z,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,W.jsxs)(k,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,W.jsx)(j,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function X({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(!1),[u,d]=(0,H.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),g=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),_=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,W.jsxs)(O,{className:`overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`p-5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,W.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,W.jsx)(E,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,W.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,W.jsx)(N,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,W.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,W.jsx)(p,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,W.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,W.jsx)(h,{className:`w-4 h-4`}):(0,W.jsx)(m,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,W.jsx)(T,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,W.jsx)(k,{size:`sm`,onClick:_,children:a(`common.save`)}),(0,W.jsx)(k,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,W.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,W.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,W.jsx)(b,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,W.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,W.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),g&&(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 rounded-lg ${g.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,W.jsx)(K(g.maintenance_type_icon),{className:`w-4 h-4 ${g.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-sm font-medium ${g.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:g.maintenance_type_name}),(0,W.jsx)(`div`,{className:`text-xs ${g.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:g.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,W.jsx)(D,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,W.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,W.jsx)(Y,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function Z({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[p,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(`hours`),[ee,x]=(0,H.useState)(!1),[S,C]=(0,H.useState)(``),[w,E]=(0,H.useState)(`100`),[A,j]=(0,H.useState)(`hours`),[M,re]=(0,H.useState)(`Wrench`),[P,F]=(0,H.useState)(``),[I,L]=(0,H.useState)(new Set),[R,oe]=(0,H.useState)(null),[z,B]=(0,H.useState)(null),V=(0,H.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),U=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],q=t=>{if(!e)return[];let n=new Set(U(t).map(e=>e.printerId));return V.filter(e=>!n.has(e.id))},[Y,X]=(0,H.useState)(null),[Z,Q]=(0,H.useState)(``),[$,se]=(0,H.useState)(``),[ce,le]=(0,H.useState)(`hours`),[ue,de]=(0,H.useState)(`Wrench`),[fe,pe]=(0,H.useState)(``),me=e=>{X(e),Q(e.name),se(e.default_interval_hours.toString()),le(e.interval_type||`hours`),de(e.icon||`Wrench`),pe(e.wiki_url||``)},he=()=>{Y&&Z.trim()&&parseFloat($)>0&&(i(Y.id,{name:Z.trim(),default_interval_hours:parseFloat($),interval_type:ce,icon:ue,wiki_url:fe.trim()||null}),X(null))},ge=(e,t,r)=>{let i=parseFloat(g);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:v===r?null:v}),h(null)},_e=e=>{e.preventDefault(),S.trim()&&parseFloat(w)>0&&I.size>0&&(r({name:S.trim(),default_interval_hours:parseFloat(w),interval_type:A,icon:M,wiki_url:P.trim()||null},Array.from(I)),C(``),E(`100`),j(`hours`),F(``),L(new Set),x(!1))},ve=e=>{L(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ye=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],be=t.filter(e=>e.is_system),xe=t.filter(e=>!e.is_system);return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(k,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,W.jsxs)(k,{onClick:()=>x(!ee),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,W.jsx)(ie,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),ee&&(0,W.jsx)(O,{className:`mb-6`,children:(0,W.jsx)(D,{className:`py-4`,children:(0,W.jsxs)(`form`,{onSubmit:_e,children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,W.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,W.jsx)(`input`,{type:`text`,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 text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,W.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),e.target.value===`days`?E(`30`):E(`100`)},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`,children:[(0,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:A===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,W.jsx)(`input`,{type:`number`,value:w,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,W.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,W.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(G).map(e=>{let t=G[e];return(0,W.jsx)(`button`,{type:`button`,onClick:()=>re(e),className:`p-2 rounded-lg transition-colors ${M===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,W.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,W.jsxs)(`div`,{className:`mt-4`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,W.jsx)(`input`,{type:`url`,value:P,onChange:e=>F(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,W.jsxs)(`div`,{className:`mt-4`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:V.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>ve(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${I.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),I.size===0&&(0,W.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,W.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,W.jsx)(k,{type:`button`,variant:`secondary`,onClick:()=>{x(!1),L(new Set)},children:d(`common.cancel`)}),(0,W.jsx)(k,{type:`submit`,disabled:!S.trim()||I.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[be.map(e=>{let t=K(e.icon),n=e.interval_type||`hours`;return(0,W.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,W.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,W.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.default_interval_hours,n,d)]})]}),(0,W.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&B(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,W.jsx)(te,{className:`w-4 h-4`})})]})},e.id)}),xe.map(e=>{let t=K(e.icon),n=e.interval_type||`hours`;if(Y?.id===e.id)return(0,W.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(`input`,{type:`text`,value:Z,onChange:e=>Q(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(`select`,{value:ce,onChange:e=>le(e.target.value),className:`flex-1 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`,children:[(0,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,W.jsx)(`input`,{type:`number`,value:$,onChange:e=>se(e.target.value),className:`w-24 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`,min:`1`})]}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(G).map(e=>{let t=G[e];return(0,W.jsx)(`button`,{type:`button`,onClick:()=>de(e),className:`p-1.5 rounded transition-colors ${ue===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,W.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,W.jsx)(`input`,{type:`url`,value:fe,onChange:e=>pe(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(k,{size:`sm`,onClick:he,disabled:!Z.trim(),children:d(`common.save`)}),(0,W.jsx)(k,{size:`sm`,variant:`secondary`,onClick:()=>X(null),children:d(`common.cancel`)})]})]})},e.id);let r=U(e.id),i=q(e.id),o=R===e.id;return(0,W.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,W.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,W.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,W.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.default_interval_hours,n,d)]})]}),(0,W.jsxs)(`button`,{onClick:()=>oe(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-300 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-400/50 dark:bg-orange-400/10 dark:text-orange-400 dark:hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,W.jsx)(ne,{className:`w-3 h-3`}),(0,W.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,W.jsx)(m,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,W.jsx)(`button`,{onClick:()=>me(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,W.jsx)(b,{className:`w-4 h-4`})}),(0,W.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,W.jsx)(te,{className:`w-4 h-4`})})]}),o&&(0,W.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,W.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,W.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,W.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-600 dark:hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,W.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),ye.length>0&&(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,W.jsx)(`div`,{className:`space-y-4`,children:ye.map(e=>(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`py-4`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=K(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=p===e.id;return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,W.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[v===`days`?(0,W.jsx)(f,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,W.jsx)(T,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,W.jsxs)(`select`,{value:v,onChange:e=>y(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,W.jsx)(`input`,{type:`number`,value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ge(e.id,i,a),t.key===`Escape`&&h(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,W.jsx)(k,{size:`sm`,onClick:()=>ge(e.id,i,a),children:`OK`})]}):(0,W.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(h(e.id),_(e.interval_hours.toString()),y(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.interval_hours,o,d),(0,W.jsx)(b,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),ye.length===0&&(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`text-center py-12`,children:[(0,W.jsx)(N,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,W.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),z&&(0,W.jsx)(ae,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:z.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(z.id),B(null)},onCancel:()=>B(null)})]})}function Q(){let{t:e}=i(),t=a(),{showToast:n}=g(),{hasPermission:c}=oe(),[l,u]=(0,H.useState)(`status`),{data:d,isLoading:f}=o({queryKey:[`maintenanceOverview`],queryFn:r.getMaintenanceOverview}),{data:p}=o({queryKey:[`maintenanceTypes`],queryFn:r.getMaintenanceTypes}),m=s({mutationFn:({id:e,notes:t})=>r.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),h=s({mutationFn:({id:e,data:t})=>r.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),_=s({mutationFn:({id:e,data:t})=>r.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),v=s({mutationFn:r.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),y=s({mutationFn:r.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),b=s({mutationFn:({printerId:e,hours:t})=>r.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),x=s({mutationFn:({printerId:e,typeId:t})=>r.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),S=s({mutationFn:r.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),C=e=>{m.mutate({id:e})},w=(e,t)=>{h.mutate({id:e,data:{enabled:t}})},T=(e,t)=>{b.mutate({printerId:e,hours:t})};if(f)return(0,W.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,W.jsx)(ee,{className:`w-8 h-8 text-bambu-green animate-spin`})});let E=d?.reduce((e,t)=>e+t.due_count,0)||0,k=d?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,W.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,W.jsxs)(`div`,{className:`mb-6`,children:[(0,W.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,W.jsx)(R,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,W.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:l===`status`?(0,W.jsxs)(W.Fragment,{children:[E>0&&(0,W.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:E})}),E>0&&k>0&&` · `,k>0&&(0,W.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:k})}),E===0&&k===0&&(0,W.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,W.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,W.jsx)(`button`,{onClick:()=>u(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${l===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,W.jsx)(`button`,{onClick:()=>u(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${l===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),l===`status`?(0,W.jsx)(`div`,{className:`space-y-6`,children:d&&d.length>0?[...d].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,W.jsx)(X,{overview:t,onPerform:C,onToggle:w,onSetHours:T,hasPermission:c,t:e},t.printer_id)):(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`text-center py-16`,children:[(0,W.jsx)(R,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,W.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,W.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,W.jsx)(Z,{overview:d,types:p||[],onUpdateInterval:(e,t)=>h.mutate({id:e,data:t}),onAddType:async(i,a)=>{let o=await r.createMaintenanceType(i);for(let e of a)await r.assignMaintenanceType(e,o.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>_.mutate({id:e,data:t}),onDeleteType:e=>v.mutate(e),onRestoreDefaults:()=>y.mutate(),isRestoringDefaults:y.isPending,onAssignType:(e,t)=>x.mutate({printerId:e,typeId:t}),onRemoveItem:e=>S.mutate(e),hasPermission:c,t:e})]})}export{Q as MaintenancePage};
\ No newline at end of file
diff --git a/static/assets/ModelSourcesPage-8I2_SqrV.js b/static/assets/ModelSourcesPage-N6_2aJy3.js
similarity index 99%
rename from static/assets/ModelSourcesPage-8I2_SqrV.js
rename to static/assets/ModelSourcesPage-N6_2aJy3.js
index 9e00f8363..78e95ac94 100644
--- a/static/assets/ModelSourcesPage-8I2_SqrV.js
+++ b/static/assets/ModelSourcesPage-N6_2aJy3.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-BdOyoZJz.js";import{n as o}from"./QueryClientProvider-Clbyr4Jg.js";import{t as s}from"./useQuery-CCy0EwsM.js";import{t as c}from"./useMutation-qh3Iyscy.js";import{t as l}from"./createLucideIcon-Yo2YoYjm.js";import{t as u}from"./arrow-left-MSgMxOFV.js";import{t as d}from"./arrow-right-Da96kh4S.js";import{t as f}from"./box-BIRPxdgi.js";import{t as p}from"./check-D1Pn8T1J.js";import{r as m}from"./info-DcT0QU8O.js";import{n as h}from"./ToastContext-VFOrCCoA.js";import{t as g}from"./cog-pa-nvQzt.js";import{t as _}from"./SliceModal-DYhyNfSM.js";import{t as v}from"./loader-circle-CB4leTZa.js";import{t as y}from"./search-BpAJdxRw.js";import{t as b}from"./x-Dctff5l9.js";import{i as x,n as S,t as C}from"./Card-OUAj0Ayh.js";import{t as w}from"./Button-pwVKPiYn.js";import{At as T,Cn as E,Mn as D,Rn as O,Vn as k,Vt as A,Wn as j,_t as M,hn as N,jn as ee,vn as P,wn as te,yt as ne}from"./index-Bw-_P2Fg.js";import{a as re,o as ie}from"./slicer-DgCA7cW6.js";import{t as ae}from"./purify.es-F_7NWVtX.js";import{t as oe}from"./libraryFiles-B0B1SFfn.js";var F=l(`images`,[[`path`,{d:`m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16`,key:`9kzy35`}],[`path`,{d:`M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2`,key:`1t0f0t`}],[`circle`,{cx:`13`,cy:`7`,r:`1`,fill:`currentColor`,key:`1obus6`}],[`rect`,{x:`8`,y:`2`,width:`14`,height:`14`,rx:`2`,key:`1gvhby`}]]),I=l(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),L=e(n(),1),R=t(),z=new Set([`manyfold_not_configured`,`manyfold_credentials`,`manyfold_scope`,`manyfold_rate_limited`,`manyfold_unreachable`,`manyfold_forbidden`,`manyfold_not_found`,`manyfold_too_large`,`manyfold_not_importable`,`manyfold_bad_url`,`manyfold_secret_required`,`manyfold_failed`]);function B(e,t){return e instanceof i&&e.code&&z.has(e.code)?t(`manyfold.errors.${e.code}`):e instanceof Error&&e.message?e.message:t(`manyfold.errors.manyfold_failed`)}function V(e){return((e.split(`/`)[1]??``).replace(/^x-/,``).split(/[+.;]/)[0]||`?`).toUpperCase()}function H(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])H(r,t+1,n);return n}function U({modelId:e,className:t}){let{data:n,isLoading:i}=s({queryKey:[`manyfold-preview`,e],queryFn:()=>r.getManyfoldPreview(e),staleTime:1/0,retry:!1}),[a,o]=(0,L.useState)(null);return(0,L.useEffect)(()=>{if(!n){o(null);return}let e=URL.createObjectURL(n);return o(e),()=>URL.revokeObjectURL(e)},[n]),(0,R.jsx)(`div`,{className:`flex items-center justify-center bg-bambu-dark overflow-hidden ${t??``}`,children:a?(0,R.jsx)(`img`,{src:a,alt:``,className:`w-full h-full object-contain`}):i?(0,R.jsx)(v,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,R.jsx)(f,{className:`w-10 h-10 text-bambu-gray/50`,"aria-hidden":!0})})}function W({onDone:e}){let{t}=a(),{showToast:n}=h(),i=o(),l=s({queryKey:[`manyfold-config`],queryFn:()=>r.getManyfoldConfig()}),[u,d]=(0,L.useState)(``),[f,p]=(0,L.useState)(``),[m,g]=(0,L.useState)(``),[_,y]=(0,L.useState)(null),[b,T]=(0,L.useState)(!1);(0,L.useEffect)(()=>{l.data&&(d(l.data.url),p(l.data.client_id))},[l.data]);let E=l.data?.has_client_secret??!1,D={url:u.trim(),client_id:f.trim(),client_secret:m.trim()||void 0},O=!!D.url&&!!D.client_id&&(!!D.client_secret||E),k=()=>{i.invalidateQueries({queryKey:[`manyfold-config`]}),i.invalidateQueries({queryKey:[`manyfold-status`]}),i.invalidateQueries({queryKey:[`manyfold-models`]}),i.invalidateQueries({queryKey:[`manyfold-model`]}),i.invalidateQueries({queryKey:[`manyfold-preview`]})},j=c({mutationFn:()=>r.testManyfoldConfig(D),onSuccess:e=>y({ok:!0,text:t(`manyfold.testOk`,{count:e.model_count})}),onError:e=>y({ok:!1,text:B(e,t)})}),N=c({mutationFn:()=>r.updateManyfoldConfig(D),onSuccess:()=>{g(``),k(),n(t(`settings.toast.settingsSaved`),`success`),e?.()},onError:e=>n(B(e,t),`error`)}),ee=c({mutationFn:()=>r.deleteManyfoldConfig(),onSuccess:()=>{T(!1),d(``),p(``),g(``),y(null),k(),n(t(`manyfold.disconnected`),`success`)},onError:e=>{T(!1),n(B(e,t),`error`)}}),P=`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`;return(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,R.jsx)(A,{className:`w-5 h-5 text-bambu-green`}),t(`manyfold.connectionTitle`)]})}),(0,R.jsxs)(S,{className:`space-y-4`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`manyfold.connectionHelp`)}),(0,R.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),O&&N.mutate()},children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-url`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.url`)}),(0,R.jsx)(`input`,{id:`manyfold-url`,type:`url`,value:u,onChange:e=>{d(e.target.value),y(null)},placeholder:t(`manyfold.urlPlaceholder`),className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-id`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientId`)}),(0,R.jsx)(`input`,{id:`manyfold-client-id`,type:`text`,value:f,onChange:e=>{p(e.target.value),y(null)},className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-secret`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientSecret`)}),(0,R.jsx)(`input`,{id:`manyfold-client-secret`,type:`password`,value:m,onChange:e=>{g(e.target.value),y(null)},placeholder:E?t(`manyfold.clientSecretStored`):``,className:P,autoComplete:`new-password`})]}),_&&(0,R.jsx)(`p`,{role:`status`,className:`text-sm ${_.ok?`text-bambu-green`:`text-red-400`}`,children:_.text}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,R.jsxs)(w,{type:`submit`,disabled:!O||N.isPending,children:[N.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`common.save`)]}),(0,R.jsxs)(w,{type:`button`,variant:`secondary`,disabled:!O||j.isPending,onClick:()=>j.mutate(),children:[j.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`manyfold.test`)]}),l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`danger`,onClick:()=>T(!0),children:t(`manyfold.disconnect`)}),e&&l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`ghost`,onClick:e,children:t(`common.cancel`)})]})]})]}),b&&(0,R.jsx)(M,{title:t(`manyfold.disconnectTitle`),message:t(`manyfold.disconnectBody`),confirmText:t(`manyfold.disconnect`),variant:`danger`,isLoading:ee.isPending,onCancel:()=>T(!1),onConfirm:()=>ee.mutate()})]})}function se({value:e,onChange:t,disabled:n}){let{t:i}=a(),o=(s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}).data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>H(e));return(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[i(`manyfold.importTo`),(0,R.jsxs)(`select`,{value:e??``,disabled:n,onChange:e=>t(e.target.value?Number(e.target.value):null),className:`px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,children:[(0,R.jsx)(`option`,{value:``,children:i(`manyfold.folderAuto`)}),o.map(({folder:e,depth:t})=>(0,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]})]})}function G(e){return e.length>3?`${e.slice(0,3).join(`, `)} +${e.length-3}`:e.join(`, `)}function K(){let{t:e}=a(),{showToast:t}=h(),n=o(),[i,s]=(0,L.useState)(null);return{run:async(i,a)=>{if(i.length===0){t(e(`manyfold.bulkNothing`),`info`);return}let o=0,c=0,l=[],u=null;try{for(let e=0;er.getManyfoldModel(e)}),N=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),ee=N.data?.use_slicer_api??!1,re=ie(N.data?.open_in_slicer,N.data?.preferred_slicer),ae=c({mutationFn:t=>r.importManyfoldFile(e,t.id,y),onMutate:e=>D(e.id),onSettled:()=>D(null),onSuccess:t=>{f.invalidateQueries({queryKey:[`manyfold-model`,e]}),f.invalidateQueries({queryKey:[`library-files`]}),f.invalidateQueries({queryKey:[`library-folders`]}),d(t.was_existing?i(`manyfold.alreadyInLibrary`):i(`manyfold.imported`,{filename:t.filename}),`success`)},onError:e=>d(B(e,i),`error`)});if(M.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(M.isError||!M.data)return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(`p`,{className:`text-red-400 text-sm`,children:B(M.error,i)})]});let F=M.data,I=F.files.filter(e=>e.importable&&!e.library_file),z=I.filter(e=>O.has(e.id)),H=I.length>0&&z.length===I.length,W=j.busy||ae.isPending,G=async e=>{await j.run(e.map(e=>({modelId:F.id,fileId:e.id,name:e.name})),y),A(new Set)};return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-6 py-2`,children:[(0,R.jsx)(U,{modelId:F.id,className:`w-full md:w-72 aspect-square rounded-lg shrink-0`}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-xl font-semibold text-white break-words`,children:F.name}),F.caption&&(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:F.caption})]}),F.description&&(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray whitespace-pre-line break-words`,children:F.description}),F.tags.length>0&&(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:F.tags.map(e=>(0,R.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-xs text-white`,children:e},e))}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 text-sm`,children:[F.license&&(0,R.jsxs)(`span`,{className:`text-bambu-gray`,children:[i(`manyfold.license`),`: `,(0,R.jsx)(`span`,{className:`text-white`,children:F.license})]}),(0,R.jsxs)(`a`,{href:F.url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-bambu-green hover:underline`,children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),i(`manyfold.openInManyfold`)]})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsxs)(x,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:i(`manyfold.files`)}),_&&(0,R.jsx)(se,{value:y,onChange:b,disabled:W})]}),_&&I.length>0&&(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-3`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:H,ref:e=>{e&&(e.indeterminate=z.length>0&&!H)},disabled:W,onChange:()=>A(H?new Set:new Set(I.map(e=>e.id))),className:`accent-bambu-green`}),i(`manyfold.selectAll`)]}),j.progress?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),i(`manyfold.importProgress`,j.progress)]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,disabled:W||z.length===0,onClick:()=>G(z),children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),i(`manyfold.importSelected`,{count:z.length})]}),(0,R.jsx)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>G(I),children:i(`manyfold.importAll`)})]})]})]}),(0,R.jsx)(S,{children:F.files.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`manyfold.noFiles`)}):(0,R.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:F.files.map(e=>{let t=e.library_file,r=t!==null&&oe({filename:t.filename},ee,re);return(0,R.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2`,children:[_&&I.length>0&&(0,R.jsx)(`span`,{className:`w-4 shrink-0 flex`,children:e.importable&&!t&&(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":i(`manyfold.selectFile`,{name:e.name}),checked:O.has(e.id),disabled:W,onChange:()=>A(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),className:`accent-bambu-green`})}),(0,R.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-[11px] font-mono text-bambu-gray shrink-0`,children:V(e.mime)}),(0,R.jsx)(`span`,{className:`text-sm text-white min-w-0 flex-1 break-words`,children:e.name}),(0,R.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.importable?t?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-bambu-green`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5`}),i(`manyfold.inLibrary`)]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>m(t.folder_id?`/files?folder=${t.folder_id}`:`/files`),children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),i(`manyfold.showInLibrary`)]}),r&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>n(t.id,t.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),i(`slice.action`,`Slice`)]})]}):_?(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>ae.mutate(e),children:[T===e.id?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),T===e.id?i(`manyfold.importing`):i(`manyfold.import`)]}):null:(0,R.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:i(`manyfold.notImportable`)})})]},e.id)})})})]})]})}function le(){let{t:e}=a(),{hasPermission:t}=ne(),n=t(`settings:update`),[i,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(``),[p,m]=(0,L.useState)(1),[g,b]=(0,L.useState)(null),[x,T]=(0,L.useState)(null),[E,O]=(0,L.useState)(new Map),[k,j]=(0,L.useState)(null),[M,N]=(0,L.useState)(null),P=t(`manyfold:import`),ae=o(),{showToast:oe}=h(),F=K(),I=M!==null||F.busy,z=M?e(`manyfold.collectProgress`,M):F.progress?e(`manyfold.importProgress`,F.progress):null,V=(e,t)=>O(n=>{let r=new Map(n);return r.has(e)?r.delete(e):r.set(e,t),r}),H=async()=>{let t=[...E.keys()],n=[],i=[];try{for(let e=0;er.getManyfoldModel(t[e])});for(let e of i.files)e.importable&&!e.library_file&&n.push({modelId:i.id,fileId:e.id,name:`${i.name}: ${e.name}`})}catch{i.push(E.get(t[e])??t[e])}}}finally{N(null)}i.length&&oe(e(`manyfold.modelsUnreadable`,{names:G(i)}),`error`),await F.run(n,k),O(new Map)},le=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),q=s({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus()}),ue=q.data?.configured??!1,J=s({queryKey:[`manyfold-models`,d,p],queryFn:()=>r.listManyfoldModels(d,p),enabled:ue,placeholderData:e=>e}),Y=async(e,t)=>{if(le.data?.use_slicer_api){T({kind:`libraryFile`,id:e,filename:t});return}let n=ie(le.data?.open_in_slicer,le.data?.preferred_slicer);try{let{token:i}=await r.createLibrarySlicerToken(e);re(`${window.location.origin}${r.getLibrarySlicerDownloadUrl(e,i,t)}`,n)}catch{re(`${window.location.origin}${r.getLibraryFileDownloadUrl(e)}`,n)}};if(q.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!ue||i)return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:e(`manyfold.description`)}),n?(0,R.jsx)(W,{onDone:ue?()=>c(!1):void 0}):(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`py-2`,children:[(0,R.jsx)(`p`,{className:`font-medium text-white`,children:e(`manyfold.notConnectedTitle`)}),(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`manyfold.notConnectedBody`)})]})})})]});let X=J.data;return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[g?(0,R.jsx)(ce,{modelId:g,onBack:()=>b(null),onSlice:Y}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray flex-1 min-w-[16rem]`,children:e(`manyfold.description`)}),n&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),children:[(0,R.jsx)(A,{className:`w-4 h-4`}),e(`manyfold.editConnection`)]})]}),(0,R.jsxs)(`form`,{className:`flex gap-2`,role:`search`,onSubmit:e=>{e.preventDefault(),f(l.trim()),m(1)},children:[(0,R.jsxs)(`div`,{className:`relative flex-1`,children:[(0,R.jsx)(y,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,R.jsx)(`input`,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:e(`manyfold.searchPlaceholder`),"aria-label":e(`manyfold.searchPlaceholder`),className:`w-full pl-9 pr-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,R.jsx)(w,{type:`submit`,children:e(`common.search`)})]}),J.isError?(0,R.jsx)(`p`,{className:`text-sm text-red-400`,children:B(J.error,e)}):X?X.models.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.noModels`)}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.modelCount`,{count:X.total})}),P&&(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:I,onClick:()=>O(e=>{let t=new Map(e);for(let e of X.models)t.set(e.id,e.name);return t}),children:e(`manyfold.selectPage`)})]}),P&&E.size>0&&(0,R.jsxs)(`div`,{className:`sticky top-0 z-10 flex flex-wrap items-center gap-3 rounded-lg border border-bambu-green/40 bg-bambu-dark-secondary px-4 py-3`,children:[(0,R.jsx)(`span`,{className:`text-sm text-white`,children:e(`manyfold.modelsSelected`,{count:E.size})}),(0,R.jsx)(se,{value:k,onChange:j,disabled:I}),z?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),z]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,onClick:H,children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),e(`manyfold.importModels`)]}),(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>O(new Map),children:e(`manyfold.clearSelection`)})]})]}),(0,R.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4`,children:X.models.map(t=>{let n=E.has(t.id);return(0,R.jsxs)(`div`,{className:`relative rounded-lg border bg-bambu-dark-secondary overflow-hidden transition-colors ${n?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green`}`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>b(t.id),disabled:I,className:`block w-full text-left disabled:cursor-wait`,children:[(0,R.jsx)(U,{modelId:t.id,className:`aspect-square`}),(0,R.jsx)(`span`,{className:`block px-3 py-2 text-sm text-white truncate`,title:t.name,children:t.name})]}),P&&(0,R.jsx)(`label`,{className:`absolute top-2 left-2 flex items-center justify-center w-7 h-7 rounded bg-black/60 cursor-pointer`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":e(`manyfold.selectModel`,{name:t.name}),checked:n,disabled:I,onChange:()=>V(t.id,t.name),className:`accent-bambu-green w-4 h-4`})})]},t.id)})}),(X.has_previous||X.has_next)&&(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_previous||J.isFetching,onClick:()=>m(e=>Math.max(1,e-1)),children:[(0,R.jsx)(ee,{className:`w-4 h-4`}),e(`manyfold.previous`)]}),(0,R.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.page`,{page:X.page})}),(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_next||J.isFetching,onClick:()=>m(e=>e+1),children:[e(`manyfold.next`),(0,R.jsx)(D,{className:`w-4 h-4`})]})]})]}):(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})})]}),x&&(0,R.jsx)(_,{source:x,onClose:()=>T(null)})]})}function q(e,t){let n=e?.[t];return typeof n==`string`?n:``}function ue(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function J(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function Y(e,t){let n=e?.[t];return typeof n==`number`?n:null}function X(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function de(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])de(r,t+1,n);return n}function fe(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function pe(e){let[t,n]=(0,L.useState)(0);return(0,L.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function me({embedded:e=!1}={}){let{t}=a(),{hasPermission:n}=ne(),{showToast:i}=h(),l=o(),u=n(`makerworld:import`),[f,y]=(0,L.useState)(``),[k,A]=(0,L.useState)(null),[j,oe]=(0,L.useState)(null),[I,z]=(0,L.useState)(null),[B,V]=(0,L.useState)(null),[H,U]=(0,L.useState)(null),[W,se]=(0,L.useState)(``),[G,K]=(0,L.useState)({}),ce=s({queryKey:[`makerworld-status`],queryFn:()=>r.getMakerworldStatus()}),le=s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}),me=s({queryKey:[`makerworld-recent-imports`],queryFn:()=>r.getMakerworldRecentImports(10)}),he=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),ge=he.data?.use_slicer_api??!1,_e=he.data?.preferred_slicer||`bambu_studio`,ve=ie(he.data?.open_in_slicer,he.data?.preferred_slicer),ye=ge?_e:ve,be=ye===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[xe,Se]=(0,L.useState)(null),Ce=(e,t)=>{Se({kind:`libraryFile`,id:e,filename:t})},we=c({mutationFn:e=>r.resolveMakerworldUrl(e),onSuccess:(e,t)=>{A(e),se(t),K({})},onError:e=>i(e.message||t(`makerworld.errors.resolveFailed`),`error`)});(0,L.useEffect)(()=>{k!==null&&f.trim()!==W.trim()&&(A(null),se(``),K({}))},[f,k,W]);let Z=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),i(e.was_existing?t(`makerworld.alreadyInLibrary`):t(`makerworld.importSuccess`,{filename:e.filename}),`success`)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Te=c({mutationFn:({libraryFileId:e})=>r.deleteLibraryFile(e),onSuccess:(e,{profileId:n})=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),K(e=>{let t={...e};return delete t[n],t}),V(null),i(t(`makerworld.importDeleted`),`success`)},onError:e=>{V(null),i(e.message||t(`makerworld.errors.deleteFailed`),`error`)}}),Ee=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:async e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),ge?Ce(e.library_file_id,e.filename):await je(e.library_file_id,e.filename,ye)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Q=pe(Z.isPending||Ee.isPending),De=fe(Q,t),Oe=e=>{e?.preventDefault();let t=f.trim();t&&we.mutate(t)};(0,L.useEffect)(()=>{if(!H)return;let e=e=>{e.key===`Escape`?U(null):e.key===`ArrowLeft`?U(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&U(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[H]);let ke=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:q(e,`name`)||`image`,url:q(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=q(e,`cover`);return n?[{name:`cover`,url:n}]:[]},Ae=async()=>{if(!k)return;let e=k.instances.filter(e=>{let t=Y(e,`profileId`);return t!==null&&!G[t]});if(e.length!==0){z({current:0,total:e.length});try{for(let t=0;t{try{let{token:i}=await r.createLibrarySlicerToken(e),a=r.getLibrarySlicerDownloadUrl(e,i,t);re(`${window.location.origin}${a}`,n)}catch{let t=r.getLibraryFileDownloadUrl(e);re(`${window.location.origin}${t}`,n)}},$=k?.design,Me=X($,`designCreator`),Ne=k?.instances??[],Pe=(k?.already_imported_library_ids.length??0)>0,Fe=ce.data?.can_download??!1,Ie=ce.data?.sign_in_expired??!1,Le=(0,L.useMemo)(()=>q($,`coverUrl`),[$]),Re=q($,`title`),ze=q($,`summary`),Be=q($,`license`),Ve=Y($,`downloadCount`);return(0,R.jsxs)(`div`,{className:e?`space-y-6`:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[e?(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:t(`makerworld.description`)}):(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),t(`makerworld.title`)]}),(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:t(`makerworld.description`)})]}),(0,R.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,R.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!Fe&&(0,R.jsx)(C,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,R.jsx)(m,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,R.jsxs)(`div`,{className:`text-sm`,children:[(0,R.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:t(Ie?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,R.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[t(Ie?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,R.jsx)(O,{to:`/profiles`,className:`underline`,children:t(`makerworld.openCloudSettings`)})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.pasteUrlHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsxs)(`form`,{onSubmit:Oe,className:`flex gap-2`,children:[(0,R.jsx)(`input`,{type:`text`,value:f,onChange:e=>y(e.target.value),placeholder:t(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,R.jsxs)(w,{type:`submit`,variant:`primary`,disabled:!f.trim()||we.isPending,children:[we.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):(0,R.jsx)(d,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.resolveButton`)})]})]})})]}),k&&(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[Le&&(0,R.jsx)(`img`,{src:J(Le),alt:Re,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:Re||t(`makerworld.untitledModel`)}),Me&&(0,R.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:t(`makerworld.byCreator`,{name:q(Me,`name`)})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[Ve!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:Ve})}),Be&&(0,R.jsxs)(`span`,{children:[t(`makerworld.licensePrefix`),`: `,Be]}),Pe&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,R.jsx)(p,{className:`w-3 h-3`}),` `,t(`makerworld.alreadyImported`)]})]}),ze&&(0,R.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:ae.sanitize(ue(ze))}}),k&&(0,R.jsxs)(`a`,{href:`https://makerworld.com/models/${k.model_id}${k.profile_id?`#profileId-${k.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,R.jsx)(E,{className:`w-3 h-3`}),` `,t(`makerworld.openOnMakerworld`)]})]})]})})}),k&&Ne.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.platesHeader`,{count:Ne.length})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,R.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:t(`makerworld.importTo`)}),(0,R.jsxs)(`select`,{value:j??``,onChange:e=>oe(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:I!==null,children:[(0,R.jsx)(`option`,{value:``,children:t(`makerworld.folderAuto`)}),(le.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>de(e)).map(({folder:e,depth:t})=>(0,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||I!==null||Z.isPending||Ee.isPending,onClick:Ae,children:I===null?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importAll`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[t(`makerworld.importAllProgress`,{current:I.current,total:I.total}),Q>0&&` · ${De} · ${Q}s`]})]})})]})]})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`grid gap-3`,children:Ne.map((e,n)=>{let r=Y(e,`id`),i=Y(e,`profileId`),a=q(e,`title`),o=q(e,`cover`),s=Y(e,`materialCnt`),c=e?.needAms===!0,l=Y(e,`downloadCount`),d=e?.compatibility??null,f=e?.otherCompatibility??null,m=d?.devProductName??null,h=Array.isArray(f)?f.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let _=Z.isPending&&Z.variables?.instanceId===r,y=Ee.isPending&&Ee.variables?.instanceId===r,b=i===null?void 0:G[i];return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,R.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=ke(e),r=n.length>0;return(0,R.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&U({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":t(`makerworld.openGallery`),children:[o?(0,R.jsx)(`img`,{src:J(o),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,R.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,R.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,R.jsx)(F,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`p`,{className:`font-medium truncate`,children:a||t(`makerworld.plateDefaultName`,{n:n+1})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[m&&(0,R.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:t(`makerworld.slicedFor`,{printer:m,defaultValue:`Sliced for {{printer}}`})}),s!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.materialCount`,{count:s})}),c&&(0,R.jsx)(`span`,{children:t(`makerworld.amsRequired`)}),l!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:l})})]}),h.length>0&&(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:h.join(`, `),children:t(`makerworld.alsoCompatible`,{printers:h.slice(0,6).join(`, `)+(h.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,R.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Z.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:_?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importToLibrary`)})]})}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Ee.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:y?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(E,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.sliceIn`,{slicer:be})})]})})]})]}),b&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,R.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:b.was_existing?t(`makerworld.lastImportAlreadyInLibrary`):t(`makerworld.lastImportSuccess`)}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>{let e=b.folder_id?`/files?folder=${b.folder_id}`:`/files`;window.location.assign(e)},children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.viewInLibrary`)})]}),ge?(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(b.library_file_id,b.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`slice.action`,`Slice`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`bambu_studio`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInBambuStudio`)})]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`orcaslicer`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInOrcaSlicer`)})]})]}),(0,R.jsx)(`div`,{className:`ml-auto`,children:(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:Te.isPending&&Te.variables?.profileId===i,onClick:()=>{i!==null&&V({libraryFileId:b.library_file_id,profileId:i,filename:b.filename})},title:t(`makerworld.deleteImport`),children:Te.isPending&&Te.variables?.profileId===i?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(T,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,R.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:me.data&&me.data.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-base font-semibold`,children:t(`makerworld.recentImportsHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:me.data.map(e=>(0,R.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[e.thumbnail_path?(0,R.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,R.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,R.jsx)(`p`,{className:`text-xs font-medium truncate`,title:e.filename,children:e.filename}),(0,R.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>{let t=e.folder_id?`/files?folder=${e.folder_id}`:`/files`;window.location.assign(t)},title:t(`makerworld.viewInLibrary`),children:(0,R.jsx)(P,{className:`w-3.5 h-3.5`})}),ge?(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(e.library_file_id,e.filename),title:t(`slice.action`,`Slice`),children:(0,R.jsx)(g,{className:`w-3.5 h-3.5`})}):(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(e.library_file_id,e.filename,`bambu_studio`),title:t(`makerworld.openInBambuStudio`),children:(0,R.jsx)(E,{className:`w-3.5 h-3.5`})}),e.source_url&&(0,R.jsx)(`a`,{href:e.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:t(`makerworld.openOnMakerworld`),children:(0,R.jsx)(N,{className:`w-3.5 h-3.5`})})]})]})]},e.library_file_id))})})]})})]}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:t(`makerworld.disclaimer`)}),B&&(0,R.jsx)(M,{title:t(`makerworld.deleteImport`),message:t(`makerworld.confirmDelete`,{filename:B.filename}),confirmText:t(`makerworld.deleteImport`),variant:`danger`,isLoading:Te.isPending,loadingText:t(`makerworld.importDeleting`),onCancel:()=>V(null),onConfirm:()=>Te.mutate({libraryFileId:B.libraryFileId,profileId:B.profileId})}),xe&&(0,R.jsx)(_,{source:xe,onClose:()=>Se(null)}),H&&(0,R.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>U(null),role:`dialog`,"aria-modal":`true`,children:[(0,R.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),U(null)},"aria-label":t(`common.close`,`Close`),children:(0,R.jsx)(b,{className:`w-5 h-5`})}),H.images.length>1&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:H.index===0,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":t(`makerworld.galleryPrev`),children:(0,R.jsx)(ee,{className:`w-6 h-6`})}),(0,R.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:H.index>=H.images.length-1,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":t(`makerworld.galleryNext`),children:(0,R.jsx)(D,{className:`w-6 h-6`})})]}),(0,R.jsx)(`img`,{src:J(H.images[H.index].url),alt:H.images[H.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),H.images.length>1&&(0,R.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[H.index+1,` / `,H.images.length]})]})]})}function he(){let{t:e}=a(),{hasPermission:t}=ne(),[n,i]=j(),o=t(`manyfold:view`),c=s({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus(),enabled:o}),l=o&&(c.data?.configured===!0||t(`settings:update`)),u=[];t(`makerworld:view`)&&u.push({id:`makerworld`,label:e(`modelSources.tabMakerworld`),icon:N}),l&&u.push({id:`manyfold`,label:e(`modelSources.tabManyfold`),icon:I});let d=n.get(`tab`),f=u.find(e=>e.id===d)?.id??u[0]?.id??(o?`manyfold`:void 0);return(0,R.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl`,children:[(0,R.jsx)(`div`,{className:`mb-6`,children:(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),e(`modelSources.title`)]})}),u.length>1&&(0,R.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,role:`tablist`,children:u.map(({id:e,label:t,icon:n})=>(0,R.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":f===e,onClick:()=>i({tab:e},{replace:!0}),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${f===e?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,R.jsx)(n,{className:`w-4 h-4`}),t]},e))}),f===`makerworld`&&(0,R.jsx)(me,{embedded:!0}),f===`manyfold`&&(0,R.jsx)(le,{})]})}export{he as ModelSourcesPage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-BdOyoZJz.js";import{n as o}from"./QueryClientProvider-Clbyr4Jg.js";import{t as s}from"./useQuery-CCy0EwsM.js";import{t as c}from"./useMutation-qh3Iyscy.js";import{t as l}from"./createLucideIcon-Yo2YoYjm.js";import{t as u}from"./arrow-left-MSgMxOFV.js";import{t as d}from"./arrow-right-Da96kh4S.js";import{t as f}from"./box-BIRPxdgi.js";import{t as p}from"./check-D1Pn8T1J.js";import{r as m}from"./info-DcT0QU8O.js";import{n as h}from"./ToastContext-VFOrCCoA.js";import{t as g}from"./cog-pa-nvQzt.js";import{t as _}from"./SliceModal-C_D5egPX.js";import{t as v}from"./loader-circle-CB4leTZa.js";import{t as y}from"./search-BpAJdxRw.js";import{t as b}from"./x-Dctff5l9.js";import{i as x,n as S,t as C}from"./Card-OUAj0Ayh.js";import{t as w}from"./Button-pwVKPiYn.js";import{At as T,Cn as E,Mn as D,Rn as O,Vn as k,Vt as A,Wn as j,_t as M,hn as N,jn as ee,vn as P,wn as te,yt as ne}from"./index-ggB_TpPo.js";import{a as re,o as ie}from"./slicer-DgCA7cW6.js";import{t as ae}from"./purify.es-F_7NWVtX.js";import{t as oe}from"./libraryFiles-B0B1SFfn.js";var F=l(`images`,[[`path`,{d:`m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16`,key:`9kzy35`}],[`path`,{d:`M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2`,key:`1t0f0t`}],[`circle`,{cx:`13`,cy:`7`,r:`1`,fill:`currentColor`,key:`1obus6`}],[`rect`,{x:`8`,y:`2`,width:`14`,height:`14`,rx:`2`,key:`1gvhby`}]]),I=l(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),L=e(n(),1),R=t(),z=new Set([`manyfold_not_configured`,`manyfold_credentials`,`manyfold_scope`,`manyfold_rate_limited`,`manyfold_unreachable`,`manyfold_forbidden`,`manyfold_not_found`,`manyfold_too_large`,`manyfold_not_importable`,`manyfold_bad_url`,`manyfold_secret_required`,`manyfold_failed`]);function B(e,t){return e instanceof i&&e.code&&z.has(e.code)?t(`manyfold.errors.${e.code}`):e instanceof Error&&e.message?e.message:t(`manyfold.errors.manyfold_failed`)}function V(e){return((e.split(`/`)[1]??``).replace(/^x-/,``).split(/[+.;]/)[0]||`?`).toUpperCase()}function H(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])H(r,t+1,n);return n}function U({modelId:e,className:t}){let{data:n,isLoading:i}=s({queryKey:[`manyfold-preview`,e],queryFn:()=>r.getManyfoldPreview(e),staleTime:1/0,retry:!1}),[a,o]=(0,L.useState)(null);return(0,L.useEffect)(()=>{if(!n){o(null);return}let e=URL.createObjectURL(n);return o(e),()=>URL.revokeObjectURL(e)},[n]),(0,R.jsx)(`div`,{className:`flex items-center justify-center bg-bambu-dark overflow-hidden ${t??``}`,children:a?(0,R.jsx)(`img`,{src:a,alt:``,className:`w-full h-full object-contain`}):i?(0,R.jsx)(v,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,R.jsx)(f,{className:`w-10 h-10 text-bambu-gray/50`,"aria-hidden":!0})})}function W({onDone:e}){let{t}=a(),{showToast:n}=h(),i=o(),l=s({queryKey:[`manyfold-config`],queryFn:()=>r.getManyfoldConfig()}),[u,d]=(0,L.useState)(``),[f,p]=(0,L.useState)(``),[m,g]=(0,L.useState)(``),[_,y]=(0,L.useState)(null),[b,T]=(0,L.useState)(!1);(0,L.useEffect)(()=>{l.data&&(d(l.data.url),p(l.data.client_id))},[l.data]);let E=l.data?.has_client_secret??!1,D={url:u.trim(),client_id:f.trim(),client_secret:m.trim()||void 0},O=!!D.url&&!!D.client_id&&(!!D.client_secret||E),k=()=>{i.invalidateQueries({queryKey:[`manyfold-config`]}),i.invalidateQueries({queryKey:[`manyfold-status`]}),i.invalidateQueries({queryKey:[`manyfold-models`]}),i.invalidateQueries({queryKey:[`manyfold-model`]}),i.invalidateQueries({queryKey:[`manyfold-preview`]})},j=c({mutationFn:()=>r.testManyfoldConfig(D),onSuccess:e=>y({ok:!0,text:t(`manyfold.testOk`,{count:e.model_count})}),onError:e=>y({ok:!1,text:B(e,t)})}),N=c({mutationFn:()=>r.updateManyfoldConfig(D),onSuccess:()=>{g(``),k(),n(t(`settings.toast.settingsSaved`),`success`),e?.()},onError:e=>n(B(e,t),`error`)}),ee=c({mutationFn:()=>r.deleteManyfoldConfig(),onSuccess:()=>{T(!1),d(``),p(``),g(``),y(null),k(),n(t(`manyfold.disconnected`),`success`)},onError:e=>{T(!1),n(B(e,t),`error`)}}),P=`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`;return(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,R.jsx)(A,{className:`w-5 h-5 text-bambu-green`}),t(`manyfold.connectionTitle`)]})}),(0,R.jsxs)(S,{className:`space-y-4`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`manyfold.connectionHelp`)}),(0,R.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),O&&N.mutate()},children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-url`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.url`)}),(0,R.jsx)(`input`,{id:`manyfold-url`,type:`url`,value:u,onChange:e=>{d(e.target.value),y(null)},placeholder:t(`manyfold.urlPlaceholder`),className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-id`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientId`)}),(0,R.jsx)(`input`,{id:`manyfold-client-id`,type:`text`,value:f,onChange:e=>{p(e.target.value),y(null)},className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-secret`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientSecret`)}),(0,R.jsx)(`input`,{id:`manyfold-client-secret`,type:`password`,value:m,onChange:e=>{g(e.target.value),y(null)},placeholder:E?t(`manyfold.clientSecretStored`):``,className:P,autoComplete:`new-password`})]}),_&&(0,R.jsx)(`p`,{role:`status`,className:`text-sm ${_.ok?`text-bambu-green`:`text-red-400`}`,children:_.text}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,R.jsxs)(w,{type:`submit`,disabled:!O||N.isPending,children:[N.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`common.save`)]}),(0,R.jsxs)(w,{type:`button`,variant:`secondary`,disabled:!O||j.isPending,onClick:()=>j.mutate(),children:[j.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`manyfold.test`)]}),l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`danger`,onClick:()=>T(!0),children:t(`manyfold.disconnect`)}),e&&l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`ghost`,onClick:e,children:t(`common.cancel`)})]})]})]}),b&&(0,R.jsx)(M,{title:t(`manyfold.disconnectTitle`),message:t(`manyfold.disconnectBody`),confirmText:t(`manyfold.disconnect`),variant:`danger`,isLoading:ee.isPending,onCancel:()=>T(!1),onConfirm:()=>ee.mutate()})]})}function se({value:e,onChange:t,disabled:n}){let{t:i}=a(),o=(s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}).data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>H(e));return(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[i(`manyfold.importTo`),(0,R.jsxs)(`select`,{value:e??``,disabled:n,onChange:e=>t(e.target.value?Number(e.target.value):null),className:`px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,children:[(0,R.jsx)(`option`,{value:``,children:i(`manyfold.folderAuto`)}),o.map(({folder:e,depth:t})=>(0,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]})]})}function G(e){return e.length>3?`${e.slice(0,3).join(`, `)} +${e.length-3}`:e.join(`, `)}function K(){let{t:e}=a(),{showToast:t}=h(),n=o(),[i,s]=(0,L.useState)(null);return{run:async(i,a)=>{if(i.length===0){t(e(`manyfold.bulkNothing`),`info`);return}let o=0,c=0,l=[],u=null;try{for(let e=0;er.getManyfoldModel(e)}),N=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),ee=N.data?.use_slicer_api??!1,re=ie(N.data?.open_in_slicer,N.data?.preferred_slicer),ae=c({mutationFn:t=>r.importManyfoldFile(e,t.id,y),onMutate:e=>D(e.id),onSettled:()=>D(null),onSuccess:t=>{f.invalidateQueries({queryKey:[`manyfold-model`,e]}),f.invalidateQueries({queryKey:[`library-files`]}),f.invalidateQueries({queryKey:[`library-folders`]}),d(t.was_existing?i(`manyfold.alreadyInLibrary`):i(`manyfold.imported`,{filename:t.filename}),`success`)},onError:e=>d(B(e,i),`error`)});if(M.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(M.isError||!M.data)return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(`p`,{className:`text-red-400 text-sm`,children:B(M.error,i)})]});let F=M.data,I=F.files.filter(e=>e.importable&&!e.library_file),z=I.filter(e=>O.has(e.id)),H=I.length>0&&z.length===I.length,W=j.busy||ae.isPending,G=async e=>{await j.run(e.map(e=>({modelId:F.id,fileId:e.id,name:e.name})),y),A(new Set)};return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-6 py-2`,children:[(0,R.jsx)(U,{modelId:F.id,className:`w-full md:w-72 aspect-square rounded-lg shrink-0`}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-xl font-semibold text-white break-words`,children:F.name}),F.caption&&(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:F.caption})]}),F.description&&(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray whitespace-pre-line break-words`,children:F.description}),F.tags.length>0&&(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:F.tags.map(e=>(0,R.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-xs text-white`,children:e},e))}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 text-sm`,children:[F.license&&(0,R.jsxs)(`span`,{className:`text-bambu-gray`,children:[i(`manyfold.license`),`: `,(0,R.jsx)(`span`,{className:`text-white`,children:F.license})]}),(0,R.jsxs)(`a`,{href:F.url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-bambu-green hover:underline`,children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),i(`manyfold.openInManyfold`)]})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsxs)(x,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:i(`manyfold.files`)}),_&&(0,R.jsx)(se,{value:y,onChange:b,disabled:W})]}),_&&I.length>0&&(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-3`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:H,ref:e=>{e&&(e.indeterminate=z.length>0&&!H)},disabled:W,onChange:()=>A(H?new Set:new Set(I.map(e=>e.id))),className:`accent-bambu-green`}),i(`manyfold.selectAll`)]}),j.progress?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),i(`manyfold.importProgress`,j.progress)]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,disabled:W||z.length===0,onClick:()=>G(z),children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),i(`manyfold.importSelected`,{count:z.length})]}),(0,R.jsx)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>G(I),children:i(`manyfold.importAll`)})]})]})]}),(0,R.jsx)(S,{children:F.files.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`manyfold.noFiles`)}):(0,R.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:F.files.map(e=>{let t=e.library_file,r=t!==null&&oe({filename:t.filename},ee,re);return(0,R.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2`,children:[_&&I.length>0&&(0,R.jsx)(`span`,{className:`w-4 shrink-0 flex`,children:e.importable&&!t&&(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":i(`manyfold.selectFile`,{name:e.name}),checked:O.has(e.id),disabled:W,onChange:()=>A(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),className:`accent-bambu-green`})}),(0,R.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-[11px] font-mono text-bambu-gray shrink-0`,children:V(e.mime)}),(0,R.jsx)(`span`,{className:`text-sm text-white min-w-0 flex-1 break-words`,children:e.name}),(0,R.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.importable?t?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-bambu-green`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5`}),i(`manyfold.inLibrary`)]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>m(t.folder_id?`/files?folder=${t.folder_id}`:`/files`),children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),i(`manyfold.showInLibrary`)]}),r&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>n(t.id,t.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),i(`slice.action`,`Slice`)]})]}):_?(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>ae.mutate(e),children:[T===e.id?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),T===e.id?i(`manyfold.importing`):i(`manyfold.import`)]}):null:(0,R.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:i(`manyfold.notImportable`)})})]},e.id)})})})]})]})}function le(){let{t:e}=a(),{hasPermission:t}=ne(),n=t(`settings:update`),[i,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(``),[p,m]=(0,L.useState)(1),[g,b]=(0,L.useState)(null),[x,T]=(0,L.useState)(null),[E,O]=(0,L.useState)(new Map),[k,j]=(0,L.useState)(null),[M,N]=(0,L.useState)(null),P=t(`manyfold:import`),ae=o(),{showToast:oe}=h(),F=K(),I=M!==null||F.busy,z=M?e(`manyfold.collectProgress`,M):F.progress?e(`manyfold.importProgress`,F.progress):null,V=(e,t)=>O(n=>{let r=new Map(n);return r.has(e)?r.delete(e):r.set(e,t),r}),H=async()=>{let t=[...E.keys()],n=[],i=[];try{for(let e=0;er.getManyfoldModel(t[e])});for(let e of i.files)e.importable&&!e.library_file&&n.push({modelId:i.id,fileId:e.id,name:`${i.name}: ${e.name}`})}catch{i.push(E.get(t[e])??t[e])}}}finally{N(null)}i.length&&oe(e(`manyfold.modelsUnreadable`,{names:G(i)}),`error`),await F.run(n,k),O(new Map)},le=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),q=s({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus()}),ue=q.data?.configured??!1,J=s({queryKey:[`manyfold-models`,d,p],queryFn:()=>r.listManyfoldModels(d,p),enabled:ue,placeholderData:e=>e}),Y=async(e,t)=>{if(le.data?.use_slicer_api){T({kind:`libraryFile`,id:e,filename:t});return}let n=ie(le.data?.open_in_slicer,le.data?.preferred_slicer);try{let{token:i}=await r.createLibrarySlicerToken(e);re(`${window.location.origin}${r.getLibrarySlicerDownloadUrl(e,i,t)}`,n)}catch{re(`${window.location.origin}${r.getLibraryFileDownloadUrl(e)}`,n)}};if(q.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!ue||i)return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:e(`manyfold.description`)}),n?(0,R.jsx)(W,{onDone:ue?()=>c(!1):void 0}):(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`py-2`,children:[(0,R.jsx)(`p`,{className:`font-medium text-white`,children:e(`manyfold.notConnectedTitle`)}),(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`manyfold.notConnectedBody`)})]})})})]});let X=J.data;return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[g?(0,R.jsx)(ce,{modelId:g,onBack:()=>b(null),onSlice:Y}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray flex-1 min-w-[16rem]`,children:e(`manyfold.description`)}),n&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),children:[(0,R.jsx)(A,{className:`w-4 h-4`}),e(`manyfold.editConnection`)]})]}),(0,R.jsxs)(`form`,{className:`flex gap-2`,role:`search`,onSubmit:e=>{e.preventDefault(),f(l.trim()),m(1)},children:[(0,R.jsxs)(`div`,{className:`relative flex-1`,children:[(0,R.jsx)(y,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,R.jsx)(`input`,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:e(`manyfold.searchPlaceholder`),"aria-label":e(`manyfold.searchPlaceholder`),className:`w-full pl-9 pr-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,R.jsx)(w,{type:`submit`,children:e(`common.search`)})]}),J.isError?(0,R.jsx)(`p`,{className:`text-sm text-red-400`,children:B(J.error,e)}):X?X.models.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.noModels`)}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.modelCount`,{count:X.total})}),P&&(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:I,onClick:()=>O(e=>{let t=new Map(e);for(let e of X.models)t.set(e.id,e.name);return t}),children:e(`manyfold.selectPage`)})]}),P&&E.size>0&&(0,R.jsxs)(`div`,{className:`sticky top-0 z-10 flex flex-wrap items-center gap-3 rounded-lg border border-bambu-green/40 bg-bambu-dark-secondary px-4 py-3`,children:[(0,R.jsx)(`span`,{className:`text-sm text-white`,children:e(`manyfold.modelsSelected`,{count:E.size})}),(0,R.jsx)(se,{value:k,onChange:j,disabled:I}),z?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),z]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,onClick:H,children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),e(`manyfold.importModels`)]}),(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>O(new Map),children:e(`manyfold.clearSelection`)})]})]}),(0,R.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4`,children:X.models.map(t=>{let n=E.has(t.id);return(0,R.jsxs)(`div`,{className:`relative rounded-lg border bg-bambu-dark-secondary overflow-hidden transition-colors ${n?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green`}`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>b(t.id),disabled:I,className:`block w-full text-left disabled:cursor-wait`,children:[(0,R.jsx)(U,{modelId:t.id,className:`aspect-square`}),(0,R.jsx)(`span`,{className:`block px-3 py-2 text-sm text-white truncate`,title:t.name,children:t.name})]}),P&&(0,R.jsx)(`label`,{className:`absolute top-2 left-2 flex items-center justify-center w-7 h-7 rounded bg-black/60 cursor-pointer`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":e(`manyfold.selectModel`,{name:t.name}),checked:n,disabled:I,onChange:()=>V(t.id,t.name),className:`accent-bambu-green w-4 h-4`})})]},t.id)})}),(X.has_previous||X.has_next)&&(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_previous||J.isFetching,onClick:()=>m(e=>Math.max(1,e-1)),children:[(0,R.jsx)(ee,{className:`w-4 h-4`}),e(`manyfold.previous`)]}),(0,R.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.page`,{page:X.page})}),(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_next||J.isFetching,onClick:()=>m(e=>e+1),children:[e(`manyfold.next`),(0,R.jsx)(D,{className:`w-4 h-4`})]})]})]}):(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})})]}),x&&(0,R.jsx)(_,{source:x,onClose:()=>T(null)})]})}function q(e,t){let n=e?.[t];return typeof n==`string`?n:``}function ue(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function J(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function Y(e,t){let n=e?.[t];return typeof n==`number`?n:null}function X(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function de(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])de(r,t+1,n);return n}function fe(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function pe(e){let[t,n]=(0,L.useState)(0);return(0,L.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function me({embedded:e=!1}={}){let{t}=a(),{hasPermission:n}=ne(),{showToast:i}=h(),l=o(),u=n(`makerworld:import`),[f,y]=(0,L.useState)(``),[k,A]=(0,L.useState)(null),[j,oe]=(0,L.useState)(null),[I,z]=(0,L.useState)(null),[B,V]=(0,L.useState)(null),[H,U]=(0,L.useState)(null),[W,se]=(0,L.useState)(``),[G,K]=(0,L.useState)({}),ce=s({queryKey:[`makerworld-status`],queryFn:()=>r.getMakerworldStatus()}),le=s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}),me=s({queryKey:[`makerworld-recent-imports`],queryFn:()=>r.getMakerworldRecentImports(10)}),he=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),ge=he.data?.use_slicer_api??!1,_e=he.data?.preferred_slicer||`bambu_studio`,ve=ie(he.data?.open_in_slicer,he.data?.preferred_slicer),ye=ge?_e:ve,be=ye===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[xe,Se]=(0,L.useState)(null),Ce=(e,t)=>{Se({kind:`libraryFile`,id:e,filename:t})},we=c({mutationFn:e=>r.resolveMakerworldUrl(e),onSuccess:(e,t)=>{A(e),se(t),K({})},onError:e=>i(e.message||t(`makerworld.errors.resolveFailed`),`error`)});(0,L.useEffect)(()=>{k!==null&&f.trim()!==W.trim()&&(A(null),se(``),K({}))},[f,k,W]);let Z=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),i(e.was_existing?t(`makerworld.alreadyInLibrary`):t(`makerworld.importSuccess`,{filename:e.filename}),`success`)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Te=c({mutationFn:({libraryFileId:e})=>r.deleteLibraryFile(e),onSuccess:(e,{profileId:n})=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),K(e=>{let t={...e};return delete t[n],t}),V(null),i(t(`makerworld.importDeleted`),`success`)},onError:e=>{V(null),i(e.message||t(`makerworld.errors.deleteFailed`),`error`)}}),Ee=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:async e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),ge?Ce(e.library_file_id,e.filename):await je(e.library_file_id,e.filename,ye)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Q=pe(Z.isPending||Ee.isPending),De=fe(Q,t),Oe=e=>{e?.preventDefault();let t=f.trim();t&&we.mutate(t)};(0,L.useEffect)(()=>{if(!H)return;let e=e=>{e.key===`Escape`?U(null):e.key===`ArrowLeft`?U(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&U(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[H]);let ke=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:q(e,`name`)||`image`,url:q(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=q(e,`cover`);return n?[{name:`cover`,url:n}]:[]},Ae=async()=>{if(!k)return;let e=k.instances.filter(e=>{let t=Y(e,`profileId`);return t!==null&&!G[t]});if(e.length!==0){z({current:0,total:e.length});try{for(let t=0;t{try{let{token:i}=await r.createLibrarySlicerToken(e),a=r.getLibrarySlicerDownloadUrl(e,i,t);re(`${window.location.origin}${a}`,n)}catch{let t=r.getLibraryFileDownloadUrl(e);re(`${window.location.origin}${t}`,n)}},$=k?.design,Me=X($,`designCreator`),Ne=k?.instances??[],Pe=(k?.already_imported_library_ids.length??0)>0,Fe=ce.data?.can_download??!1,Ie=ce.data?.sign_in_expired??!1,Le=(0,L.useMemo)(()=>q($,`coverUrl`),[$]),Re=q($,`title`),ze=q($,`summary`),Be=q($,`license`),Ve=Y($,`downloadCount`);return(0,R.jsxs)(`div`,{className:e?`space-y-6`:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[e?(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:t(`makerworld.description`)}):(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),t(`makerworld.title`)]}),(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:t(`makerworld.description`)})]}),(0,R.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,R.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!Fe&&(0,R.jsx)(C,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,R.jsx)(m,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,R.jsxs)(`div`,{className:`text-sm`,children:[(0,R.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:t(Ie?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,R.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[t(Ie?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,R.jsx)(O,{to:`/profiles`,className:`underline`,children:t(`makerworld.openCloudSettings`)})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.pasteUrlHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsxs)(`form`,{onSubmit:Oe,className:`flex gap-2`,children:[(0,R.jsx)(`input`,{type:`text`,value:f,onChange:e=>y(e.target.value),placeholder:t(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,R.jsxs)(w,{type:`submit`,variant:`primary`,disabled:!f.trim()||we.isPending,children:[we.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):(0,R.jsx)(d,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.resolveButton`)})]})]})})]}),k&&(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[Le&&(0,R.jsx)(`img`,{src:J(Le),alt:Re,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:Re||t(`makerworld.untitledModel`)}),Me&&(0,R.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:t(`makerworld.byCreator`,{name:q(Me,`name`)})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[Ve!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:Ve})}),Be&&(0,R.jsxs)(`span`,{children:[t(`makerworld.licensePrefix`),`: `,Be]}),Pe&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,R.jsx)(p,{className:`w-3 h-3`}),` `,t(`makerworld.alreadyImported`)]})]}),ze&&(0,R.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:ae.sanitize(ue(ze))}}),k&&(0,R.jsxs)(`a`,{href:`https://makerworld.com/models/${k.model_id}${k.profile_id?`#profileId-${k.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,R.jsx)(E,{className:`w-3 h-3`}),` `,t(`makerworld.openOnMakerworld`)]})]})]})})}),k&&Ne.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.platesHeader`,{count:Ne.length})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,R.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:t(`makerworld.importTo`)}),(0,R.jsxs)(`select`,{value:j??``,onChange:e=>oe(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:I!==null,children:[(0,R.jsx)(`option`,{value:``,children:t(`makerworld.folderAuto`)}),(le.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>de(e)).map(({folder:e,depth:t})=>(0,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||I!==null||Z.isPending||Ee.isPending,onClick:Ae,children:I===null?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importAll`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[t(`makerworld.importAllProgress`,{current:I.current,total:I.total}),Q>0&&` · ${De} · ${Q}s`]})]})})]})]})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`grid gap-3`,children:Ne.map((e,n)=>{let r=Y(e,`id`),i=Y(e,`profileId`),a=q(e,`title`),o=q(e,`cover`),s=Y(e,`materialCnt`),c=e?.needAms===!0,l=Y(e,`downloadCount`),d=e?.compatibility??null,f=e?.otherCompatibility??null,m=d?.devProductName??null,h=Array.isArray(f)?f.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let _=Z.isPending&&Z.variables?.instanceId===r,y=Ee.isPending&&Ee.variables?.instanceId===r,b=i===null?void 0:G[i];return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,R.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=ke(e),r=n.length>0;return(0,R.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&U({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":t(`makerworld.openGallery`),children:[o?(0,R.jsx)(`img`,{src:J(o),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,R.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,R.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,R.jsx)(F,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`p`,{className:`font-medium truncate`,children:a||t(`makerworld.plateDefaultName`,{n:n+1})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[m&&(0,R.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:t(`makerworld.slicedFor`,{printer:m,defaultValue:`Sliced for {{printer}}`})}),s!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.materialCount`,{count:s})}),c&&(0,R.jsx)(`span`,{children:t(`makerworld.amsRequired`)}),l!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:l})})]}),h.length>0&&(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:h.join(`, `),children:t(`makerworld.alsoCompatible`,{printers:h.slice(0,6).join(`, `)+(h.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,R.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Z.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:_?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importToLibrary`)})]})}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Ee.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:y?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(E,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.sliceIn`,{slicer:be})})]})})]})]}),b&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,R.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:b.was_existing?t(`makerworld.lastImportAlreadyInLibrary`):t(`makerworld.lastImportSuccess`)}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>{let e=b.folder_id?`/files?folder=${b.folder_id}`:`/files`;window.location.assign(e)},children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.viewInLibrary`)})]}),ge?(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(b.library_file_id,b.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`slice.action`,`Slice`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`bambu_studio`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInBambuStudio`)})]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`orcaslicer`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInOrcaSlicer`)})]})]}),(0,R.jsx)(`div`,{className:`ml-auto`,children:(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:Te.isPending&&Te.variables?.profileId===i,onClick:()=>{i!==null&&V({libraryFileId:b.library_file_id,profileId:i,filename:b.filename})},title:t(`makerworld.deleteImport`),children:Te.isPending&&Te.variables?.profileId===i?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(T,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,R.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:me.data&&me.data.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-base font-semibold`,children:t(`makerworld.recentImportsHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:me.data.map(e=>(0,R.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[e.thumbnail_path?(0,R.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,R.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,R.jsx)(`p`,{className:`text-xs font-medium truncate`,title:e.filename,children:e.filename}),(0,R.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>{let t=e.folder_id?`/files?folder=${e.folder_id}`:`/files`;window.location.assign(t)},title:t(`makerworld.viewInLibrary`),children:(0,R.jsx)(P,{className:`w-3.5 h-3.5`})}),ge?(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(e.library_file_id,e.filename),title:t(`slice.action`,`Slice`),children:(0,R.jsx)(g,{className:`w-3.5 h-3.5`})}):(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(e.library_file_id,e.filename,`bambu_studio`),title:t(`makerworld.openInBambuStudio`),children:(0,R.jsx)(E,{className:`w-3.5 h-3.5`})}),e.source_url&&(0,R.jsx)(`a`,{href:e.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:t(`makerworld.openOnMakerworld`),children:(0,R.jsx)(N,{className:`w-3.5 h-3.5`})})]})]})]},e.library_file_id))})})]})})]}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:t(`makerworld.disclaimer`)}),B&&(0,R.jsx)(M,{title:t(`makerworld.deleteImport`),message:t(`makerworld.confirmDelete`,{filename:B.filename}),confirmText:t(`makerworld.deleteImport`),variant:`danger`,isLoading:Te.isPending,loadingText:t(`makerworld.importDeleting`),onCancel:()=>V(null),onConfirm:()=>Te.mutate({libraryFileId:B.libraryFileId,profileId:B.profileId})}),xe&&(0,R.jsx)(_,{source:xe,onClose:()=>Se(null)}),H&&(0,R.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>U(null),role:`dialog`,"aria-modal":`true`,children:[(0,R.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),U(null)},"aria-label":t(`common.close`,`Close`),children:(0,R.jsx)(b,{className:`w-5 h-5`})}),H.images.length>1&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:H.index===0,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":t(`makerworld.galleryPrev`),children:(0,R.jsx)(ee,{className:`w-6 h-6`})}),(0,R.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:H.index>=H.images.length-1,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":t(`makerworld.galleryNext`),children:(0,R.jsx)(D,{className:`w-6 h-6`})})]}),(0,R.jsx)(`img`,{src:J(H.images[H.index].url),alt:H.images[H.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),H.images.length>1&&(0,R.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[H.index+1,` / `,H.images.length]})]})]})}function he(){let{t:e}=a(),{hasPermission:t}=ne(),[n,i]=j(),o=t(`manyfold:view`),c=s({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus(),enabled:o}),l=o&&(c.data?.configured===!0||t(`settings:update`)),u=[];t(`makerworld:view`)&&u.push({id:`makerworld`,label:e(`modelSources.tabMakerworld`),icon:N}),l&&u.push({id:`manyfold`,label:e(`modelSources.tabManyfold`),icon:I});let d=n.get(`tab`),f=u.find(e=>e.id===d)?.id??u[0]?.id??(o?`manyfold`:void 0);return(0,R.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl`,children:[(0,R.jsx)(`div`,{className:`mb-6`,children:(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),e(`modelSources.title`)]})}),u.length>1&&(0,R.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,role:`tablist`,children:u.map(({id:e,label:t,icon:n})=>(0,R.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":f===e,onClick:()=>i({tab:e},{replace:!0}),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${f===e?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,R.jsx)(n,{className:`w-4 h-4`}),t]},e))}),f===`makerworld`&&(0,R.jsx)(me,{embedded:!0}),f===`manyfold`&&(0,R.jsx)(le,{})]})}export{he as ModelSourcesPage};
\ No newline at end of file
diff --git a/static/assets/NotificationsPage-Wf6csR7A.js b/static/assets/NotificationsPage-B-6BvYgs.js
similarity index 99%
rename from static/assets/NotificationsPage-Wf6csR7A.js
rename to static/assets/NotificationsPage-B-6BvYgs.js
index cc2269ecd..7735e131b 100644
--- a/static/assets/NotificationsPage-Wf6csR7A.js
+++ b/static/assets/NotificationsPage-B-6BvYgs.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{n as c}from"./ToastContext-VFOrCCoA.js";import{t as l}from"./loader-circle-CB4leTZa.js";import{i as u,n as d,t as f}from"./Card-OUAj0Ayh.js";import{t as p}from"./Button-pwVKPiYn.js";import{An as m,In as h,Ut as g,Vn as _,in as v,yt as y}from"./index-Bw-_P2Fg.js";var b=e(n(),1),x=t();function S(){let{t:e}=i(),{user:t}=y(),{showToast:n}=c(),S=a(),C=_(),[w,T]=(0,b.useState)(!0),[E,D]=(0,b.useState)(!0),[O,k]=(0,b.useState)(!0),[A,j]=(0,b.useState)(!0),[M,N]=(0,b.useState)(!1),{data:P,isLoading:F}=o({queryKey:[`advancedAuthStatus`],queryFn:r.getAdvancedAuthStatus,staleTime:300*1e3}),{data:I,isLoading:L}=o({queryKey:[`settings`],queryFn:r.getSettings,staleTime:300*1e3}),{data:R,isLoading:z}=o({queryKey:[`user-email-preferences`],queryFn:()=>r.getUserEmailPreferences()});(0,b.useEffect)(()=>{(P&&!P.advanced_auth_enabled||I&&!I.user_notifications_enabled)&&C(`/settings`,{replace:!0})},[P,I,C]),(0,b.useEffect)(()=>{R&&(T(R.notify_print_start),D(R.notify_print_complete),k(R.notify_print_failed),j(R.notify_print_stopped),N(!1))},[R]);let B=s({mutationFn:()=>r.updateUserEmailPreferences({notify_print_start:w,notify_print_complete:E,notify_print_failed:O,notify_print_stopped:A}),onSuccess:()=>{S.invalidateQueries({queryKey:[`user-email-preferences`]}),N(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),V=(e,t)=>{e(!t),N(!0)};return z||F||L?(0,x.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,x.jsx)(l,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,x.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,x.jsx)(h,{className:`w-7 h-7 text-bambu-green`}),(0,x.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,x.jsx)(f,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,x.jsx)(d,{className:`py-4`,children:(0,x.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-100 dark:bg-blue-500/20 flex-shrink-0`,children:(0,x.jsx)(v,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,x.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,x.jsx)(`strong`,{children:t.email})]}):(0,x.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,x.jsxs)(f,{className:`mb-6`,children:[(0,x.jsxs)(u,{children:[(0,x.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,x.jsxs)(d,{className:`space-y-4`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${w?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${w?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(T,w),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${w?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":w,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${w?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${E?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${E?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(D,E),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":E,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${E?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${O?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${O?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(k,O),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${O?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":O,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${O?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${A?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${A?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(j,A),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${A?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":A,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${A?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,x.jsx)(`div`,{className:`flex justify-end`,children:(0,x.jsx)(p,{onClick:()=>B.mutate(),disabled:!M||B.isPending||!t?.email,children:B.isPending?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(l,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(g,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}export{S as NotificationsPage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{n as c}from"./ToastContext-VFOrCCoA.js";import{t as l}from"./loader-circle-CB4leTZa.js";import{i as u,n as d,t as f}from"./Card-OUAj0Ayh.js";import{t as p}from"./Button-pwVKPiYn.js";import{An as m,In as h,Ut as g,Vn as _,in as v,yt as y}from"./index-ggB_TpPo.js";var b=e(n(),1),x=t();function S(){let{t:e}=i(),{user:t}=y(),{showToast:n}=c(),S=a(),C=_(),[w,T]=(0,b.useState)(!0),[E,D]=(0,b.useState)(!0),[O,k]=(0,b.useState)(!0),[A,j]=(0,b.useState)(!0),[M,N]=(0,b.useState)(!1),{data:P,isLoading:F}=o({queryKey:[`advancedAuthStatus`],queryFn:r.getAdvancedAuthStatus,staleTime:300*1e3}),{data:I,isLoading:L}=o({queryKey:[`settings`],queryFn:r.getSettings,staleTime:300*1e3}),{data:R,isLoading:z}=o({queryKey:[`user-email-preferences`],queryFn:()=>r.getUserEmailPreferences()});(0,b.useEffect)(()=>{(P&&!P.advanced_auth_enabled||I&&!I.user_notifications_enabled)&&C(`/settings`,{replace:!0})},[P,I,C]),(0,b.useEffect)(()=>{R&&(T(R.notify_print_start),D(R.notify_print_complete),k(R.notify_print_failed),j(R.notify_print_stopped),N(!1))},[R]);let B=s({mutationFn:()=>r.updateUserEmailPreferences({notify_print_start:w,notify_print_complete:E,notify_print_failed:O,notify_print_stopped:A}),onSuccess:()=>{S.invalidateQueries({queryKey:[`user-email-preferences`]}),N(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),V=(e,t)=>{e(!t),N(!0)};return z||F||L?(0,x.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,x.jsx)(l,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,x.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,x.jsx)(h,{className:`w-7 h-7 text-bambu-green`}),(0,x.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,x.jsx)(f,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,x.jsx)(d,{className:`py-4`,children:(0,x.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-100 dark:bg-blue-500/20 flex-shrink-0`,children:(0,x.jsx)(v,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,x.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,x.jsx)(`strong`,{children:t.email})]}):(0,x.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,x.jsxs)(f,{className:`mb-6`,children:[(0,x.jsxs)(u,{children:[(0,x.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,x.jsxs)(d,{className:`space-y-4`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${w?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${w?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(T,w),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${w?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":w,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${w?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${E?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${E?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(D,E),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":E,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${E?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${O?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${O?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(k,O),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${O?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":O,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${O?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${A?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${A?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(j,A),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${A?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":A,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${A?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,x.jsx)(`div`,{className:`flex justify-end`,children:(0,x.jsx)(p,{onClick:()=>B.mutate(),disabled:!M||B.isPending||!t?.email,children:B.isPending?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(l,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(g,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}export{S as NotificationsPage};
\ No newline at end of file
diff --git a/static/assets/PdfPreviewModal-HVSkaROI.js b/static/assets/PdfPreviewModal-DSim_AJc.js
similarity index 97%
rename from static/assets/PdfPreviewModal-HVSkaROI.js
rename to static/assets/PdfPreviewModal-DSim_AJc.js
index 72053bcbd..dc51d05b3 100644
--- a/static/assets/PdfPreviewModal-HVSkaROI.js
+++ b/static/assets/PdfPreviewModal-DSim_AJc.js
@@ -1,2 +1,2 @@
-const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-h6Jgng8Y.js","assets/index-Bw-_P2Fg.js","assets/chunk-aKtaBQYM.js","assets/QueryClientProvider-Clbyr4Jg.js","assets/client-BdOyoZJz.js","assets/useMutation-qh3Iyscy.js","assets/useQueries-C87lFrjE.js","assets/useQuery-CCy0EwsM.js","assets/createLucideIcon-Yo2YoYjm.js","assets/arrow-down-C4OBNDqJ.js","assets/arrow-up-Dam8cLfE.js","assets/calendar-DiVEdzUw.js","assets/check-D1Pn8T1J.js","assets/info-DcT0QU8O.js","assets/ToastContext-VFOrCCoA.js","assets/loader-circle-CB4leTZa.js","assets/x-Dctff5l9.js","assets/file-DDkFXH-b.js","assets/triangle-alert-gIik0G2C.js","assets/react-dom-xhkz5--P.js","assets/Button-pwVKPiYn.js","assets/Card-OUAj0Ayh.js","assets/filamentSwatchHelpers-D3oXQSGk.js","assets/date-G9KUauqz.js","assets/index-jO4mF6Tu.css"])))=>i.map(i=>d[i]);
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-BdOyoZJz.js";import{t as o}from"./loader-circle-CB4leTZa.js";import{n as s,t as c}from"./zoom-out-C85W_TC5.js";import{t as l}from"./file-DDkFXH-b.js";import{Kn as u,Mn as d,jn as ee,xn as te}from"./index-Bw-_P2Fg.js";import{n as ne,r as f,t as p}from"./usePreviewFullscreen-DOsgAeT7.js";var m=e(n(),1),h=t(),g=.4,_=4,v=1.25,y=30,b=Math.log(v)/y,re=150,x=16*1024*1024,S=`/assets/pdfjs/`,C=e=>Math.min(_,Math.max(g,e));function w(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);n.fillStyle=`#ffffff`,n.fillRect(0,0,256,256);let r=256/Math.max(e.width,e.height),i=e.width*r,a=e.height*r;return n.drawImage(e,(256-i)/2,(256-a)/2,i,a),new Promise(e=>t.toBlob(e,`image/png`))}function ie(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:t,fileSize:n,onClose:g,onSnapshot:_}){let{t:T}=a(),E=p(),{panelRef:D,isFullscreen:ae,toggleFullscreen:oe}=E,O=(0,m.useRef)(null),k=(0,m.useRef)(null),A=(0,m.useRef)(null),j=(0,m.useRef)(!1),M=(0,m.useRef)(_);(0,m.useEffect)(()=>{M.current=_});let[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(1),[L,R]=(0,m.useState)(1),[z,B]=(0,m.useState)(1),[V,se]=(0,m.useState)(0),[H,U]=(0,m.useState)(null),[ce,W]=(0,m.useState)(!0),G=(0,m.useRef)(L),K=(0,m.useRef)(null),q=(0,m.useRef)(null),J=(0,m.useRef)(new Map),Y=(0,m.useRef)(null),X=(0,m.useCallback)((e,t,n)=>{let r=O.current,i=k.current;if(r&&i){let e=r.getBoundingClientRect(),a=i.getBoundingClientRect(),o=t==null?e.width/2:t-e.left,s=n==null?e.height/2:n-e.top;q.current=a.width>0&&a.height>0?{fx:(o+e.left-a.left)/a.width,fy:(s+e.top-a.top)/a.height,px:o,py:s}:null}R(t=>C(t*e))},[]);(0,m.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),X(v)):e.key===`-`?(e.preventDefault(),X(1/v)):e.key===`0`&&(e.preventDefault(),q.current=null,R(1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[X]),(0,m.useEffect)(()=>{let e=O.current;if(!e)return;let t=t=>{if(!k.current||!K.current||!(t.ctrlKey||t.metaKey)&&!(e.scrollHeight<=e.clientHeight&&e.scrollWidth<=e.clientWidth))return;t.preventDefault();let n=Math.max(-30,Math.min(y,ie(t)));X(Math.exp(-n*b),t.clientX,t.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[X]);let le=e=>{e.pointerType===`touch`&&(J.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),Y.current=null)},ue=e=>{if(e.pointerType!==`touch`)return;let t=J.current,n=t.get(e.pointerId);if(!n)return;if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){let t=O.current;t&&(t.scrollLeft-=e.clientX-n.x,t.scrollTop-=e.clientY-n.y);return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=Y.current;Y.current=a,o!=null&&o>0&&a>0&&X(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},Z=e=>{e.pointerType===`touch`&&(J.current.delete(e.pointerId),Y.current=null)};(0,m.useLayoutEffect)(()=>{G.current=L;let e=k.current,t=O.current,n=K.current;if(!e||!t||!n)return;e.style.width=`${n.width*L}px`,e.style.height=`${n.height*L}px`;let r=q.current;q.current=null,r&&(t.scrollLeft=e.offsetLeft+r.fx*e.offsetWidth-r.px,t.scrollTop=e.offsetTop+r.fy*e.offsetHeight-r.py)},[L]),(0,m.useEffect)(()=>{if(L===z)return;let e=window.setTimeout(()=>B(L),re);return()=>window.clearTimeout(e)},[L,z]),(0,m.useEffect)(()=>{let e=D.current;if(!e)return;let t=new ResizeObserver(()=>se(e=>e+1));return t.observe(e),()=>t.disconnect()},[D]),(0,m.useEffect)(()=>{let t=!1,a=null;if(P(null),U(null),I(1),W(!0),n>52428800){U(T(`fileManager.preview.tooLarge`,{size:l(n)})),W(!1);return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let n=await fetch(r.getLibraryFileDownloadUrl(e),{headers:o});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.arrayBuffer(),s=await u(()=>import(`./pdf-h6Jgng8Y.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]));if(s.GlobalWorkerOptions.workerSrc||(s.GlobalWorkerOptions.workerSrc=(await u(async()=>{let{default:e}=await import(`./pdf.worker.min-DpOxPwGP.js`);return{default:e}},[])).default),a=s.getDocument({data:new Uint8Array(i),cMapUrl:`${S}cmaps/`,iccUrl:`${S}iccs/`,standardFontDataUrl:`${S}standard_fonts/`,wasmUrl:`${S}wasm/`}),t){a.destroy();return}let c=await a.promise;t||P(c)})().catch(e=>{console.error(`[pdf-preview] load failed`,e),t||(U(T(`fileManager.preview.error`)),W(!1))}),()=>{t=!0,A.current?.cancel(),A.current=null,a?.destroy()}},[e,n,T]),(0,m.useEffect)(()=>{if(!N)return;let e=!1;return W(!0),(async()=>{let t=await N.getPage(F),n=k.current,r=O.current;if(!n||!r||e)return;let i=t.getViewport({scale:1}),a=Math.max((r.clientWidth-32)/i.width,.1),o=Math.min(window.devicePixelRatio||1,2),s=a*z*o,c=i.width*s*(i.height*s),l=c>x?s*Math.sqrt(x/c):s,u=t.getViewport({scale:l});n.width=u.width,n.height=u.height,K.current={width:i.width*a,height:i.height*a},n.style.width=`${K.current.width*G.current}px`,n.style.height=`${K.current.height*G.current}px`,A.current?.cancel();let d=t.render({canvas:n,viewport:u});if(A.current=d,await d.promise,!e&&(W(!1),F===1&&M.current&&!j.current)){j.current=!0;let t=await w(n);t&&!e&&M.current?.(t)}})().catch(t=>{!e&&t?.name!==`RenderingCancelledException`&&(console.error(`[pdf-preview] render failed`,t),U(T(`fileManager.preview.error`)),W(!1))}),()=>{e=!0}},[N,F,z,V,T]);let Q=N?.numPages??0,$=f;return(0,h.jsx)(ne,{title:t,fullscreen:E,onClose:g,icon:(0,h.jsx)(te,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:(0,h.jsxs)(h.Fragment,{children:[N&&Q>1&&(0,h.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,h.jsx)(`button`,{onClick:()=>I(e=>Math.max(1,e-1)),disabled:F<=1,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":T(`fileManager.preview.prevPage`),children:(0,h.jsx)(ee,{className:`w-4 h-4`})}),(0,h.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:T(`fileManager.preview.page`,{current:F,total:Q})}),(0,h.jsx)(`button`,{onClick:()=>I(e=>Math.min(Q,e+1)),disabled:F>=Q,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":T(`fileManager.preview.nextPage`),children:(0,h.jsx)(d,{className:`w-4 h-4`})})]}),N&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`button`,{onClick:()=>X(1/v),className:$,"aria-label":T(`fileManager.preview.zoomOut`),children:(0,h.jsx)(c,{className:`w-4 h-4`})}),(0,h.jsx)(`button`,{onClick:()=>X(v),className:$,"aria-label":T(`fileManager.preview.zoomIn`),children:(0,h.jsx)(s,{className:`w-4 h-4`})})]})]}),children:(0,h.jsxs)(`div`,{ref:O,"data-testid":`pdf-preview-page`,className:`relative flex-1 min-h-0 overflow-auto bg-bambu-dark p-4 touch-none ${ae?``:`rounded-b-lg`}`,onDoubleClick:oe,onPointerDown:le,onPointerMove:ue,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:[H?(0,h.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,h.jsx)(`p`,{className:`text-bambu-gray text-center`,children:H})}):(0,h.jsx)(`div`,{className:`flex justify-center min-w-fit`,children:(0,h.jsx)(`canvas`,{ref:k,className:`shadow-lg`})}),!H&&ce&&(0,h.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,h.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})}export{T as PdfPreviewModal};
\ No newline at end of file
+const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-Cvgl8N9R.js","assets/index-ggB_TpPo.js","assets/chunk-aKtaBQYM.js","assets/QueryClientProvider-Clbyr4Jg.js","assets/client-BdOyoZJz.js","assets/useMutation-qh3Iyscy.js","assets/useQueries-C87lFrjE.js","assets/useQuery-CCy0EwsM.js","assets/createLucideIcon-Yo2YoYjm.js","assets/arrow-down-C4OBNDqJ.js","assets/arrow-up-Dam8cLfE.js","assets/calendar-DiVEdzUw.js","assets/check-D1Pn8T1J.js","assets/info-DcT0QU8O.js","assets/ToastContext-VFOrCCoA.js","assets/loader-circle-CB4leTZa.js","assets/x-Dctff5l9.js","assets/file-DDkFXH-b.js","assets/triangle-alert-gIik0G2C.js","assets/react-dom-xhkz5--P.js","assets/Button-pwVKPiYn.js","assets/Card-OUAj0Ayh.js","assets/filamentSwatchHelpers-D3oXQSGk.js","assets/date-G9KUauqz.js","assets/index-jO4mF6Tu.css"])))=>i.map(i=>d[i]);
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-BdOyoZJz.js";import{t as o}from"./loader-circle-CB4leTZa.js";import{n as s,t as c}from"./zoom-out-C85W_TC5.js";import{t as l}from"./file-DDkFXH-b.js";import{Kn as u,Mn as d,jn as ee,xn as te}from"./index-ggB_TpPo.js";import{n as ne,r as f,t as p}from"./usePreviewFullscreen-DOsgAeT7.js";var m=e(n(),1),h=t(),g=.4,_=4,v=1.25,y=30,b=Math.log(v)/y,re=150,x=16*1024*1024,S=`/assets/pdfjs/`,C=e=>Math.min(_,Math.max(g,e));function w(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);n.fillStyle=`#ffffff`,n.fillRect(0,0,256,256);let r=256/Math.max(e.width,e.height),i=e.width*r,a=e.height*r;return n.drawImage(e,(256-i)/2,(256-a)/2,i,a),new Promise(e=>t.toBlob(e,`image/png`))}function ie(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:t,fileSize:n,onClose:g,onSnapshot:_}){let{t:T}=a(),E=p(),{panelRef:D,isFullscreen:ae,toggleFullscreen:oe}=E,O=(0,m.useRef)(null),k=(0,m.useRef)(null),A=(0,m.useRef)(null),j=(0,m.useRef)(!1),M=(0,m.useRef)(_);(0,m.useEffect)(()=>{M.current=_});let[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(1),[L,R]=(0,m.useState)(1),[z,B]=(0,m.useState)(1),[V,se]=(0,m.useState)(0),[H,U]=(0,m.useState)(null),[ce,W]=(0,m.useState)(!0),G=(0,m.useRef)(L),K=(0,m.useRef)(null),q=(0,m.useRef)(null),J=(0,m.useRef)(new Map),Y=(0,m.useRef)(null),X=(0,m.useCallback)((e,t,n)=>{let r=O.current,i=k.current;if(r&&i){let e=r.getBoundingClientRect(),a=i.getBoundingClientRect(),o=t==null?e.width/2:t-e.left,s=n==null?e.height/2:n-e.top;q.current=a.width>0&&a.height>0?{fx:(o+e.left-a.left)/a.width,fy:(s+e.top-a.top)/a.height,px:o,py:s}:null}R(t=>C(t*e))},[]);(0,m.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),X(v)):e.key===`-`?(e.preventDefault(),X(1/v)):e.key===`0`&&(e.preventDefault(),q.current=null,R(1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[X]),(0,m.useEffect)(()=>{let e=O.current;if(!e)return;let t=t=>{if(!k.current||!K.current||!(t.ctrlKey||t.metaKey)&&!(e.scrollHeight<=e.clientHeight&&e.scrollWidth<=e.clientWidth))return;t.preventDefault();let n=Math.max(-30,Math.min(y,ie(t)));X(Math.exp(-n*b),t.clientX,t.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[X]);let le=e=>{e.pointerType===`touch`&&(J.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),Y.current=null)},ue=e=>{if(e.pointerType!==`touch`)return;let t=J.current,n=t.get(e.pointerId);if(!n)return;if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){let t=O.current;t&&(t.scrollLeft-=e.clientX-n.x,t.scrollTop-=e.clientY-n.y);return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=Y.current;Y.current=a,o!=null&&o>0&&a>0&&X(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},Z=e=>{e.pointerType===`touch`&&(J.current.delete(e.pointerId),Y.current=null)};(0,m.useLayoutEffect)(()=>{G.current=L;let e=k.current,t=O.current,n=K.current;if(!e||!t||!n)return;e.style.width=`${n.width*L}px`,e.style.height=`${n.height*L}px`;let r=q.current;q.current=null,r&&(t.scrollLeft=e.offsetLeft+r.fx*e.offsetWidth-r.px,t.scrollTop=e.offsetTop+r.fy*e.offsetHeight-r.py)},[L]),(0,m.useEffect)(()=>{if(L===z)return;let e=window.setTimeout(()=>B(L),re);return()=>window.clearTimeout(e)},[L,z]),(0,m.useEffect)(()=>{let e=D.current;if(!e)return;let t=new ResizeObserver(()=>se(e=>e+1));return t.observe(e),()=>t.disconnect()},[D]),(0,m.useEffect)(()=>{let t=!1,a=null;if(P(null),U(null),I(1),W(!0),n>52428800){U(T(`fileManager.preview.tooLarge`,{size:l(n)})),W(!1);return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let n=await fetch(r.getLibraryFileDownloadUrl(e),{headers:o});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.arrayBuffer(),s=await u(()=>import(`./pdf-Cvgl8N9R.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]));if(s.GlobalWorkerOptions.workerSrc||(s.GlobalWorkerOptions.workerSrc=(await u(async()=>{let{default:e}=await import(`./pdf.worker.min-DpOxPwGP.js`);return{default:e}},[])).default),a=s.getDocument({data:new Uint8Array(i),cMapUrl:`${S}cmaps/`,iccUrl:`${S}iccs/`,standardFontDataUrl:`${S}standard_fonts/`,wasmUrl:`${S}wasm/`}),t){a.destroy();return}let c=await a.promise;t||P(c)})().catch(e=>{console.error(`[pdf-preview] load failed`,e),t||(U(T(`fileManager.preview.error`)),W(!1))}),()=>{t=!0,A.current?.cancel(),A.current=null,a?.destroy()}},[e,n,T]),(0,m.useEffect)(()=>{if(!N)return;let e=!1;return W(!0),(async()=>{let t=await N.getPage(F),n=k.current,r=O.current;if(!n||!r||e)return;let i=t.getViewport({scale:1}),a=Math.max((r.clientWidth-32)/i.width,.1),o=Math.min(window.devicePixelRatio||1,2),s=a*z*o,c=i.width*s*(i.height*s),l=c>x?s*Math.sqrt(x/c):s,u=t.getViewport({scale:l});n.width=u.width,n.height=u.height,K.current={width:i.width*a,height:i.height*a},n.style.width=`${K.current.width*G.current}px`,n.style.height=`${K.current.height*G.current}px`,A.current?.cancel();let d=t.render({canvas:n,viewport:u});if(A.current=d,await d.promise,!e&&(W(!1),F===1&&M.current&&!j.current)){j.current=!0;let t=await w(n);t&&!e&&M.current?.(t)}})().catch(t=>{!e&&t?.name!==`RenderingCancelledException`&&(console.error(`[pdf-preview] render failed`,t),U(T(`fileManager.preview.error`)),W(!1))}),()=>{e=!0}},[N,F,z,V,T]);let Q=N?.numPages??0,$=f;return(0,h.jsx)(ne,{title:t,fullscreen:E,onClose:g,icon:(0,h.jsx)(te,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:(0,h.jsxs)(h.Fragment,{children:[N&&Q>1&&(0,h.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,h.jsx)(`button`,{onClick:()=>I(e=>Math.max(1,e-1)),disabled:F<=1,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":T(`fileManager.preview.prevPage`),children:(0,h.jsx)(ee,{className:`w-4 h-4`})}),(0,h.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:T(`fileManager.preview.page`,{current:F,total:Q})}),(0,h.jsx)(`button`,{onClick:()=>I(e=>Math.min(Q,e+1)),disabled:F>=Q,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":T(`fileManager.preview.nextPage`),children:(0,h.jsx)(d,{className:`w-4 h-4`})})]}),N&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`button`,{onClick:()=>X(1/v),className:$,"aria-label":T(`fileManager.preview.zoomOut`),children:(0,h.jsx)(c,{className:`w-4 h-4`})}),(0,h.jsx)(`button`,{onClick:()=>X(v),className:$,"aria-label":T(`fileManager.preview.zoomIn`),children:(0,h.jsx)(s,{className:`w-4 h-4`})})]})]}),children:(0,h.jsxs)(`div`,{ref:O,"data-testid":`pdf-preview-page`,className:`relative flex-1 min-h-0 overflow-auto bg-bambu-dark p-4 touch-none ${ae?``:`rounded-b-lg`}`,onDoubleClick:oe,onPointerDown:le,onPointerMove:ue,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:[H?(0,h.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,h.jsx)(`p`,{className:`text-bambu-gray text-center`,children:H})}):(0,h.jsx)(`div`,{className:`flex justify-center min-w-fit`,children:(0,h.jsx)(`canvas`,{ref:k,className:`shadow-lg`})}),!H&&ce&&(0,h.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,h.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})}export{T as PdfPreviewModal};
\ No newline at end of file
diff --git a/static/assets/PhotoGalleryModal-N1J3Wu90.js b/static/assets/PhotoGalleryModal-DIrTkEw_.js
similarity index 99%
rename from static/assets/PhotoGalleryModal-N1J3Wu90.js
rename to static/assets/PhotoGalleryModal-DIrTkEw_.js
index d541465ba..df0e5c503 100644
--- a/static/assets/PhotoGalleryModal-N1J3Wu90.js
+++ b/static/assets/PhotoGalleryModal-DIrTkEw_.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{n as c}from"./ToastContext-VFOrCCoA.js";import{t as l}from"./cog-pa-nvQzt.js";import{t as u}from"./loader-circle-CB4leTZa.js";import{t as d}from"./play-DROvjtg7.js";import{t as f}from"./triangle-alert-gIik0G2C.js";import{t as p}from"./x-Dctff5l9.js";import{t as m}from"./Button-pwVKPiYn.js";import{At as h,Jt as g,Mn as _,_t as v,jn as y,t as b,wn as x}from"./index-Bw-_P2Fg.js";var S=e(n(),1),C=t();function w({source:e,onClose:t}){let{t:n}=i(),l=a(),{showToast:u}=c(),[f,m]=(0,S.useState)(null),[h,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(1),{trackJob:y}=b(),{data:x,isLoading:w}=o({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:D}=o({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),{data:O}=o({queryKey:[`app-settings`],queryFn:()=>r.getSettings()}),k=O?.pipeline_max_copies??50,A={kind:e.kind,id:e.id},j=s({mutationFn:e=>r.checkPipelineEligibility(e,A)}),M=s({mutationFn:({pipelineId:e,force:t})=>r.runPipeline(e,A,t,_),onSuccess:r=>{l.invalidateQueries({queryKey:[`slicer-pipelines`]}),l.invalidateQueries({queryKey:[`pipeline-runs`]}),r.slice_job_id&&y(r.slice_job_id,e.kind,e.filename),u(n(`library.runWithPipeline.toast.started`,`Pipeline run started`),`success`),t()},onError:e=>{u(e.message||n(`library.runWithPipeline.toast.failed`,`Could not start run`),`error`)}}),N=x?.pipelines??[],P=(D??[]).reduce((e,t)=>(e[t.id]=t,e),{});return(0,C.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:t,role:`dialog`,"aria-modal":`true`,"aria-label":n(`library.runWithPipeline.modalTitle`,`Run with pipeline`),children:(0,C.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md max-h-[80vh] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,C.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,C.jsx)(d,{className:`w-4 h-4 text-bambu-green`}),f&&h?n(`library.runWithPipeline.confirmTitle`,`Confirm run`):n(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,C.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,C.jsx)(p,{className:`w-4 h-4`})})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:f&&h?(0,C.jsx)(E,{pipeline:f,report:h,source:e,onBack:()=>{m(null),g(null)},onConfirm:()=>{f&&M.mutate({pipelineId:f.id,force:!0})},running:M.isPending}):(0,C.jsx)(T,{source:e,pipelines:N,printerById:P,loading:w||j.isPending,onPick:async e=>{if(!(e.target_printer_id||e.target_kind===`printer_class`&&e.target_model_class)){u(n(`library.runWithPipeline.noTargetMessage`,`This pipeline has no target printer set. Open it in Settings to pick one.`),`error`);return}m(e);try{let t=await j.mutateAsync(e.id);g(t),t.ok&&M.mutate({pipelineId:e.id,force:!1})}catch{m(null)}},copies:_,maxCopies:k,onCopiesChange:v})})]})})}function T({source:e,pipelines:t,printerById:n,loading:r,onPick:a,copies:o,maxCopies:s,onCopiesChange:c}){let{t:d}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[d(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,C.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[d(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,C.jsx)(`input`,{id:`run-pipeline-copies`,type:`number`,min:1,max:s,value:o,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||c(Math.max(1,Math.min(s,t)))},"aria-label":d(`library.runWithPipeline.copies`,`Copies`),className:`w-20 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,C.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:d(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:s})})]}),r&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,C.jsx)(u,{className:`w-4 h-4 animate-spin`}),d(`library.runWithPipeline.loading`,`Loading…`)]}),!r&&t.length===0&&(0,C.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d(`library.runWithPipeline.empty`,`No pipelines saved yet. Open the Slice dialog and click "Save as pipeline" to create one.`)}),!r&&t.length>0&&(0,C.jsx)(`ul`,{className:`space-y-1.5`,"aria-label":d(`library.runWithPipeline.pipelineListAria`,`Available pipelines`),children:t.map(e=>{let t=e.target_kind===`printer_class`,r=e.target_printer_id?n[e.target_printer_id]?.name:null,i=t&&e.target_model_class?d(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):null;return(0,C.jsx)(`li`,{children:(0,C.jsxs)(`button`,{type:`button`,onClick:()=>a(e),disabled:!(e.target_printer_id||t&&e.target_model_class),className:`w-full text-left px-3 py-2 rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(l,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,C.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,C.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,C.jsx)(g,{className:`w-3 h-3`}),i?(0,C.jsx)(`span`,{children:i}):r?(0,C.jsx)(`span`,{children:r}):(0,C.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:d(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function E({pipeline:e,report:t,source:n,onBack:r,onConfirm:a,running:o}){let{t:s}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,C.jsxs)(`p`,{children:[s(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,C.jsxs)(`p`,{className:`mt-1`,children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:n.filename})]}),(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:e.name})]}),t.target_printer_name&&(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:t.target_printer_name})]})]}),(0,C.jsx)(`ul`,{className:`space-y-1.5`,children:t.issues.map((e,t)=>(0,C.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,C.jsx)(f,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,C.jsx)(`span`,{className:`text-bambu-gray`,children:(0,C.jsx)(D,{issue:e})})]},t))}),(0,C.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:r,disabled:o,className:`px-3 py-1.5 text-xs text-bambu-gray hover:text-white`,children:s(`common.back`,`Back`)}),(0,C.jsxs)(`button`,{type:`button`,onClick:a,disabled:o,className:`px-3 py-1.5 text-xs bg-amber-500 hover:bg-amber-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[o?(0,C.jsx)(u,{className:`w-3 h-3 animate-spin`}):(0,C.jsx)(d,{className:`w-3 h-3`}),s(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function D({issue:e}){let{t}=i();switch(e.kind){case`printer_not_set`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentType`,`Filament slot {{slot}}: expected {{expected}}, AMS has {{actual}}`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`filament_color_mismatch`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentColor`,`Filament slot {{slot}}: colour differs (expected {{expected}}, AMS has {{actual}})`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`ams_slot_missing`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.amsSlotMissing`,`AMS slot {{slot}} not available on this printer`,{slot:(e.slot_index??0)+1})});case`filament_unverified`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentUnverified`,`Filament slot {{slot}} comes from a cloud / standard preset and could not be statically verified.`,{slot:(e.slot_index??0)+1})});default:return(0,C.jsx)(C.Fragment,{children:e.kind})}}function O({onFiles:e,onRejected:t,extensions:n,disabled:r=!1}){let[i,a]=(0,S.useState)(!1),o=(0,S.useRef)(e),s=(0,S.useRef)(t),c=(0,S.useRef)(n);(0,S.useEffect)(()=>{o.current=e},[e]),(0,S.useEffect)(()=>{s.current=t},[t]),(0,S.useEffect)(()=>{c.current=n},[n]);let l=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),u=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),d=(0,S.useCallback)(e=>{if(r)return;e.preventDefault();let t=e.currentTarget,n=e.relatedTarget;(!n||!t.contains(n))&&a(!1)},[r]),f=(0,S.useCallback)(e=>{if(r)return;e.preventDefault(),a(!1);let t=Array.from(e.dataTransfer.files);if(t.length===0)return;let n=c.current,i=n&&n.length>0?t.filter(e=>n.some(t=>e.name.toLowerCase().endsWith(t))):t;i.length>0?o.current(i):s.current?.()},[r]);return(0,S.useEffect)(()=>{if(!i)return;let e=()=>a(!1),t=t=>{t.key===`Escape`&&e()};return document.addEventListener(`drop`,e),document.addEventListener(`dragend`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`drop`,e),document.removeEventListener(`dragend`,e),document.removeEventListener(`keydown`,t)}},[i]),{isDraggingOver:i,dragHandlers:{onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f}}}function k(e){let{archiveName:t,photos:n,initialIndex:i,onClose:a,onDelete:o}=e,[s,c]=(0,S.useState)(()=>Math.min(Math.max(i??0,0),Math.max(n.length-1,0))),[l,u]=(0,S.useState)(!1);if((0,S.useEffect)(()=>{if(l)return;let e=e=>{e.key===`Escape`&&a(),e.key===`ArrowLeft`&&c(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&c(e=>Math.min(n.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a,n.length,l]),(0,S.useEffect)(()=>{s>=n.length&&c(Math.max(0,n.length-1))},[n.length,s]),n.length===0)return a(),null;let d=t=>e.getPhotoUrl?e.getPhotoUrl(t):r.getArchivePhotoUrl(e.archiveId,t),f=n[s],g=d(f);return(0,C.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:e=>{e.stopPropagation(),a()},children:[(0,C.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,C.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,s+1,` of `,n.length]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=g,e.download=`${t}_photo_${s+1}.jpg`,e.click()},children:[(0,C.jsx)(x,{className:`w-4 h-4`}),`Download`]}),o&&(0,C.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>{o&&u(!0)},className:`text-red-400 hover:text-red-300`,children:(0,C.jsx)(h,{className:`w-4 h-4`})}),(0,C.jsx)(`button`,{onClick:a,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,C.jsx)(p,{className:`w-6 h-6`})})]})]}),(0,C.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[s>0&&(0,C.jsx)(`button`,{onClick:()=>c(e=>e-1),className:`absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(y,{className:`w-8 h-8 text-white`})}),(0,C.jsx)(`img`,{src:g,alt:`Photo ${s+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),sc(e=>e+1),className:`absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(_,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,C.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((e,t)=>(0,C.jsx)(`button`,{onClick:()=>c(t),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${t===s?`border-bambu-green`:`border-transparent hover:border-bambu-gray`}`,children:(0,C.jsx)(`img`,{src:d(e),alt:`Thumbnail ${t+1}`,className:`w-full h-full object-cover`})},e))})]}),l&&(0,C.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,C.jsx)(v,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{o?.(f),u(!1)},onCancel:()=>u(!1)})})]})}export{O as n,w as r,k as t};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{n as c}from"./ToastContext-VFOrCCoA.js";import{t as l}from"./cog-pa-nvQzt.js";import{t as u}from"./loader-circle-CB4leTZa.js";import{t as d}from"./play-DROvjtg7.js";import{t as f}from"./triangle-alert-gIik0G2C.js";import{t as p}from"./x-Dctff5l9.js";import{t as m}from"./Button-pwVKPiYn.js";import{At as h,Jt as g,Mn as _,_t as v,jn as y,t as b,wn as x}from"./index-ggB_TpPo.js";var S=e(n(),1),C=t();function w({source:e,onClose:t}){let{t:n}=i(),l=a(),{showToast:u}=c(),[f,m]=(0,S.useState)(null),[h,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(1),{trackJob:y}=b(),{data:x,isLoading:w}=o({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:D}=o({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),{data:O}=o({queryKey:[`app-settings`],queryFn:()=>r.getSettings()}),k=O?.pipeline_max_copies??50,A={kind:e.kind,id:e.id},j=s({mutationFn:e=>r.checkPipelineEligibility(e,A)}),M=s({mutationFn:({pipelineId:e,force:t})=>r.runPipeline(e,A,t,_),onSuccess:r=>{l.invalidateQueries({queryKey:[`slicer-pipelines`]}),l.invalidateQueries({queryKey:[`pipeline-runs`]}),r.slice_job_id&&y(r.slice_job_id,e.kind,e.filename),u(n(`library.runWithPipeline.toast.started`,`Pipeline run started`),`success`),t()},onError:e=>{u(e.message||n(`library.runWithPipeline.toast.failed`,`Could not start run`),`error`)}}),N=x?.pipelines??[],P=(D??[]).reduce((e,t)=>(e[t.id]=t,e),{});return(0,C.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:t,role:`dialog`,"aria-modal":`true`,"aria-label":n(`library.runWithPipeline.modalTitle`,`Run with pipeline`),children:(0,C.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md max-h-[80vh] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,C.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,C.jsx)(d,{className:`w-4 h-4 text-bambu-green`}),f&&h?n(`library.runWithPipeline.confirmTitle`,`Confirm run`):n(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,C.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,C.jsx)(p,{className:`w-4 h-4`})})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:f&&h?(0,C.jsx)(E,{pipeline:f,report:h,source:e,onBack:()=>{m(null),g(null)},onConfirm:()=>{f&&M.mutate({pipelineId:f.id,force:!0})},running:M.isPending}):(0,C.jsx)(T,{source:e,pipelines:N,printerById:P,loading:w||j.isPending,onPick:async e=>{if(!(e.target_printer_id||e.target_kind===`printer_class`&&e.target_model_class)){u(n(`library.runWithPipeline.noTargetMessage`,`This pipeline has no target printer set. Open it in Settings to pick one.`),`error`);return}m(e);try{let t=await j.mutateAsync(e.id);g(t),t.ok&&M.mutate({pipelineId:e.id,force:!1})}catch{m(null)}},copies:_,maxCopies:k,onCopiesChange:v})})]})})}function T({source:e,pipelines:t,printerById:n,loading:r,onPick:a,copies:o,maxCopies:s,onCopiesChange:c}){let{t:d}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[d(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,C.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[d(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,C.jsx)(`input`,{id:`run-pipeline-copies`,type:`number`,min:1,max:s,value:o,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||c(Math.max(1,Math.min(s,t)))},"aria-label":d(`library.runWithPipeline.copies`,`Copies`),className:`w-20 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,C.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:d(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:s})})]}),r&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,C.jsx)(u,{className:`w-4 h-4 animate-spin`}),d(`library.runWithPipeline.loading`,`Loading…`)]}),!r&&t.length===0&&(0,C.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d(`library.runWithPipeline.empty`,`No pipelines saved yet. Open the Slice dialog and click "Save as pipeline" to create one.`)}),!r&&t.length>0&&(0,C.jsx)(`ul`,{className:`space-y-1.5`,"aria-label":d(`library.runWithPipeline.pipelineListAria`,`Available pipelines`),children:t.map(e=>{let t=e.target_kind===`printer_class`,r=e.target_printer_id?n[e.target_printer_id]?.name:null,i=t&&e.target_model_class?d(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):null;return(0,C.jsx)(`li`,{children:(0,C.jsxs)(`button`,{type:`button`,onClick:()=>a(e),disabled:!(e.target_printer_id||t&&e.target_model_class),className:`w-full text-left px-3 py-2 rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(l,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,C.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,C.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,C.jsx)(g,{className:`w-3 h-3`}),i?(0,C.jsx)(`span`,{children:i}):r?(0,C.jsx)(`span`,{children:r}):(0,C.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:d(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function E({pipeline:e,report:t,source:n,onBack:r,onConfirm:a,running:o}){let{t:s}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,C.jsxs)(`p`,{children:[s(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,C.jsxs)(`p`,{className:`mt-1`,children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:n.filename})]}),(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:e.name})]}),t.target_printer_name&&(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:t.target_printer_name})]})]}),(0,C.jsx)(`ul`,{className:`space-y-1.5`,children:t.issues.map((e,t)=>(0,C.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,C.jsx)(f,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,C.jsx)(`span`,{className:`text-bambu-gray`,children:(0,C.jsx)(D,{issue:e})})]},t))}),(0,C.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:r,disabled:o,className:`px-3 py-1.5 text-xs text-bambu-gray hover:text-white`,children:s(`common.back`,`Back`)}),(0,C.jsxs)(`button`,{type:`button`,onClick:a,disabled:o,className:`px-3 py-1.5 text-xs bg-amber-500 hover:bg-amber-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[o?(0,C.jsx)(u,{className:`w-3 h-3 animate-spin`}):(0,C.jsx)(d,{className:`w-3 h-3`}),s(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function D({issue:e}){let{t}=i();switch(e.kind){case`printer_not_set`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentType`,`Filament slot {{slot}}: expected {{expected}}, AMS has {{actual}}`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`filament_color_mismatch`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentColor`,`Filament slot {{slot}}: colour differs (expected {{expected}}, AMS has {{actual}})`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`ams_slot_missing`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.amsSlotMissing`,`AMS slot {{slot}} not available on this printer`,{slot:(e.slot_index??0)+1})});case`filament_unverified`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentUnverified`,`Filament slot {{slot}} comes from a cloud / standard preset and could not be statically verified.`,{slot:(e.slot_index??0)+1})});default:return(0,C.jsx)(C.Fragment,{children:e.kind})}}function O({onFiles:e,onRejected:t,extensions:n,disabled:r=!1}){let[i,a]=(0,S.useState)(!1),o=(0,S.useRef)(e),s=(0,S.useRef)(t),c=(0,S.useRef)(n);(0,S.useEffect)(()=>{o.current=e},[e]),(0,S.useEffect)(()=>{s.current=t},[t]),(0,S.useEffect)(()=>{c.current=n},[n]);let l=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),u=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),d=(0,S.useCallback)(e=>{if(r)return;e.preventDefault();let t=e.currentTarget,n=e.relatedTarget;(!n||!t.contains(n))&&a(!1)},[r]),f=(0,S.useCallback)(e=>{if(r)return;e.preventDefault(),a(!1);let t=Array.from(e.dataTransfer.files);if(t.length===0)return;let n=c.current,i=n&&n.length>0?t.filter(e=>n.some(t=>e.name.toLowerCase().endsWith(t))):t;i.length>0?o.current(i):s.current?.()},[r]);return(0,S.useEffect)(()=>{if(!i)return;let e=()=>a(!1),t=t=>{t.key===`Escape`&&e()};return document.addEventListener(`drop`,e),document.addEventListener(`dragend`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`drop`,e),document.removeEventListener(`dragend`,e),document.removeEventListener(`keydown`,t)}},[i]),{isDraggingOver:i,dragHandlers:{onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f}}}function k(e){let{archiveName:t,photos:n,initialIndex:i,onClose:a,onDelete:o}=e,[s,c]=(0,S.useState)(()=>Math.min(Math.max(i??0,0),Math.max(n.length-1,0))),[l,u]=(0,S.useState)(!1);if((0,S.useEffect)(()=>{if(l)return;let e=e=>{e.key===`Escape`&&a(),e.key===`ArrowLeft`&&c(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&c(e=>Math.min(n.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a,n.length,l]),(0,S.useEffect)(()=>{s>=n.length&&c(Math.max(0,n.length-1))},[n.length,s]),n.length===0)return a(),null;let d=t=>e.getPhotoUrl?e.getPhotoUrl(t):r.getArchivePhotoUrl(e.archiveId,t),f=n[s],g=d(f);return(0,C.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:e=>{e.stopPropagation(),a()},children:[(0,C.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,C.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,s+1,` of `,n.length]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=g,e.download=`${t}_photo_${s+1}.jpg`,e.click()},children:[(0,C.jsx)(x,{className:`w-4 h-4`}),`Download`]}),o&&(0,C.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>{o&&u(!0)},className:`text-red-400 hover:text-red-300`,children:(0,C.jsx)(h,{className:`w-4 h-4`})}),(0,C.jsx)(`button`,{onClick:a,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,C.jsx)(p,{className:`w-6 h-6`})})]})]}),(0,C.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[s>0&&(0,C.jsx)(`button`,{onClick:()=>c(e=>e-1),className:`absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(y,{className:`w-8 h-8 text-white`})}),(0,C.jsx)(`img`,{src:g,alt:`Photo ${s+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),sc(e=>e+1),className:`absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(_,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,C.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((e,t)=>(0,C.jsx)(`button`,{onClick:()=>c(t),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${t===s?`border-bambu-green`:`border-transparent hover:border-bambu-gray`}`,children:(0,C.jsx)(`img`,{src:d(e),alt:`Thumbnail ${t+1}`,className:`w-full h-full object-cover`})},e))})]}),l&&(0,C.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,C.jsx)(v,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{o?.(f),u(!1)},onCancel:()=>u(!1)})})]})}export{O as n,w as r,k as t};
\ No newline at end of file
diff --git a/static/assets/PrinterLocationsPage-BIW5YJnm.js b/static/assets/PrinterLocationsPage-wzI9VkgW.js
similarity index 99%
rename from static/assets/PrinterLocationsPage-BIW5YJnm.js
rename to static/assets/PrinterLocationsPage-wzI9VkgW.js
index fb64c9e12..baeec6d04 100644
--- a/static/assets/PrinterLocationsPage-BIW5YJnm.js
+++ b/static/assets/PrinterLocationsPage-wzI9VkgW.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as c}from"./useQueries-C87lFrjE.js";import{t as l}from"./createLucideIcon-Yo2YoYjm.js";import{t as u}from"./arrow-left-MSgMxOFV.js";import{t as d}from"./box-BIRPxdgi.js";import{a as f}from"./info-DcT0QU8O.js";import{n as p}from"./ToastContext-VFOrCCoA.js";import{t as m}from"./loader-circle-CB4leTZa.js";import{t as ee}from"./move-CEngqF8v.js";import{t as te}from"./search-BpAJdxRw.js";import{t as h}from"./x-Dctff5l9.js";import{n as g,t as _}from"./Card-OUAj0Ayh.js";import{t as v}from"./Button-pwVKPiYn.js";import{$t as ne,At as re,Lt as y,Rn as ie,Rt as b,Zt as ae,_t as oe,ht as x,mt as se,yt as ce}from"./index-Bw-_P2Fg.js";var S=l(`user-minus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),C=e(n(),1),w=t(),le=100,T=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#14b8a6`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`],ue=[`name-asc`,`name-desc`,`count-asc`,`count-desc`],de=`printerLocations.hideEmpty`,fe=`printerLocations.sort`;function pe(e,t,n){try{let r=localStorage.getItem(e);return t.includes(r)?r:n}catch{return n}}function me(e,t){try{localStorage.setItem(e,t)}catch{}}var he=e=>e.location?.trim()||``;function ge({location:e}){return(0,w.jsxs)(`div`,{className:`p-2 rounded-lg bg-bambu-dark relative overflow-hidden flex-shrink-0`,children:[(0,w.jsx)(se.find(t=>t.name===e.icon)?.icon??d,{className:`w-[25px] h-[25px] text-bambu-gray`}),e.color&&(0,w.jsx)(`div`,{className:`absolute top-0 left-0 w-1 h-full`,style:{backgroundColor:e.color}})]})}function _e({printer:e,status:t,selected:n,canEdit:r,busy:a,onToggle:o,onMove:s,onRemove:c}){let{t:l}=i(),u=t?.state,d=t?.connected,f=l(d?u===`RUNNING`?`printers.status.printing`:u===`PAUSE`?`printers.status.paused`:u===`FINISH`?`printers.status.finished`:`printers.status.idle`:`printers.status.offline`),p=d?u===`RUNNING`?`bg-orange-500/20 text-orange-400`:u===`PAUSE`?`bg-yellow-500/20 text-yellow-400`:u===`FINISH`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`:`bg-gray-500/20 text-gray-400`;return(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-2 px-3 rounded-lg transition-colors ${n?`bg-bambu-green/10 border border-bambu-green/30`:`bg-bambu-dark-secondary hover:bg-bambu-dark`}`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[r&&(0,w.jsx)(`button`,{type:`button`,onClick:o,className:`text-bambu-gray hover:text-bambu-green transition-colors`,title:l(`printers.locations.selectPrinter`),"aria-label":l(`printers.locations.selectPrinter`),"aria-pressed":n,children:n?(0,w.jsx)(b,{className:`w-4 h-4 text-bambu-green`}):(0,w.jsx)(y,{className:`w-4 h-4`})}),(0,w.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${d?u===`RUNNING`||u===`PAUSE`?`bg-orange-500`:`bg-bambu-green`:`bg-gray-500`}`}),(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-white text-sm font-medium truncate`,children:e.name}),(0,w.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.model||l(`printers.status.unknown`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,w.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${p}`,children:f}),r&&(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:s,disabled:a,className:`text-bambu-gray hover:text-bambu-green hover:bg-bambu-green/10`,title:l(`printers.locations.move`),"aria-label":l(`printers.locations.move`),children:(0,w.jsx)(ee,{className:`w-3.5 h-3.5`})}),r&&c&&(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:c,disabled:a,className:`text-bambu-gray hover:text-red-400 hover:bg-red-500/10`,title:l(`printers.locations.removeFromLocation`),"aria-label":l(`printers.locations.removeFromLocation`),children:(0,w.jsx)(S,{className:`w-3.5 h-3.5`})})]})]})}function ve({initial:e,saving:t,onSave:n,onCancel:r}){let{t:a}=i(),[o,s]=(0,C.useState)(e?.name??``),[c,l]=(0,C.useState)(e?.icon??``),[u,d]=(0,C.useState)(e?.color??``),f=o.trim().length>0&&!t,p=()=>f&&n({name:o.trim(),icon:c,color:u});return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,w.jsx)(_,{className:`w-full max-w-md`,children:(0,w.jsxs)(g,{className:`space-y-4`,children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`printers.locations.editTitle`:`printers.locations.createTitle`)}),(0,w.jsx)(`input`,{type:`text`,value:o,maxLength:le,onChange:e=>s(e.target.value),placeholder:a(`printers.locations.namePlaceholder`),"aria-label":a(`printers.locations.namePlaceholder`),className:`w-full px-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&p(),e.key===`Escape`&&r()}}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:a(`printers.locations.icon`)}),(0,w.jsx)(x,{value:c,onChange:l})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:a(`printers.locations.color`)}),(0,w.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[T.map(e=>(0,w.jsx)(`button`,{type:`button`,onClick:()=>d(u===e?``:e),className:`w-8 h-8 rounded-lg transition-all ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:`hover:scale-105`}`,style:{backgroundColor:e},title:e,"aria-label":e,"aria-pressed":u===e},e)),u&&(0,w.jsx)(`button`,{type:`button`,onClick:()=>d(``),className:`w-8 h-8 rounded-lg border-2 border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:border-bambu-gray transition-all flex items-center justify-center`,title:a(`printers.locations.noColor`),"aria-label":a(`printers.locations.noColor`),children:(0,w.jsx)(h,{className:`w-3.5 h-3.5`})})]})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,w.jsx)(v,{variant:`secondary`,onClick:r,disabled:t,children:a(`common.cancel`)}),(0,w.jsx)(v,{onClick:p,disabled:!f,children:t?(0,w.jsx)(m,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`printers.locations.create`)})]})]})})})}var E=`__none__`;function ye({count:e,printerName:t,locations:n,saving:r,onMove:a,onCancel:o}){let{t:s}=i(),[c,l]=(0,C.useState)(``);return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,w.jsx)(_,{className:`w-full max-w-md`,children:(0,w.jsxs)(g,{className:`space-y-4`,children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===1?s(`printers.locations.moveTitle`):s(`printers.locations.moveTitleMany`,{count:e})}),t&&(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,w.jsxs)(`select`,{value:c,onChange:e=>l(e.target.value),"aria-label":s(`printers.locations.targetPlaceholder`),className:`w-full px-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,disabled:r,autoFocus:!0,children:[(0,w.jsx)(`option`,{value:``,disabled:!0,children:s(`printers.locations.targetPlaceholder`)}),n.map(e=>(0,w.jsx)(`option`,{value:e.name,children:e.name},e.name)),(0,w.jsx)(`option`,{value:E,children:s(`printers.locations.noLocation`)})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,w.jsx)(v,{variant:`secondary`,onClick:o,disabled:r,children:s(`common.cancel`)}),(0,w.jsx)(v,{onClick:()=>a(c===E?null:c),disabled:r||!c,children:r?(0,w.jsx)(m,{className:`w-4 h-4 animate-spin`}):s(`printers.locations.moveButton`)})]})]})})})}function D(){let e=a(),{t}=i(),{showToast:n}=p(),{hasPermission:l}=ce(),h=l(`printers:update`),[x,se]=(0,C.useState)(``),[S,le]=(0,C.useState)(()=>pe(de,[`true`,`false`],`false`)===`true`),[T,E]=(0,C.useState)(()=>pe(fe,ue,`name-asc`)),[D,O]=(0,C.useState)(!1),[k,A]=(0,C.useState)(null),[j,M]=(0,C.useState)(!1),[N,P]=(0,C.useState)(new Set),[F,I]=(0,C.useState)(new Set),[L,R]=(0,C.useState)(null),[z,B]=(0,C.useState)(null),[V,H]=(0,C.useState)(null);(0,C.useEffect)(()=>me(de,String(S)),[S]),(0,C.useEffect)(()=>me(fe,T),[T]),(0,C.useEffect)(()=>{j&&A(null)},[j]);let{data:U,isLoading:be}=o({queryKey:[`printers`],queryFn:r.getPrinters}),{data:W,isLoading:xe}=o({queryKey:[`printer-locations`],queryFn:r.getPrinterLocations}),Se=c({queries:(U??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>r.getPrinterStatus(e.id),refetchInterval:3e4}))}),Ce=new Map((U??[]).map((e,t)=>[e.id,Se[t]?.data])),G=(0,C.useMemo)(()=>{let e=new Map;for(let t of U??[]){let n=he(t);e.set(n,[...e.get(n)??[],t])}return e},[U]),K=G.get(``)??[],we=(U?.length??0)-K.length,Te=(0,C.useMemo)(()=>{let e=x.trim().toLowerCase(),t=(W??[]).filter(t=>(!e||t.name.toLowerCase().includes(e))&&(!S||t.printer_count>0)),n=(e,t)=>e.name.localeCompare(t.name,void 0,{numeric:!0,sensitivity:`base`});return[...t].sort((e,t)=>{switch(T){case`name-desc`:return n(t,e);case`count-asc`:return e.printer_count-t.printer_count||n(e,t);case`count-desc`:return t.printer_count-e.printer_count||n(e,t);default:return n(e,t)}})},[W,x,S,T]),q=()=>{e.invalidateQueries({queryKey:[`printer-locations`]}),e.invalidateQueries({queryKey:[`printers`]})},J=e=>n(t(`printers.locations.failed`,{error:e instanceof Error?e.message:String(e)}),`error`),Y=s({mutationFn:({value:e,location:t})=>t?r.updatePrinterLocation({name:t.name,...e.name===t.name?{}:{new_name:e.name},icon:e.icon||null,color:e.color||null}):r.createPrinterLocation({name:e.name,icon:e.icon||null,color:e.color||null}),onSuccess:(e,{location:r})=>{q(),r&&k===r.name&&A(e.name),n(t(r?`printers.locations.saved`:`printers.locations.created`)),R(null)},onError:J}),X=s({mutationFn:({ids:e,location:t})=>r.assignPrinterLocation(e,t),onSuccess:({moved:e})=>{q(),n(t(`printers.locations.moved`,{count:e})),I(new Set),B(null)},onError:J}),Z=s({mutationFn:e=>r.deletePrinterLocations(e),onSuccess:({deleted:e})=>{q(),n(t(`printers.locations.deleted`,{count:e})),P(new Set),M(!1),H(null)},onError:e=>{J(e),H(null)}}),Q=X.isPending||Z.isPending||Y.isPending,Ee=(e,t)=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n};if(be||xe)return(0,w.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,w.jsx)(m,{className:`w-8 h-8 text-bambu-green animate-spin`})});let De=(V??[]).reduce((e,t)=>e+(W?.find(e=>e.name===t)?.printer_count??0),0),Oe=e=>({"name-asc":t(`printers.locations.sortNameAsc`),"name-desc":t(`printers.locations.sortNameDesc`),"count-asc":t(`printers.locations.sortCountAsc`),"count-desc":t(`printers.locations.sortCountDesc`)})[e],ke=(e,t)=>(0,w.jsx)(_e,{printer:e,status:Ce.get(e.id),selected:F.has(e.id),canEdit:h&&!j,busy:Q,onToggle:()=>I(Ee(F,e.id)),onMove:()=>B({ids:[e.id],printerName:e.name}),onRemove:t?()=>X.mutate({ids:[e.id],location:null}):void 0},e.id),$=K.length>0&&K.every(e=>F.has(e.id));return(0,w.jsxs)(`div`,{className:`p-4 md:p-8 pb-28`,children:[(0,w.jsxs)(ie,{to:`/`,className:`inline-flex items-center gap-1 mb-3 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,w.jsx)(u,{className:`w-4 h-4`}),` `,t(`printers.locations.backToPrinters`)]}),(0,w.jsxs)(`div`,{className:`mb-4`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 mb-1`,children:[(0,w.jsx)(d,{className:`w-[25px] h-[25px] text-bambu-green`}),(0,w.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:t(`printers.locations.title`)})]}),(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`printers.locations.subtitle`,{grouped:we,ungrouped:K.length})})]}),(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-3 mb-6`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,w.jsx)(te,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,w.jsx)(`input`,{type:`text`,value:x,onChange:e=>se(e.target.value),placeholder:t(`printers.locations.search`),"aria-label":t(`printers.locations.search`),className:`w-full pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`})]}),(0,w.jsx)(v,{onClick:()=>le(!S),variant:S?`primary`:`secondary`,children:t(S?`printers.locations.showEmpty`:`printers.locations.hideEmpty`)}),h&&(0,w.jsxs)(v,{onClick:()=>{P(new Set),M(!j)},variant:j?`primary`:`secondary`,children:[(0,w.jsx)(b,{className:`w-4 h-4 mr-1`}),t(j?`printers.locations.done`:`printers.locations.select`)]}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsxs)(v,{onClick:()=>O(!D),variant:`secondary`,"aria-haspopup":`menu`,children:[(0,w.jsx)(f,{className:`w-4 h-4 mr-1 transition-transform ${D?`rotate-180`:``}`}),Oe(T)]}),D&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>O(!1)}),(0,w.jsx)(`div`,{role:`menu`,className:`absolute right-0 top-full mt-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg p-1 min-w-[10rem]`,children:ue.map(e=>(0,w.jsx)(`button`,{role:`menuitem`,onClick:()=>{E(e),O(!1)},className:`w-full text-left px-3 py-2 text-sm rounded transition-colors ${T===e?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white`}`,children:Oe(e)},e))})]})]}),h&&(0,w.jsxs)(v,{onClick:()=>R({mode:`create`}),children:[(0,w.jsx)(ae,{className:`w-4 h-4 mr-1`}),t(`printers.locations.create`)]})]}),Te.length===0&&K.length===0?(0,w.jsx)(_,{children:(0,w.jsx)(g,{className:`text-center py-12 text-bambu-gray`,children:t(x?`printers.locations.noResults`:`printers.locations.none`)})}):(0,w.jsxs)(`div`,{className:`space-y-3`,children:[Te.map(e=>{let n=k===e.name,r=N.has(e.name);return(0,w.jsx)(_,{children:(0,w.jsxs)(g,{className:`p-4`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,w.jsxs)(`button`,{type:`button`,onClick:()=>j?P(Ee(N,e.name)):A(n?null:e.name),className:`flex items-center gap-3 flex-1 min-w-0 text-left`,"aria-expanded":j?void 0:n,"aria-pressed":j?r:void 0,children:[j?r?(0,w.jsx)(b,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}):(0,w.jsx)(y,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,w.jsx)(f,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 transition-transform ${n?`rotate-180`:``}`}),(0,w.jsx)(ge,{location:e}),(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`printers.locations.printerCount`,{count:e.printer_count})})]})]}),h&&!j&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>R({mode:`edit`,location:e}),disabled:Q,className:`text-bambu-gray hover:text-blue-400 hover:bg-blue-500/10`,title:t(`common.edit`),"aria-label":t(`common.edit`),children:(0,w.jsx)(ne,{className:`w-4 h-4`})}),(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>H([e.name]),disabled:Q,className:`text-red-500 hover:text-red-400 hover:bg-red-500/10`,title:t(`common.delete`),"aria-label":t(`common.delete`),children:(0,w.jsx)(re,{className:`w-4 h-4`})})]})]}),n&&(0,w.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-2`,children:(G.get(e.name)??[]).length===0?(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:t(`printers.locations.noPrinters`)}):(G.get(e.name)??[]).map(e=>ke(e,!0))})]})},e.name)}),K.length>0&&(0,w.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t(`printers.locations.ungroupedPrinters`,{count:K.length})}),h&&!j&&(0,w.jsx)(`button`,{type:`button`,onClick:()=>{let e=new Set(F);K.forEach(t=>$?e.delete(t.id):e.add(t.id)),I(e)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors`,children:t($?`common.deselectAll`:`common.selectAll`)})]}),(0,w.jsx)(`div`,{className:`space-y-2`,children:K.map(e=>ke(e,!1))})]})]}),h&&!j&&F.size>0&&(0,w.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 bg-bambu-dark border border-bambu-dark-tertiary rounded-xl shadow-2xl px-6 py-4 flex items-center gap-4 z-40`,children:[(0,w.jsx)(`span`,{className:`text-white text-sm`,children:t(`printers.locations.selected`,{count:F.size})}),(0,w.jsxs)(v,{onClick:()=>B({ids:Array.from(F)}),disabled:Q,children:[(0,w.jsx)(ee,{className:`w-4 h-4 mr-1`}),t(`printers.locations.moveButton`)]}),(0,w.jsx)(v,{variant:`ghost`,onClick:()=>I(new Set),disabled:Q,children:t(`common.cancel`)})]}),j&&N.size>0&&(0,w.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 bg-bambu-dark border border-bambu-dark-tertiary rounded-xl shadow-2xl px-6 py-4 flex items-center gap-4 z-40`,children:[(0,w.jsx)(`span`,{className:`text-white text-sm`,children:t(`printers.locations.selected`,{count:N.size})}),(0,w.jsxs)(v,{variant:`danger`,onClick:()=>H(Array.from(N)),disabled:Q,children:[(0,w.jsx)(re,{className:`w-4 h-4 mr-1`}),t(`printers.locations.deleteSelected`)]}),(0,w.jsx)(v,{variant:`ghost`,onClick:()=>P(new Set),disabled:Q,children:t(`common.cancel`)})]}),L&&(0,w.jsx)(ve,{initial:L.mode===`edit`?L.location:void 0,saving:Y.isPending,onSave:e=>Y.mutate({value:e,location:L.mode===`edit`?L.location:void 0}),onCancel:()=>R(null)}),z&&(0,w.jsx)(ye,{count:z.ids.length,printerName:z.printerName,locations:W??[],saving:X.isPending,onMove:e=>X.mutate({ids:z.ids,location:e}),onCancel:()=>B(null)}),V&&(0,w.jsx)(oe,{title:V.length===1?t(`printers.locations.deleteTitle`):t(`printers.locations.deleteTitleMany`,{count:V.length}),message:t(`printers.locations.deleteMessage`,{count:De,names:V.join(`, `)}),confirmText:t(`common.delete`),variant:`danger`,isLoading:Z.isPending,onConfirm:()=>Z.mutate(V),onCancel:()=>H(null)})]})}export{D as PrinterLocationsPage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as c}from"./useQueries-C87lFrjE.js";import{t as l}from"./createLucideIcon-Yo2YoYjm.js";import{t as u}from"./arrow-left-MSgMxOFV.js";import{t as d}from"./box-BIRPxdgi.js";import{a as f}from"./info-DcT0QU8O.js";import{n as p}from"./ToastContext-VFOrCCoA.js";import{t as m}from"./loader-circle-CB4leTZa.js";import{t as ee}from"./move-CEngqF8v.js";import{t as te}from"./search-BpAJdxRw.js";import{t as h}from"./x-Dctff5l9.js";import{n as g,t as _}from"./Card-OUAj0Ayh.js";import{t as v}from"./Button-pwVKPiYn.js";import{$t as ne,At as re,Lt as y,Rn as ie,Rt as b,Zt as ae,_t as oe,ht as x,mt as se,yt as ce}from"./index-ggB_TpPo.js";var S=l(`user-minus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),C=e(n(),1),w=t(),le=100,T=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#14b8a6`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`],ue=[`name-asc`,`name-desc`,`count-asc`,`count-desc`],de=`printerLocations.hideEmpty`,fe=`printerLocations.sort`;function pe(e,t,n){try{let r=localStorage.getItem(e);return t.includes(r)?r:n}catch{return n}}function me(e,t){try{localStorage.setItem(e,t)}catch{}}var he=e=>e.location?.trim()||``;function ge({location:e}){return(0,w.jsxs)(`div`,{className:`p-2 rounded-lg bg-bambu-dark relative overflow-hidden flex-shrink-0`,children:[(0,w.jsx)(se.find(t=>t.name===e.icon)?.icon??d,{className:`w-[25px] h-[25px] text-bambu-gray`}),e.color&&(0,w.jsx)(`div`,{className:`absolute top-0 left-0 w-1 h-full`,style:{backgroundColor:e.color}})]})}function _e({printer:e,status:t,selected:n,canEdit:r,busy:a,onToggle:o,onMove:s,onRemove:c}){let{t:l}=i(),u=t?.state,d=t?.connected,f=l(d?u===`RUNNING`?`printers.status.printing`:u===`PAUSE`?`printers.status.paused`:u===`FINISH`?`printers.status.finished`:`printers.status.idle`:`printers.status.offline`),p=d?u===`RUNNING`?`bg-orange-500/20 text-orange-400`:u===`PAUSE`?`bg-yellow-500/20 text-yellow-400`:u===`FINISH`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`:`bg-gray-500/20 text-gray-400`;return(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-2 px-3 rounded-lg transition-colors ${n?`bg-bambu-green/10 border border-bambu-green/30`:`bg-bambu-dark-secondary hover:bg-bambu-dark`}`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[r&&(0,w.jsx)(`button`,{type:`button`,onClick:o,className:`text-bambu-gray hover:text-bambu-green transition-colors`,title:l(`printers.locations.selectPrinter`),"aria-label":l(`printers.locations.selectPrinter`),"aria-pressed":n,children:n?(0,w.jsx)(b,{className:`w-4 h-4 text-bambu-green`}):(0,w.jsx)(y,{className:`w-4 h-4`})}),(0,w.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${d?u===`RUNNING`||u===`PAUSE`?`bg-orange-500`:`bg-bambu-green`:`bg-gray-500`}`}),(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-white text-sm font-medium truncate`,children:e.name}),(0,w.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.model||l(`printers.status.unknown`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,w.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${p}`,children:f}),r&&(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:s,disabled:a,className:`text-bambu-gray hover:text-bambu-green hover:bg-bambu-green/10`,title:l(`printers.locations.move`),"aria-label":l(`printers.locations.move`),children:(0,w.jsx)(ee,{className:`w-3.5 h-3.5`})}),r&&c&&(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:c,disabled:a,className:`text-bambu-gray hover:text-red-400 hover:bg-red-500/10`,title:l(`printers.locations.removeFromLocation`),"aria-label":l(`printers.locations.removeFromLocation`),children:(0,w.jsx)(S,{className:`w-3.5 h-3.5`})})]})]})}function ve({initial:e,saving:t,onSave:n,onCancel:r}){let{t:a}=i(),[o,s]=(0,C.useState)(e?.name??``),[c,l]=(0,C.useState)(e?.icon??``),[u,d]=(0,C.useState)(e?.color??``),f=o.trim().length>0&&!t,p=()=>f&&n({name:o.trim(),icon:c,color:u});return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,w.jsx)(_,{className:`w-full max-w-md`,children:(0,w.jsxs)(g,{className:`space-y-4`,children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`printers.locations.editTitle`:`printers.locations.createTitle`)}),(0,w.jsx)(`input`,{type:`text`,value:o,maxLength:le,onChange:e=>s(e.target.value),placeholder:a(`printers.locations.namePlaceholder`),"aria-label":a(`printers.locations.namePlaceholder`),className:`w-full px-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&p(),e.key===`Escape`&&r()}}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:a(`printers.locations.icon`)}),(0,w.jsx)(x,{value:c,onChange:l})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:a(`printers.locations.color`)}),(0,w.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[T.map(e=>(0,w.jsx)(`button`,{type:`button`,onClick:()=>d(u===e?``:e),className:`w-8 h-8 rounded-lg transition-all ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:`hover:scale-105`}`,style:{backgroundColor:e},title:e,"aria-label":e,"aria-pressed":u===e},e)),u&&(0,w.jsx)(`button`,{type:`button`,onClick:()=>d(``),className:`w-8 h-8 rounded-lg border-2 border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:border-bambu-gray transition-all flex items-center justify-center`,title:a(`printers.locations.noColor`),"aria-label":a(`printers.locations.noColor`),children:(0,w.jsx)(h,{className:`w-3.5 h-3.5`})})]})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,w.jsx)(v,{variant:`secondary`,onClick:r,disabled:t,children:a(`common.cancel`)}),(0,w.jsx)(v,{onClick:p,disabled:!f,children:t?(0,w.jsx)(m,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`printers.locations.create`)})]})]})})})}var E=`__none__`;function ye({count:e,printerName:t,locations:n,saving:r,onMove:a,onCancel:o}){let{t:s}=i(),[c,l]=(0,C.useState)(``);return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,w.jsx)(_,{className:`w-full max-w-md`,children:(0,w.jsxs)(g,{className:`space-y-4`,children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===1?s(`printers.locations.moveTitle`):s(`printers.locations.moveTitleMany`,{count:e})}),t&&(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,w.jsxs)(`select`,{value:c,onChange:e=>l(e.target.value),"aria-label":s(`printers.locations.targetPlaceholder`),className:`w-full px-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,disabled:r,autoFocus:!0,children:[(0,w.jsx)(`option`,{value:``,disabled:!0,children:s(`printers.locations.targetPlaceholder`)}),n.map(e=>(0,w.jsx)(`option`,{value:e.name,children:e.name},e.name)),(0,w.jsx)(`option`,{value:E,children:s(`printers.locations.noLocation`)})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,w.jsx)(v,{variant:`secondary`,onClick:o,disabled:r,children:s(`common.cancel`)}),(0,w.jsx)(v,{onClick:()=>a(c===E?null:c),disabled:r||!c,children:r?(0,w.jsx)(m,{className:`w-4 h-4 animate-spin`}):s(`printers.locations.moveButton`)})]})]})})})}function D(){let e=a(),{t}=i(),{showToast:n}=p(),{hasPermission:l}=ce(),h=l(`printers:update`),[x,se]=(0,C.useState)(``),[S,le]=(0,C.useState)(()=>pe(de,[`true`,`false`],`false`)===`true`),[T,E]=(0,C.useState)(()=>pe(fe,ue,`name-asc`)),[D,O]=(0,C.useState)(!1),[k,A]=(0,C.useState)(null),[j,M]=(0,C.useState)(!1),[N,P]=(0,C.useState)(new Set),[F,I]=(0,C.useState)(new Set),[L,R]=(0,C.useState)(null),[z,B]=(0,C.useState)(null),[V,H]=(0,C.useState)(null);(0,C.useEffect)(()=>me(de,String(S)),[S]),(0,C.useEffect)(()=>me(fe,T),[T]),(0,C.useEffect)(()=>{j&&A(null)},[j]);let{data:U,isLoading:be}=o({queryKey:[`printers`],queryFn:r.getPrinters}),{data:W,isLoading:xe}=o({queryKey:[`printer-locations`],queryFn:r.getPrinterLocations}),Se=c({queries:(U??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>r.getPrinterStatus(e.id),refetchInterval:3e4}))}),Ce=new Map((U??[]).map((e,t)=>[e.id,Se[t]?.data])),G=(0,C.useMemo)(()=>{let e=new Map;for(let t of U??[]){let n=he(t);e.set(n,[...e.get(n)??[],t])}return e},[U]),K=G.get(``)??[],we=(U?.length??0)-K.length,Te=(0,C.useMemo)(()=>{let e=x.trim().toLowerCase(),t=(W??[]).filter(t=>(!e||t.name.toLowerCase().includes(e))&&(!S||t.printer_count>0)),n=(e,t)=>e.name.localeCompare(t.name,void 0,{numeric:!0,sensitivity:`base`});return[...t].sort((e,t)=>{switch(T){case`name-desc`:return n(t,e);case`count-asc`:return e.printer_count-t.printer_count||n(e,t);case`count-desc`:return t.printer_count-e.printer_count||n(e,t);default:return n(e,t)}})},[W,x,S,T]),q=()=>{e.invalidateQueries({queryKey:[`printer-locations`]}),e.invalidateQueries({queryKey:[`printers`]})},J=e=>n(t(`printers.locations.failed`,{error:e instanceof Error?e.message:String(e)}),`error`),Y=s({mutationFn:({value:e,location:t})=>t?r.updatePrinterLocation({name:t.name,...e.name===t.name?{}:{new_name:e.name},icon:e.icon||null,color:e.color||null}):r.createPrinterLocation({name:e.name,icon:e.icon||null,color:e.color||null}),onSuccess:(e,{location:r})=>{q(),r&&k===r.name&&A(e.name),n(t(r?`printers.locations.saved`:`printers.locations.created`)),R(null)},onError:J}),X=s({mutationFn:({ids:e,location:t})=>r.assignPrinterLocation(e,t),onSuccess:({moved:e})=>{q(),n(t(`printers.locations.moved`,{count:e})),I(new Set),B(null)},onError:J}),Z=s({mutationFn:e=>r.deletePrinterLocations(e),onSuccess:({deleted:e})=>{q(),n(t(`printers.locations.deleted`,{count:e})),P(new Set),M(!1),H(null)},onError:e=>{J(e),H(null)}}),Q=X.isPending||Z.isPending||Y.isPending,Ee=(e,t)=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n};if(be||xe)return(0,w.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,w.jsx)(m,{className:`w-8 h-8 text-bambu-green animate-spin`})});let De=(V??[]).reduce((e,t)=>e+(W?.find(e=>e.name===t)?.printer_count??0),0),Oe=e=>({"name-asc":t(`printers.locations.sortNameAsc`),"name-desc":t(`printers.locations.sortNameDesc`),"count-asc":t(`printers.locations.sortCountAsc`),"count-desc":t(`printers.locations.sortCountDesc`)})[e],ke=(e,t)=>(0,w.jsx)(_e,{printer:e,status:Ce.get(e.id),selected:F.has(e.id),canEdit:h&&!j,busy:Q,onToggle:()=>I(Ee(F,e.id)),onMove:()=>B({ids:[e.id],printerName:e.name}),onRemove:t?()=>X.mutate({ids:[e.id],location:null}):void 0},e.id),$=K.length>0&&K.every(e=>F.has(e.id));return(0,w.jsxs)(`div`,{className:`p-4 md:p-8 pb-28`,children:[(0,w.jsxs)(ie,{to:`/`,className:`inline-flex items-center gap-1 mb-3 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,w.jsx)(u,{className:`w-4 h-4`}),` `,t(`printers.locations.backToPrinters`)]}),(0,w.jsxs)(`div`,{className:`mb-4`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 mb-1`,children:[(0,w.jsx)(d,{className:`w-[25px] h-[25px] text-bambu-green`}),(0,w.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:t(`printers.locations.title`)})]}),(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`printers.locations.subtitle`,{grouped:we,ungrouped:K.length})})]}),(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-3 mb-6`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,w.jsx)(te,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,w.jsx)(`input`,{type:`text`,value:x,onChange:e=>se(e.target.value),placeholder:t(`printers.locations.search`),"aria-label":t(`printers.locations.search`),className:`w-full pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`})]}),(0,w.jsx)(v,{onClick:()=>le(!S),variant:S?`primary`:`secondary`,children:t(S?`printers.locations.showEmpty`:`printers.locations.hideEmpty`)}),h&&(0,w.jsxs)(v,{onClick:()=>{P(new Set),M(!j)},variant:j?`primary`:`secondary`,children:[(0,w.jsx)(b,{className:`w-4 h-4 mr-1`}),t(j?`printers.locations.done`:`printers.locations.select`)]}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsxs)(v,{onClick:()=>O(!D),variant:`secondary`,"aria-haspopup":`menu`,children:[(0,w.jsx)(f,{className:`w-4 h-4 mr-1 transition-transform ${D?`rotate-180`:``}`}),Oe(T)]}),D&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>O(!1)}),(0,w.jsx)(`div`,{role:`menu`,className:`absolute right-0 top-full mt-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg p-1 min-w-[10rem]`,children:ue.map(e=>(0,w.jsx)(`button`,{role:`menuitem`,onClick:()=>{E(e),O(!1)},className:`w-full text-left px-3 py-2 text-sm rounded transition-colors ${T===e?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white`}`,children:Oe(e)},e))})]})]}),h&&(0,w.jsxs)(v,{onClick:()=>R({mode:`create`}),children:[(0,w.jsx)(ae,{className:`w-4 h-4 mr-1`}),t(`printers.locations.create`)]})]}),Te.length===0&&K.length===0?(0,w.jsx)(_,{children:(0,w.jsx)(g,{className:`text-center py-12 text-bambu-gray`,children:t(x?`printers.locations.noResults`:`printers.locations.none`)})}):(0,w.jsxs)(`div`,{className:`space-y-3`,children:[Te.map(e=>{let n=k===e.name,r=N.has(e.name);return(0,w.jsx)(_,{children:(0,w.jsxs)(g,{className:`p-4`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,w.jsxs)(`button`,{type:`button`,onClick:()=>j?P(Ee(N,e.name)):A(n?null:e.name),className:`flex items-center gap-3 flex-1 min-w-0 text-left`,"aria-expanded":j?void 0:n,"aria-pressed":j?r:void 0,children:[j?r?(0,w.jsx)(b,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}):(0,w.jsx)(y,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,w.jsx)(f,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 transition-transform ${n?`rotate-180`:``}`}),(0,w.jsx)(ge,{location:e}),(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`printers.locations.printerCount`,{count:e.printer_count})})]})]}),h&&!j&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>R({mode:`edit`,location:e}),disabled:Q,className:`text-bambu-gray hover:text-blue-400 hover:bg-blue-500/10`,title:t(`common.edit`),"aria-label":t(`common.edit`),children:(0,w.jsx)(ne,{className:`w-4 h-4`})}),(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>H([e.name]),disabled:Q,className:`text-red-500 hover:text-red-400 hover:bg-red-500/10`,title:t(`common.delete`),"aria-label":t(`common.delete`),children:(0,w.jsx)(re,{className:`w-4 h-4`})})]})]}),n&&(0,w.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-2`,children:(G.get(e.name)??[]).length===0?(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:t(`printers.locations.noPrinters`)}):(G.get(e.name)??[]).map(e=>ke(e,!0))})]})},e.name)}),K.length>0&&(0,w.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t(`printers.locations.ungroupedPrinters`,{count:K.length})}),h&&!j&&(0,w.jsx)(`button`,{type:`button`,onClick:()=>{let e=new Set(F);K.forEach(t=>$?e.delete(t.id):e.add(t.id)),I(e)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors`,children:t($?`common.deselectAll`:`common.selectAll`)})]}),(0,w.jsx)(`div`,{className:`space-y-2`,children:K.map(e=>ke(e,!1))})]})]}),h&&!j&&F.size>0&&(0,w.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 bg-bambu-dark border border-bambu-dark-tertiary rounded-xl shadow-2xl px-6 py-4 flex items-center gap-4 z-40`,children:[(0,w.jsx)(`span`,{className:`text-white text-sm`,children:t(`printers.locations.selected`,{count:F.size})}),(0,w.jsxs)(v,{onClick:()=>B({ids:Array.from(F)}),disabled:Q,children:[(0,w.jsx)(ee,{className:`w-4 h-4 mr-1`}),t(`printers.locations.moveButton`)]}),(0,w.jsx)(v,{variant:`ghost`,onClick:()=>I(new Set),disabled:Q,children:t(`common.cancel`)})]}),j&&N.size>0&&(0,w.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 bg-bambu-dark border border-bambu-dark-tertiary rounded-xl shadow-2xl px-6 py-4 flex items-center gap-4 z-40`,children:[(0,w.jsx)(`span`,{className:`text-white text-sm`,children:t(`printers.locations.selected`,{count:N.size})}),(0,w.jsxs)(v,{variant:`danger`,onClick:()=>H(Array.from(N)),disabled:Q,children:[(0,w.jsx)(re,{className:`w-4 h-4 mr-1`}),t(`printers.locations.deleteSelected`)]}),(0,w.jsx)(v,{variant:`ghost`,onClick:()=>P(new Set),disabled:Q,children:t(`common.cancel`)})]}),L&&(0,w.jsx)(ve,{initial:L.mode===`edit`?L.location:void 0,saving:Y.isPending,onSave:e=>Y.mutate({value:e,location:L.mode===`edit`?L.location:void 0}),onCancel:()=>R(null)}),z&&(0,w.jsx)(ye,{count:z.ids.length,printerName:z.printerName,locations:W??[],saving:X.isPending,onMove:e=>X.mutate({ids:z.ids,location:e}),onCancel:()=>B(null)}),V&&(0,w.jsx)(oe,{title:V.length===1?t(`printers.locations.deleteTitle`):t(`printers.locations.deleteTitleMany`,{count:V.length}),message:t(`printers.locations.deleteMessage`,{count:De,names:V.join(`, `)}),confirmText:t(`common.delete`),variant:`danger`,isLoading:Z.isPending,onConfirm:()=>Z.mutate(V),onCancel:()=>H(null)})]})}export{D as PrinterLocationsPage};
\ No newline at end of file
diff --git a/static/assets/PrintersPage-CLoeMCjh.js b/static/assets/PrintersPage-CIZBwwUQ.js
similarity index 99%
rename from static/assets/PrintersPage-CLoeMCjh.js
rename to static/assets/PrintersPage-CIZBwwUQ.js
index 04efe8a80..ff04e6743 100644
--- a/static/assets/PrintersPage-CLoeMCjh.js
+++ b/static/assets/PrintersPage-CIZBwwUQ.js
@@ -1,4 +1,4 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,c as a,l as o,s,t as c,w as l,x as u}from"./client-BdOyoZJz.js";import{t as d}from"./react-dom-xhkz5--P.js";import{n as f}from"./QueryClientProvider-Clbyr4Jg.js";import{t as p}from"./useQuery-CCy0EwsM.js";import{t as m}from"./useMutation-qh3Iyscy.js";import{t as h}from"./createLucideIcon-Yo2YoYjm.js";import{c as g,i as _,n as v,o as y,r as b,s as x}from"./haSensorDisplay-CSo8Nw_c.js";import{t as S}from"./arrow-down-C4OBNDqJ.js";import{t as C}from"./arrow-left-MSgMxOFV.js";import{t as w}from"./arrow-right-Da96kh4S.js";import{t as T}from"./arrow-up-down-C-1Kkt1x.js";import{t as E}from"./arrow-up-Dam8cLfE.js";import{i as D,n as O,r as k,t as A}from"./ReferenceLine-l3CI8D5f.js";import{t as j}from"./box-BIRPxdgi.js";import{n as M,t as N}from"./fan-DSlOeWAh.js";import{t as P}from"./calendar-DiVEdzUw.js";import{t as F}from"./check-D1Pn8T1J.js";import{a as I,n as L,r as R,t as ee}from"./info-DcT0QU8O.js";import{n as te,r as ne}from"./ToastContext-VFOrCCoA.js";import{t as z}from"./copy-3N5VKzXz.js";import{t as re}from"./ellipsis-vertical-So0E77JK.js";import{t as B}from"./eye-off-B6dY82pM.js";import{t as ie}from"./file-box-BjB1o93N.js";import{t as ae}from"./GcodeToolpathViewer-D4M17KI8.js";import{n as V,t as oe}from"./ContextMenu-B4uGJkKW.js";import{n as se,t as ce}from"./scan-search-LN9I03Ga.js";import{t as le}from"./funnel-BtI48m95.js";import{t as ue}from"./gauge-xO5PdXj0.js";import{t as de}from"./grip-vertical-D4urhrwn.js";import{t as fe}from"./hard-drive-CN9rq6Uq.js";import{t as pe}from"./layout-grid-D4S7CgZJ.js";import{t as H}from"./loader-circle-CB4leTZa.js";import{t as me}from"./log-in-D7NdqHOf.js";import{t as he}from"./maximize-2-Cggm3z8J.js";import{t as U}from"./minimize-2-BLq3FJZO.js";import{a as ge,i as _e,n as ve,r as ye,t as W}from"./CameraDiagnoseModal-DaFY1v8I.js";import{t as G}from"./minus-D0aY9wbr.js";import{a as be,c as xe,i as Se,l as K,n as Ce,r as we,s as Te,t as q,u as J}from"./CopyButton-CyNT06yS.js";import{t as Ee}from"./move-CEngqF8v.js";import{t as De}from"./package-D9xR0eOt.js";import{t as Oe}from"./pause-CPKrVlsD.js";import{t as ke}from"./play-DROvjtg7.js";import{t as Ae}from"./search-BpAJdxRw.js";import{t as je}from"./settings-2-DYB5IzKV.js";import{n as Me,t as Ne}from"./wind-CsHQYbhI.js";import{D as Pe,Fn as Fe,It as Ie,Kt as Le,L as Re,Ln as ze,Lt as Be,M as Ve,Mn as He,On as Ue,Pn as We,R as Ge,Rn as Ke,S as qe,Sn as Je,St as Ye,T as Xe,Ut as Ze,Xt as Qe,Zt as $e,an as et,at as tt,b as nt,c as rt,cn as it,d as at,f as ot,gn as st,j as ct,jt as lt,k as ut,l as dt,ln as ft,mn as pt,mt,nn as ht,p as gt,pt as _t,s as vt,sn as yt,t as bt,u as xt,vn as St,w as Ct,wn as wt,x as Tt,y as Et,z as Dt}from"./CartesianChart-DcboTNtX.js";import{t as Ot}from"./triangle-alert-gIik0G2C.js";import{t as kt}from"./unlink-DJBJ04VB.js";import{i as At,n as jt,r as Mt,t as Nt}from"./CameraWall-yInrBATM.js";import{t as Pt}from"./x-Dctff5l9.js";import{n as Ft,t as It}from"./zoom-out-C85W_TC5.js";import{n as Lt,t as Rt}from"./Card-OUAj0Ayh.js";import{t as zt}from"./file-DDkFXH-b.js";import{t as Y}from"./Button-pwVKPiYn.js";import{a as Bt,c as Vt,i as Ht,o as Ut,s as Wt,t as Gt,u as Kt,v as qt}from"./date-G9KUauqz.js";import{n as Jt,r as Yt}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$ as Xt,$t as Zt,At as Qt,Cn as $t,Ct as en,D as tn,E as nn,Et as rn,Ft as an,G as on,H as sn,J as cn,Jt as ln,K as un,Kt as dn,Lt as fn,Mn as pn,Mt as mn,N as hn,Nt as gn,O as _n,On as vn,Ot as yn,Rn as bn,Rt as xn,Sn,U as Cn,V as wn,Vn as Tn,Vt as En,W as Dn,Wt as On,X as kn,Y as An,Yt as jn,Z as Mn,Zt as Nn,_ as Pn,_n as Fn,_t as In,an as Ln,at as Rn,b as zn,bn as Bn,bt as Vn,cn as Hn,ct as Un,dt as Wn,et as Gn,fn as Kn,ft as qn,h as Jn,jn as Yn,jt as Xn,k as Zn,q as Qn,sn as $n,tt as er,un as tr,ut as nr,v as rr,vt as ir,wn as ar,xn as or,xt as sr,y as cr,yt as lr,z as ur}from"./index-Bw-_P2Fg.js";import{n as dr,t as fr}from"./FileUploadModal-GYUY0fS6.js";import{n as pr,t as mr}from"./ErrorBarContext-6wvnfk_q.js";import{t as hr}from"./Toggle-CwMiiK0g.js";import{t as gr}from"./printerModel-DrNvERGQ.js";import{t as _r}from"./queueItemName-UFY7kpjG.js";import{n as vr,r as yr,t as br}from"./ConfigureAmsSlotModal-uPwVXZ4s.js";var xr=h(`air-vent`,[[`path`,{d:`M18 17.5a2.5 2.5 0 1 1-4 2.03V12`,key:`yd12zl`}],[`path`,{d:`M6 12H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`larmp2`}],[`path`,{d:`M6 8h12`,key:`6g4wlu`}],[`path`,{d:`M6.6 15.572A2 2 0 1 0 10 17v-5`,key:`1x1kqn`}]]),Sr=h(`chart-line`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`m19 9-5 5-4-4-3 3`,key:`2osh9i`}]]),Cr=h(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),wr=h(`fullscreen`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`rect`,{width:`10`,height:`8`,x:`7`,y:`8`,rx:`1`,key:`vys8me`}]]),Tr=h(`hourglass`,[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]),Er=h(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),Dr=h(`picture-in-picture-2`,[[`path`,{d:`M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4`,key:`daa4of`}],[`rect`,{width:`10`,height:`7`,x:`12`,y:`13`,rx:`2`,key:`1nb8gs`}]]),Or=h(`repeat`,[[`path`,{d:`m17 2 4 4-4 4`,key:`nntrym`}],[`path`,{d:`M3 11v-1a4 4 0 0 1 4-4h14`,key:`84bu3i`}],[`path`,{d:`m7 22-4-4 4-4`,key:`1wqhfi`}],[`path`,{d:`M21 13v1a4 4 0 0 1-4 4H3`,key:`1rx37r`}]]),kr=h(`signal`,[[`path`,{d:`M2 20h.01`,key:`4haj6o`}],[`path`,{d:`M7 20v-4`,key:`j294jx`}],[`path`,{d:`M12 20v-8`,key:`i3yub9`}],[`path`,{d:`M17 20V8`,key:`1tkaf5`}],[`path`,{d:`M22 4v16`,key:`sih9yq`}]]),Ar=h(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),jr=h(`snowflake`,[[`path`,{d:`m10 20-1.25-2.5L6 18`,key:`18frcb`}],[`path`,{d:`M10 4 8.75 6.5 6 6`,key:`7mghy3`}],[`path`,{d:`m14 20 1.25-2.5L18 18`,key:`1chtki`}],[`path`,{d:`m14 4 1.25 2.5L18 6`,key:`1b4wsy`}],[`path`,{d:`m17 21-3-6h-4`,key:`15hhxa`}],[`path`,{d:`m17 3-3 6 1.5 3`,key:`11697g`}],[`path`,{d:`M2 12h6.5L10 9`,key:`kv9z4n`}],[`path`,{d:`m20 10-1.5 2 1.5 2`,key:`1swlpi`}],[`path`,{d:`M22 12h-6.5L14 15`,key:`1mxi28`}],[`path`,{d:`m4 10 1.5 2L4 14`,key:`k9enpj`}],[`path`,{d:`m7 21 3-6-1.5-3`,key:`j8hb9u`}],[`path`,{d:`m7 3 3 6h4`,key:`1otusx`}]]),Mr=h(`square-minus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]]),Nr=(e,t,n,r)=>tt(e,`xAxis`,t,r),Pr=(e,t,n,r)=>_t(e,`xAxis`,t,r),Fr=(e,t,n,r)=>tt(e,`yAxis`,n,r),Ir=(e,t,n,r)=>_t(e,`yAxis`,n,r),Lr=pt([Ze,Nr,Fr,Pr,Ir],(e,t,n,r,i)=>ft(e,`xAxis`)?ht(t,r,!1):ht(n,i,!1)),Rr=(e,t,n,r,i)=>i;function zr(e){return e.type===`line`}var Br=pt([Ze,Nr,Fr,Pr,Ir,pt([mt,Rr],(e,t)=>e.filter(zr).find(e=>e.id===t)),Lr,lt],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=s;if(!(a==null||t==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null||e!==`horizontal`&&e!==`vertical`)){var{dataKey:d,data:f}=a,p=f!=null&&f.length>0?f:c?.slice(l,u+1);if(p!=null)return di({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataKey:d,bandSize:o,displayedData:p})}}),X=e(n()),Vr=[`id`],Hr=[`type`,`layout`,`connectNulls`,`needClip`,`shape`],Ur=[`activeDot`,`animateNewValues`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`hide`,`isAnimationActive`,`label`,`legendType`,`xAxisId`,`yAxisId`,`id`];function Wr(){return Wr=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var{dataKey:t,name:n,stroke:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:yt(n,t),payload:e}]},Qr=X.memo(e=>{var{dataKey:t,data:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,unit:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:n,getPosition:Ue,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:yt(o,t),hide:s,type:l,color:r,unit:c,graphicalItemId:u}};return X.createElement(Pe,{tooltipEntrySettings:d})}),$r=(e,t)=>`${t}px ${e-t}px`;function ei(e,t){for(var n=e.length%2==0?e:[...e,0],r=[],i=0;i{var r=n.reduce((e,t)=>e+t);if(!r)return $r(t,e);for(var i=Math.floor(e/r),a=e%r,o=t-e,s=[],c=0,l=0;ca){s=[...n.slice(0,c),a-l];break}}var f=s.length%2==0?[0,o]:[o];return[...ei(n,i),...s,...f].map(e=>`${e}px`).join(`, `)};function ni(e){var{clipPathId:t,points:n,props:r}=e,{dot:i,dataKey:a,needClip:o}=r,{id:s}=r,c=Fe(Yr(r,Vr));return X.createElement(Tt,{points:n,dot:i,className:`recharts-line-dots`,dotClassName:`recharts-line-dot`,dataKey:a,baseProps:c,needClip:o,clipPathId:t})}function Q(e){var{showLabels:t,children:n,points:r}=e,i=(0,X.useMemo)(()=>r?.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return Z(Z({},t),{},{value:e.value,payload:e.payload,viewBox:t,parentViewBox:void 0,fill:void 0})}),[r]);return X.createElement(ct,{value:t?i:void 0},n)}function ri(e){var{clipPathId:t,pathRef:n,points:r,strokeDasharray:i,props:a}=e,{type:o,layout:s,connectNulls:c,needClip:l,shape:u}=a,d=Z(Z({},We(Yr(a,Hr))),{},{fill:`none`,className:`recharts-line-curve`,clipPath:l?`url(#clipPath-${t})`:void 0,points:r,type:o,layout:s,connectNulls:c,strokeDasharray:i??a.strokeDasharray});return X.createElement(X.Fragment,null,r?.length>1&&X.createElement(pr,Wr({shapeType:`curve`,option:u},d,{pathRef:n})),X.createElement(ni,{points:r,clipPathId:t,props:a}))}function ii(e){try{return e&&e.getTotalLength&&e.getTotalLength()||0}catch{return 0}}function ai(e){var{clipPathId:t,props:n,pathRef:r,previousPointsRef:i,longestAnimatedLengthRef:a}=e,{points:o,strokeDasharray:s,isAnimationActive:c,animationBegin:l,animationDuration:u,animationEasing:d,animateNewValues:f,width:p,height:m,onAnimationEnd:h,onAnimationStart:g}=n,_=i.current,v=Ie(o,`recharts-line-`),y=(0,X.useRef)(v),[b,x]=(0,X.useState)(!1),S=!b,C=(0,X.useCallback)(()=>{typeof h==`function`&&h(),x(!1)},[h]),w=(0,X.useCallback)(()=>{typeof g==`function`&&g(),x(!0)},[g]),T=ii(r.current),E=(0,X.useRef)(0);y.current!==v&&(E.current=a.current,y.current=v);var D=E.current;return X.createElement(Q,{points:o,showLabels:S},n.children,X.createElement(Be,{animationId:v,begin:l,duration:u,isActive:c,easing:d,onAnimationEnd:C,onAnimationStart:w,key:v},e=>{var l=Je(D,T+D,e),u=Math.min(l,T),d=c?s?ti(u,T,`${s}`.split(/[,\s]+/gim).map(e=>parseFloat(e))):$r(T,u):s==null?void 0:String(s);if(e>0&&T>0&&(i.current=o,a.current=Math.max(a.current,u)),_){var h=_.length/o.length,g=e===1?o:o.map((t,n)=>{var r=Math.floor(n*h);if(_[r]){var i=_[r];return Z(Z({},t),{},{x:Je(i.x,t.x,e),y:Je(i.y,t.y,e)})}return f?Z(Z({},t),{},{x:Je(p*2,t.x,e),y:Je(m/2,t.y,e)}):Z(Z({},t),{},{x:t.x,y:t.y})});return i.current=g,X.createElement(ri,{props:n,points:g,clipPathId:t,pathRef:r,strokeDasharray:d})}return X.createElement(ri,{props:n,points:o,clipPathId:t,pathRef:r,strokeDasharray:d})}),X.createElement(Ve,{label:n.label}))}function oi(e){var{clipPathId:t,props:n}=e,r=(0,X.useRef)(null),i=(0,X.useRef)(0),a=(0,X.useRef)(null);return X.createElement(ai,{props:n,clipPathId:t,previousPointsRef:r,longestAnimatedLengthRef:i,pathRef:a})}var si=(e,t)=>({x:e.x??void 0,y:e.y??void 0,value:e.value,errorVal:it(e.payload,t)}),ci=class extends X.Component{render(){var{hide:e,dot:t,points:n,className:r,xAxisId:i,yAxisId:a,top:o,left:s,width:c,height:l,id:u,needClip:d,zIndex:f}=this.props;if(e)return null;var p=ze(`recharts-line`,r),m=u,{r:h,strokeWidth:g}=xt(t),_=ut(t),v=h*2+g,y=d?`url(#clipPath-${_?``:`dots-`}${m})`:void 0;return X.createElement(Dt,{zIndex:f},X.createElement(He,{className:p},d&&X.createElement(`defs`,null,X.createElement(at,{clipPathId:m,xAxisId:i,yAxisId:a}),!_&&X.createElement(`clipPath`,{id:`clipPath-dots-${m}`},X.createElement(`rect`,{x:s-v/2,y:o-v/2,width:c+v,height:l+v}))),X.createElement(mr,{xAxisId:i,yAxisId:a,data:n,dataPointFormatter:si,errorBarOffset:0},X.createElement(oi,{props:this.props,clipPathId:m}))),X.createElement(Et,{activeDot:this.props.activeDot,points:n,mainColor:this.props.stroke,itemDataKey:this.props.dataKey,clipPath:y}))}},li={activeDot:!0,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,connectNulls:!1,dot:!0,fill:`#fff`,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,xAxisId:0,yAxisId:0,zIndex:Ye.line,type:`linear`};function ui(e){var t=St(e,li),{activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,connectNulls:s,dot:c,hide:l,isAnimationActive:u,label:d,legendType:f,xAxisId:p,yAxisId:m,id:h}=t,g=Yr(t,Ur),{needClip:_}=ot(p,m),v=nt(),y=Le(),b=$e(),x=st(e=>Br(e,p,m,b,h));if(y!==`horizontal`&&y!==`vertical`||x==null||v==null)return null;var{height:S,width:C,x:w,y:T}=v;return X.createElement(ci,Wr({},g,{id:h,connectNulls:s,dot:c,activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,isAnimationActive:u,hide:l,label:d,legendType:f,xAxisId:p,yAxisId:m,points:x,layout:y,height:S,width:C,left:w,top:T,needClip:_}))}function di(e){var{layout:t,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,dataKey:o,bandSize:s,displayedData:c}=e;return c.map((e,c)=>{var l=it(e,o);if(t===`horizontal`)return{x:et({axis:n,ticks:i,bandSize:s,entry:e,index:c}),y:(wt(l)?null:r.scale.map(l))??null,value:l,payload:e};var u=wt(l)?null:n.scale.map(l),d=et({axis:r,ticks:a,bandSize:s,entry:e,index:c});return u==null||d==null?null:{x:u,y:d,value:l,payload:e}}).filter(Boolean)}function fi(e){var t=St(e,li),n=$e();return X.createElement(Ct,{id:t.id,type:`line`},e=>X.createElement(X.Fragment,null,X.createElement(Xe,{legendPayload:Zr(t)}),X.createElement(Qr,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),X.createElement(qe,{type:`line`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,hide:t.hide,isPanorama:n}),X.createElement(ui,Wr({},t,{id:e}))))}var pi=X.memo(fi,dt);pi.displayName=`Line`;var mi=[`axis`],hi=(0,X.forwardRef)((e,t)=>X.createElement(bt,{chartName:`LineChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:mi,tooltipPayloadSearcher:Ge,categoricalChartProps:e,ref:t})),gi=e(d(),1);function _i(e,t){let n=e.split(`.`).map(e=>parseInt(e,10)||0),r=t.split(`.`).map(e=>parseInt(e,10)||0);for(;n.length<4;)n.push(0);for(;r.length<4;)r.push(0);for(let e=0;e<4;e++)if(n[e]!==r[e])return n[e]-r[e];return 0}function vi(e,t,n,r){if(!e)return``;if(r)return`${e} — ${r}`;if(!t)return e;let i=t.match(/plate_(\d+)\.gcode/);return i&&parseInt(i[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:i[1]})}`:e}var yi=new Set([`A1`,`A1MINI`,`A2L`,`A1M`,`N1`,`N2S`,`N9`,`A04`,`A11`,`A12`]);function bi(e){return e?yi.has(e.toUpperCase().replace(/[^A-Z0-9]/g,``)):!1}function xi(e){let t=typeof window<`u`&&window.visualViewport?window.visualViewport.height:typeof window<`u`?window.innerHeight:0,{triggerRect:n,popoverWidth:r,estimatedHeight:i,viewportHeight:a=t,viewportWidth:o=window.innerWidth,margin:s=8,gap:c=4,horizontalAlign:l=`right`}=e,u=n.bottom+c,d=`below`;if(u+i>a-s){let e=n.top-c-i;e>=s&&(u=e,d=`above`)}let f=n.left+(n.right-n.left)/2,p=l===`center`?f-r/2:n.right-r;po-s&&(p=Math.max(s,o-r-s));let m=d===`above`?n.top-c:u,h=Math.max(14,Math.min(r-14,f-p));return{top:u,left:p,placement:d,anchorY:m,arrowLeft:h}}var Si=`cameraViewMode`,Ci=`cameraWindowState`;function wi(e){return e===`window`||e===`embedded`}function Ti(){try{let e=localStorage.getItem(Si);return wi(e)?e:null}catch{return null}}function Ei(e){try{localStorage.setItem(Si,e)}catch{}}function Di(e){let t={width:640,height:400};try{let e=localStorage.getItem(Ci);if(e){let n=JSON.parse(e);n&&typeof n==`object`&&(t=n)}}catch{}let n=[`width=${t.width??640}`,`height=${t.height??400}`,t.left===void 0?``:`left=${t.left}`,t.top===void 0?``:`top=${t.top}`,`menubar=no,toolbar=no,location=no,status=no`].filter(Boolean).join(`,`);window.open(`/camera/${e}`,`camera-${e}`,n)}var Oi={NYLON:`PA`,PA6:`PA`,PA11:`PA`,PA12:`PA`,PAHT:`PA`,PPA:`PA`};function ki(e,t){let n=(e||``).split(` `)[0].toUpperCase();for(let e of[n,n.split(`-`)[0]]){let n=Oi[e]??e;if(t[n])return n}return`PLA`}function Ai(e,t,n,r=new Date){return e===`now`?null:e===`delay`?new Date(r.getTime()+t*6e4).toISOString():new Date(n).toISOString()}var ji=`printerHiddenExternalSpools`;function Mi(){try{let e=localStorage.getItem(ji);if(!e)return{};let t=JSON.parse(e);return!t||typeof t!=`object`||Array.isArray(t)?{}:t}catch{return{}}}function Ni(e){return Mi()[String(e)]===!0}function Pi(e,t){let n=Mi();t?n[String(e)]=!0:delete n[String(e)];try{localStorage.setItem(ji,JSON.stringify(n))}catch{}}var $=t(),Fi=[{key:`printing`,dot:`bg-bambu-green`},{key:`paused`,dot:`bg-status-warning`},{key:`finished`,dot:`bg-blue-400`},{key:`idle`,dot:`bg-bambu-green`},{key:`error`,dot:`bg-status-error`},{key:`offline`,dot:`bg-gray-400`}];function Ii({selectedIds:e,printers:t,onClose:n,onSelectAll:r,onSelectByLocation:i,onSelectByState:a,onAction:o,actionPending:s}){let{t:c}=l(),{hasPermission:u}=lr(),d=f(),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),_=Array.from(e).map(e=>({id:e,status:d.getQueryData([`printerStatus`,e])})),v=_.some(({status:e})=>e?.connected&&e.state===`RUNNING`),y=_.some(({status:e})=>e?.connected&&e.state===`PAUSE`),b=v||y,x=_.some(({status:e})=>!!(e?.connected&&e.awaiting_plate_clear)),S=_.some(({status:e})=>!e?.connected||!e.hms_errors?!1:Mt(e.hms_errors).length>0),C=u(`printers:control`),w=u(`printers:clear_plate`),T=[...new Set(t.map(e=>e.location).filter(e=>!!e))].sort(),E={printing:0,paused:0,finished:0,idle:0,error:0,offline:0};t.forEach(e=>{let t=d.getQueryData([`printerStatus`,e.id]);if(!t||!t.connected){E.offline++;return}let n=t.hms_errors?Mt(t.hms_errors).length>0:!1;switch(n&&E.error++,t.state){case`RUNNING`:E.printing++;break;case`PAUSE`:E.paused++;break;case`FINISH`:E.finished++;break;case`FAILED`:n||E.finished++;break;default:E.idle++;break}});let O={printing:c(`printers.status.printing`),paused:c(`printers.status.paused`,`Paused`),finished:c(`printers.status.finished`,`Finished`),idle:c(`printers.status.idle`),error:c(`printers.status.problem`),offline:c(`printers.status.offline`)};return(0,$.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:n,children:(0,$.jsx)(Pt,{className:`w-4 h-4`})}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsx)(`span`,{className:`text-white font-medium text-sm`,children:c(`printers.bulk.selected`,{count:e.size})}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:r,children:c(`printers.bulk.selectAll`)}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>{g(!h),m(!1)},children:[c(`printers.bulk.selectByState`),(0,$.jsx)(I,{className:`w-3 h-3 transition-transform ${h?`rotate-180`:``}`})]}),h&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>g(!1)}),(0,$.jsx)(`div`,{className:`absolute bottom-full mb-2 left-0 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:Fi.filter(({key:e})=>E[e]>0).map(({key:e,dot:t})=>(0,$.jsxs)(`button`,{onClick:()=>{a(e),g(!1)},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full ${t}`}),O[e],(0,$.jsx)(`span`,{className:`ml-auto text-bambu-gray text-xs`,children:E[e]})]},e))})]})]}),T.length>0&&(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>{m(!p),g(!1)},children:[c(`printers.bulk.selectByLocation`),(0,$.jsx)(I,{className:`w-3 h-3 transition-transform ${p?`rotate-180`:``}`})]}),p&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>m(!1)}),(0,$.jsx)(`div`,{className:`absolute bottom-full mb-2 left-0 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:T.map(e=>(0,$.jsx)(`button`,{onClick:()=>{i(e),m(!1)},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors`,children:e},e))})]})]}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsxs)(Y,{size:`sm`,className:`bg-red-500 hover:bg-red-600`,onClick:()=>o(`stop`),disabled:s||!C||!b,title:C?b?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(fn,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.stop`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`pause`),disabled:s||!C||!v,title:C?v?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(Oe,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.pause`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`resume`),disabled:s||!C||!y,title:C?y?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(ke,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.resume`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`clearHMS`),disabled:s||!C||!S,title:C?S?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(D,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.clearHMS`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`clearPlate`),disabled:s||!w||!x,title:w?x?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(k,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.clearPlate`)]})]})}function Li({printerId:e,filePath:t,filename:n,onClose:r}){let[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)([]),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),p=n.toLowerCase().split(`.`).pop()||``,m=p===`3mf`||p===`stl`,h=p===`gcode`||p===`3mf`;(0,X.useEffect)(()=>{o(m?`3d`:h?`gcode`:null)},[m,h]),(0,X.useEffect)(()=>{c([]),f(null),m&&(u(!0),i.getPrinterFilePlates(e,t).then(e=>c(e.plates||[])).catch(()=>c([])).finally(()=>u(!1)))},[t,m,e]);let g=s.length>1,_=d==null?null:s.find(e=>e.index===d)??null;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-6`,onClick:r,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-4xl h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate flex-1 mr-4`,children:n}),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:r,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`button`,{onClick:()=>m&&o(`3d`),disabled:!m,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${a===`3d`?`text-bambu-green border-b-2 border-bambu-green`:m?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,$.jsx)(j,{className:`w-4 h-4`}),`3D Model`,!m&&(0,$.jsx)(`span`,{className:`text-xs`,children:`(not available)`})]}),(0,$.jsxs)(`button`,{onClick:()=>h&&o(`gcode`),disabled:!h,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${a===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:h?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,$.jsx)(or,{className:`w-4 h-4`}),`G-code Preview`,!h&&(0,$.jsx)(`span`,{className:`text-xs`,children:`(not sliced)`})]})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:a===`3d`&&m?(0,$.jsxs)(`div`,{className:`w-full h-full flex flex-col gap-3`,children:[g&&(0,$.jsxs)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,$.jsx)(j,{className:`w-4 h-4`}),`Plates`,l&&(0,$.jsx)(H,{className:`w-3 h-3 animate-spin`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(null),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${d==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,$.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,$.jsx)(j,{className:`w-5 h-5 text-bambu-gray`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:`All Plates`}),(0,$.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[s.length,` plate`,s.length===1?``:`s`]})]}),d==null&&(0,$.jsx)(xn,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]}),s.map(n=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(n.index),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${d===n.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[n.has_thumbnail?(0,$.jsx)(`img`,{src:i.getPrinterFilePlateThumbnail(e,n.index,t),alt:`Plate ${n.index}`,className:`w-10 h-10 rounded object-cover bg-bambu-dark-tertiary`}):(0,$.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,$.jsx)(j,{className:`w-5 h-5 text-bambu-gray`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:n.name||`Plate ${n.index}`}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:n.objects.length>0?n.objects.slice(0,2).join(`, `)+(n.objects.length>2?`…`:``):`${n.filaments.length} filament${n.filaments.length===1?``:`s`}`})]}),d===n.index&&(0,$.jsx)(xn,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]},n.index))]}),_&&(0,$.jsxs)(`div`,{className:`mt-3 text-xs text-bambu-gray flex flex-wrap gap-x-4 gap-y-1`,children:[(0,$.jsxs)(`span`,{children:[`Plate `,_.index]}),_.print_time_seconds!=null&&(0,$.jsxs)(`span`,{children:[`ETA `,Math.round(_.print_time_seconds/60),` min`]}),_.filament_used_grams!=null&&(0,$.jsxs)(`span`,{children:[_.filament_used_grams.toFixed(1),` g`]}),_.filaments.length>0&&(0,$.jsxs)(`span`,{children:[_.filaments.length,` filament`,_.filaments.length===1?``:`s`]})]})]}),(0,$.jsx)(`div`,{className:`flex-1`,children:(0,$.jsx)(dr,{url:i.getPrinterFileDownloadUrl(e,t),fileType:p,selectedPlateId:d,className:`w-full h-full`})})]}):a===`gcode`&&h?(0,$.jsx)(ae,{gcodeUrl:i.getPrinterFileGcodeUrl(e,t),className:`w-full h-full`}):(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:`No preview available for this file`})})]})})}function Ri(e){if(e===0)return`0 GB`;let t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function zi(e,t){if(t)return Fn;switch(e.toLowerCase().split(`.`).pop()||``){case`3mf`:return ie;case`gcode`:return or;case`mp4`:case`avi`:return se;case`png`:case`jpg`:case`jpeg`:return tr;default:return V}}var Bi=[{value:`name-asc`,label:`Name (A-Z)`},{value:`name-desc`,label:`Name (Z-A)`},{value:`size-asc`,label:`Size (smallest)`},{value:`size-desc`,label:`Size (largest)`},{value:`date-asc`,label:`Date (oldest)`},{value:`date-desc`,label:`Date (newest)`}];function Vi({printerId:e,printerName:t,onClose:n}){let{t:r}=l(),{showToast:a}=te(),o=f(),[s,c]=(0,X.useState)(`/`),[u,d]=(0,X.useState)(new Set),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)([]),[y,b]=(0,X.useState)(`name-asc`),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),E=(0,X.useRef)(null),D=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:O,isLoading:k,refetch:A}=p({queryKey:[`printerFiles`,e,s],queryFn:()=>i.getPrinterFiles(e,s)}),{data:M}=p({queryKey:[`printerStorage`,e],queryFn:()=>i.getPrinterStorage(e),staleTime:3e4}),N=(0,X.useMemo)(()=>[...O?.files??[]].filter(e=>!h||e.name.toLowerCase().includes(h.toLowerCase())).sort((e,t)=>{if(e.is_directory&&!t.is_directory)return-1;if(!e.is_directory&&t.is_directory)return 1;switch(y){case`name-asc`:return e.name.localeCompare(t.name);case`name-desc`:return t.name.localeCompare(e.name);case`size-asc`:return e.size-t.size;case`size-desc`:return t.size-e.size;case`date-asc`:return(e.mtime?qt(e.mtime)?.getTime()??0:0)-(t.mtime?qt(t.mtime)?.getTime()??0:0);case`date-desc`:{let n=e.mtime?qt(e.mtime)?.getTime()??0:0;return(t.mtime?qt(t.mtime)?.getTime()??0:0)-n}default:return e.name.localeCompare(t.name)}}),[O?.files,h,y]),P=!!O&&!O.warnings?.includes(`printer_unavailable`);(0,X.useEffect)(()=>{if(!P)return;let e=new Set(N.filter(e=>!e.is_directory).map(e=>e.path));d(t=>new Set([...t].filter(t=>e.has(t)))),E.current&&!e.has(E.current)&&(E.current=null)},[N,P]),(0,X.useEffect)(()=>()=>D.current?.abort(),[]);let F=m({mutationFn:async t=>{for(let n of t)await i.deletePrinterFile(e,n)},onSuccess:()=>{a(r(`printerFiles.toast.filesDeleted`,{count:_.length})),o.invalidateQueries({queryKey:[`printerFiles`,e]}),d(new Set),E.current=null,v([])},onError:e=>{a(r(`printerFiles.toast.deleteFailed`,{error:e.message}),`error`)}}),I=e=>{c(e),d(new Set),E.current=null},L=()=>{if(s===`/`)return;let e=s.split(`/`).filter(Boolean);e.pop(),c(e.length?`/`+e.join(`/`):`/`),d(new Set),E.current=null},R=(e,t)=>{t.stopPropagation();let n=N.filter(e=>!e.is_directory).map(e=>e.path),r=E.current?n.indexOf(E.current):-1,i=n.indexOf(e),a=t.shiftKey&&r!==-1&&i!==-1;a||(E.current=e),d(t=>{let o=new Set(t);if(a){let e=Math.min(r,i),t=Math.max(r,i);n.slice(e,t+1).forEach(e=>o.add(e))}else o.has(e)?o.delete(e):o.add(e);return o})};return(0,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,$.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(fe,{className:`w-5 h-5 text-bambu-green`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`printerFiles.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[M&&(M.used_bytes!=null||M.free_bytes!=null)&&(0,$.jsxs)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-2`,children:[M.used_bytes!=null&&(0,$.jsxs)(`span`,{children:[r(`printerFiles.storageUsed`),` `,Ri(M.used_bytes)]}),M.used_bytes!=null&&M.free_bytes!=null&&(0,$.jsx)(`span`,{className:`text-bambu-dark-tertiary`,children:`|`}),M.free_bytes!=null&&(0,$.jsxs)(`span`,{children:[r(`printerFiles.storageFree`),` `,Ri(M.free_bytes)]})]}),(0,$.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:`Close file manager`,"aria-label":`Close file manager`,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[[{path:`/`,label:`Root`},{path:`/cache`,label:`Cache`},{path:`/model`,label:`Models`},{path:`/timelapse`,label:`Timelapse`}].map(e=>(0,$.jsx)(`button`,{onClick:()=>{I(e.path),g(``)},className:`px-3 py-1 text-sm rounded-full transition-colors ${s===e.path?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:e.label},e.path)),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Ae,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,placeholder:r(`printerFiles.filterPlaceholder`),value:h,onChange:e=>g(e.target.value),className:`w-40 pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,$.jsxs)(`div`,{className:`relative flex items-center gap-1`,children:[(0,$.jsx)(T,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`select`,{value:y,onChange:e=>b(e.target.value),className:`appearance-none bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm py-1.5 pl-2 pr-6 focus:border-bambu-green focus:outline-none cursor-pointer`,title:`Sort files`,"aria-label":`Sort files`,children:Bi.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:()=>A(),disabled:k,"aria-label":r(`common.refresh`),title:r(`common.refresh`),children:(0,$.jsx)(dn,{className:`w-4 h-4 ${k?`animate-spin`:``}`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark text-sm flex-shrink-0`,children:[(0,$.jsx)(`button`,{onClick:L,disabled:s===`/`,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed`,title:`Go to parent folder`,"aria-label":`Go to parent folder`,children:(0,$.jsx)(Yn,{className:`w-4 h-4`})}),(0,$.jsx)(`span`,{className:`text-bambu-gray font-mono`,children:s})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:k?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,$.jsx)(H,{className:`w-8 h-8 text-bambu-green animate-spin`})}):O?.warnings?.includes(`printer_unavailable`)?(0,$.jsx)(`div`,{className:`text-center py-12 text-amber-600 dark:text-amber-400`,children:r(`printerFiles.printerUnavailable`)}):O?.files?.length?(0,$.jsx)(`div`,{className:`space-y-1`,children:N.map(e=>{let t=zi(e.name,e.is_directory),n=u.has(e.path);return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg cursor-pointer transition-colors ${n?`bg-bambu-green/20 border border-bambu-green/50`:`hover:bg-bambu-dark-tertiary`}`,onClick:t=>{e.is_directory?I(e.path):R(e.path,t)},children:[e.is_directory?null:(0,$.jsx)(`button`,{onClick:t=>R(e.path,t),className:`flex-shrink-0 text-bambu-gray hover:text-white`,"aria-label":r(n?`printerFiles.deselectFile`:`printerFiles.selectFile`,{name:e.name}),title:r(`printerFiles.shiftSelectHint`),children:n?(0,$.jsx)(xn,{className:`w-5 h-5 text-bambu-green`}):(0,$.jsx)(fn,{className:`w-5 h-5`})}),(0,$.jsx)(t,{className:`w-5 h-5 flex-shrink-0 ${e.is_directory?`text-bambu-green`:`text-bambu-gray`}`}),(0,$.jsx)(`span`,{className:`flex-1 text-white truncate`,children:e.name}),!e.is_directory&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:zt(e.size)}),(e.name.toLowerCase().endsWith(`.3mf`)||e.name.toLowerCase().endsWith(`.gcode`)||e.name.toLowerCase().endsWith(`.stl`))&&(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),w({path:e.path,name:e.name})},className:`p-1 rounded hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`,title:`3D View`,children:(0,$.jsx)(j,{className:`w-4 h-4`})})]}),e.is_directory&&(0,$.jsx)(Yn,{className:`w-4 h-4 text-bambu-gray rotate-180`})]},e.path)})}):(0,$.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`printerFiles.noFiles`)})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:u.size>0?`${u.size} selected`:h?`${O?.files?.filter(e=>e.name.toLowerCase().includes(h.toLowerCase())).length||0} of ${O?.files?.length||0} items`:`${O?.files?.length||0} items`}),O?.files?.some(e=>!e.is_directory)&&(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:u.size>0?(0,$.jsxs)(`button`,{onClick:()=>{d(new Set),E.current=null},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(Mr,{className:`w-4 h-4`}),`Deselect All`]}):(0,$.jsxs)(`button`,{onClick:()=>{let e=N.filter(e=>!e.is_directory).map(e=>e.path);d(new Set(e)),E.current=null},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(xn,{className:`w-4 h-4`}),`Select All`]})})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Y,{variant:`secondary`,disabled:u.size===0||x!==null,onClick:async()=>{if(u.size===0)return;let n=N.filter(e=>!e.is_directory&&u.has(e.path)).map(e=>e.path);if(n.length===0)return;let o=new AbortController;D.current=o,S({current:0,total:n.length});try{let s=Object.fromEntries(n.map(e=>[e,O?.files.find(t=>t.path===e)?.size??0])),c=await i.downloadPrinterFilesAsZip(e,n,s,n.length===1?O?.files.find(e=>e.path===n[0])?.name??`printer-file`:`${t.replace(/[^a-zA-Z0-9]/g,`_`)}-files.zip`,n.length>1,o.signal,(e,t)=>S({current:e,total:t}));c.failed>0?a(r(`printerFiles.zipPartial`,{successful:c.successful,total:c.requested}),`warning`):a(r(`printerFiles.zipStarted`,{count:c.successful})),d(new Set),E.current=null}catch(e){a(r(`printerFiles.downloadFailed`,{error:e instanceof Error?e.message:r(`printerFiles.unknownError`)}),`error`)}finally{D.current===o&&(D.current=null),S(null)}},children:x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{className:`w-4 h-4 animate-spin`}),x.current,`/`,x.total]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ar,{className:`w-4 h-4`}),`Download`,u.size>1?` (${u.size})`:``]})}),(0,$.jsxs)(Y,{variant:`secondary`,disabled:u.size===0||F.isPending,onClick:()=>{u.size!==0&&v(N.filter(e=>!e.is_directory&&u.has(e.path)).map(e=>e.path))},className:`text-red-700 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300`,children:[F.isPending?(0,$.jsx)(H,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(Qt,{className:`w-4 h-4`}),r(`printerFiles.deleteButton`),u.size>1?` (${u.size})`:``]})]})]})]}),_.length>0&&(0,$.jsx)(In,{title:_.length>1?r(`printerFiles.deleteFiles`,{count:_.length}):r(`fileManager.deleteFile`),message:_.length>1?r(`printerFiles.deleteFilesConfirm`,{count:_.length}):r(`printerFiles.deleteFileConfirm`,{name:_[0].split(`/`).pop()}),confirmText:r(`common.delete`),variant:`danger`,onConfirm:()=>{F.mutate(_)},onCancel:()=>v([])}),C&&(0,$.jsx)(Li,{printerId:e,filePath:C.path,filename:C.name,onClose:()=>w(null)})]})}var Hi=`embeddedCameraState_`,Ui=5,Wi=2e3,Gi=3e4,Ki=5e3,qi={x:window.innerWidth-420,y:20,width:400,height:300};function Ji({printerId:e,printerName:t,viewerIndex:n=0,onClose:a}){let{t:s}=l(),c=f(),{showToast:u}=te(),{hasPermission:d}=lr(),h=`${Hi}${e}`,[g,_]=(0,X.useState)(()=>{try{let e=localStorage.getItem(h);if(e){let t=JSON.parse(e);return{x:Math.min(Math.max(0,t.x),window.innerWidth-100),y:Math.min(Math.max(0,t.y),window.innerHeight-100),width:Math.max(200,Math.min(t.width,window.innerWidth-20)),height:Math.max(150,Math.min(t.height,window.innerHeight-20))}}}catch{}let e=n*30;return{...qi,x:Math.max(0,qi.x-e),y:Math.max(0,qi.y+e)}}),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)({x:0,y:0}),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(1),[A,j]=(0,X.useState)({x:0,y:0}),[M,N]=(0,X.useState)(!1),[P,F]=(0,X.useState)({x:0,y:0}),[I,L]=(0,X.useState)(null),[R,ee]=(0,X.useState)(null),[ne,z]=(0,X.useState)(!1),[re,B]=(0,X.useState)(!0),[ie,ae]=(0,X.useState)(Date.now()),[V,oe]=(0,X.useState)(0),[se,ce]=(0,X.useState)(!1),[le,ue]=(0,X.useState)(0),fe=(0,X.useRef)(null),pe=(0,X.useRef)(null),H=(0,X.useRef)(null),me=(0,X.useRef)(null),G=(0,X.useRef)(null),[be,xe]=(0,X.useState)(!1),[Se,K]=(0,X.useState)(!1),{data:Ce}=p({queryKey:[`printer`,e],queryFn:()=>i.getPrinter(e),enabled:e>0}),{data:we}=p({queryKey:[`printerStatus`,e],queryFn:()=>i.getPrinterStatus(e),refetchInterval:3e4,enabled:e>0}),Te=m({mutationFn:t=>i.setChamberLight(e,t),onMutate:async t=>{await c.cancelQueries({queryKey:[`printerStatus`,e]});let n=c.getQueryData([`printerStatus`,e]);return c.setQueryData([`printerStatus`,e],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{u(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&c.setQueryData([`printerStatus`,e],r.previousStatus),u(t.message||s(`printers.toast.failedToControlChamberLight`),`error`)}}),q=(we?.state===`RUNNING`||we?.state===`PAUSE`)&&(we?.printable_objects_count??0)>=2;(0,X.useEffect)(()=>{let e=setTimeout(()=>{localStorage.setItem(h,JSON.stringify(g))},500);return()=>clearTimeout(e)},[g,h]);let J=(0,X.useRef)(!1);(0,X.useEffect)(()=>{J.current=!1;let t=`/api/v1/printers/${e}/camera/stop`,n=()=>{if(e>0&&!J.current){J.current=!0;let e={},n=o();n&&(e.Authorization=`Bearer ${n}`),fetch(t,{method:`POST`,keepalive:!0,headers:e}).catch(()=>{})}},r=pe.current;return()=>{r&&(r.src=``),n(),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current),G.current&&clearInterval(G.current)}},[e]),(0,X.useEffect)(()=>{if(re){let e=setTimeout(()=>B(!1),3e3);return()=>clearTimeout(e)}},[re,ie]);let Ee=(0,X.useCallback)(()=>{if(V>=Ui){ce(!1),z(!0);return}let e=Math.min(Wi*2**V,Gi);ce(!0),ue(Math.ceil(e/1e3)),me.current=setInterval(()=>{ue(e=>e<=1?(me.current&&clearInterval(me.current),0):e-1)},1e3),H.current=setTimeout(()=>{oe(e=>e+1),ce(!1),B(!0),z(!1),pe.current&&(pe.current.src=``),ae(Date.now())},e)},[V]);(0,X.useEffect)(()=>{if(re||se||w){G.current&&=(clearInterval(G.current),null);return}return G.current=setInterval(async()=>{try{let t=await i.getCameraStatus(e);(t.stalled||!t.active&&!ne)&&(G.current&&=(clearInterval(G.current),null),B(!1),Ee())}catch{}},Ki),()=>{G.current&&=(clearInterval(G.current),null)}},[re,ne,se,w,e,Ee]),(0,X.useEffect)(()=>{let e=()=>{let e=!!document.fullscreenElement;D(e),e||(k(1),j({x:0,y:0}))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let De=()=>{fe.current&&(document.fullscreenElement?document.exitFullscreen():fe.current.requestFullscreen())},Oe=()=>{k(e=>Math.min(e+.5,4))},ke=()=>{k(e=>{let t=Math.max(e-.5,1);return t===1&&j({x:0,y:0}),t})},Ae=e=>{e.preventDefault(),e.deltaY<0?Oe():ke()},je=e=>{O>1&&(e.preventDefault(),N(!0),F({x:e.clientX-A.x,y:e.clientY-A.y}))},Me=(0,X.useCallback)(()=>{if(!fe.current||!pe.current)return{x:200,y:150};let e=fe.current.getBoundingClientRect(),t=e.width*(O-1)/2,n=e.height*(O-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[O]),Ne=e=>{if(M&&O>1){let t=e.clientX-P.x,n=e.clientY-P.y,r=Me();j({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Pe=()=>{N(!1)},Fe=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Ie=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},Le=e=>{e.touches.length===2?(e.preventDefault(),L(Fe(e.touches)),ee(Ie(e.touches))):e.touches.length===1&&O>1&&(e.preventDefault(),N(!0),F({x:e.touches[0].clientX-A.x,y:e.touches[0].clientY-A.y}))},Re=e=>{if(e.touches.length===2&&I!==null){e.preventDefault();let t=Fe(e.touches),n=t/I;k(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&j({x:0,y:0}),t}),L(t);let r=Ie(e.touches);if(R){let e=Me();j(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-R.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-R.y)))}))}ee(r)}else if(e.touches.length===1&&M&&O>1){e.preventDefault();let t=e.touches[0].clientX-P.x,n=e.touches[0].clientY-P.y,r=Me();j({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},ze=e=>{e.touches.length<2&&(L(null),ee(null)),e.touches.length===0&&N(!1)},Be=()=>{k(1),j({x:0,y:0})},Ve=()=>{B(!1),V{B(!1),z(!1),oe(0),ce(!1),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current)},Ue=()=>{B(!0),z(!1),oe(0),ce(!1),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current);let t={},n=o();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,headers:t}).catch(()=>{}),pe.current&&(pe.current.src=``),setTimeout(()=>ae(Date.now()),100)},We=e=>{e.target.closest(`.no-drag`)||(y(!0),C({x:e.clientX-g.x,y:e.clientY-g.y}))},Ge=e=>{if(e.target.closest(`.no-drag`))return;let t=e.touches[0];y(!0),C({x:t.clientX-g.x,y:t.clientY-g.y})},Ke=e=>{e.stopPropagation(),x(!0)},qe=e=>{e.stopPropagation(),x(!0)};(0,X.useEffect)(()=>{let e=e=>{if(v)_(t=>({...t,x:Math.max(0,Math.min(e.clientX-S.x,window.innerWidth-t.width)),y:Math.max(0,Math.min(e.clientY-S.y,window.innerHeight-t.height))}));else if(b&&fe.current){let t=fe.current.getBoundingClientRect();_(n=>({...n,width:Math.max(200,Math.min(e.clientX-t.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(e.clientY-t.top,window.innerHeight-n.y-10))}))}},t=e=>{if(!v&&!b)return;e.preventDefault();let t=e.touches[0];if(v)_(e=>({...e,x:Math.max(0,Math.min(t.clientX-S.x,window.innerWidth-e.width)),y:Math.max(0,Math.min(t.clientY-S.y,window.innerHeight-e.height))}));else if(b&&fe.current){let e=fe.current.getBoundingClientRect();_(n=>({...n,width:Math.max(200,Math.min(t.clientX-e.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(t.clientY-e.top,window.innerHeight-n.y-10))}))}},n=()=>{y(!1),x(!1)};if(v||b)return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,n),document.addEventListener(`touchmove`,t,{passive:!1}),document.addEventListener(`touchend`,n),document.addEventListener(`touchcancel`,n),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,n),document.removeEventListener(`touchmove`,t),document.removeEventListener(`touchend`,n),document.removeEventListener(`touchcancel`,n)}},[v,b,S]);let Je=r(`/api/v1/printers/${e}/camera/stream?fps=15&t=${ie}`);return(0,$.jsxs)(`div`,{ref:fe,className:`${E?`fixed inset-0 z-[100]`:`fixed z-40 rounded-lg shadow-2xl border border-bambu-dark-tertiary`} bg-bambu-dark-secondary overflow-hidden`,style:E?void 0:{left:g.x,top:g.y,width:w?200:g.width,height:w?40:g.height,cursor:v?`grabbing`:`default`},children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-bambu-dark border-b border-bambu-dark-tertiary cursor-grab active:cursor-grabbing`,onMouseDown:We,onTouchStart:Ge,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-white truncate`,children:[(0,$.jsx)(de,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:Ce?.name||t})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 no-drag`,children:[(0,$.jsx)(`button`,{onClick:()=>Te.mutate(!we?.chamber_light),disabled:!we?.connected||Te.isPending||!d(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${we?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:d(`printers:control`)?s(`camera.chamberLight`):s(`printers.permission.noControl`),children:(0,$.jsx)(_e,{on:we?.chamber_light??!1,className:`w-3.5 h-3.5`})}),(0,$.jsx)(`button`,{onClick:()=>xe(!0),disabled:!q||!d(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${q&&d(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:d(`printers:control`)?s(q?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):s(`printers.permission.noControl`),children:(0,$.jsx)(ve,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:Ue,disabled:re||se,className:`p-1 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:`Refresh stream`,children:(0,$.jsx)(dn,{className:`w-3.5 h-3.5 text-bambu-gray ${re?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:()=>K(!0),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:s(`camera.diagnose.button`),children:(0,$.jsx)(an,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:De,className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:E?`Exit fullscreen`:`Fullscreen`,children:E?(0,$.jsx)(ge,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,$.jsx)(wr,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:()=>T(!w),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:w?`Expand`:`Minimize`,children:w?(0,$.jsx)(he,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,$.jsx)(U,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:a,className:`p-1 hover:bg-red-500/20 rounded`,title:`Close`,children:(0,$.jsx)(Pt,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`})})]})]}),!w&&(0,$.jsxs)(`div`,{className:`relative w-full bg-black flex items-center justify-center overflow-hidden h-[calc(100%-40px)]`,onWheel:Ae,onMouseMove:Ne,onMouseUp:Pe,onMouseLeave:Pe,onTouchStart:Le,onTouchMove:Re,onTouchEnd:ze,style:{touchAction:`none`},children:[re&&!se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,$.jsx)(dn,{className:`w-6 h-6 text-bambu-gray animate-spin`})}),se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,$.jsxs)(`div`,{className:`text-center p-2`,children:[(0,$.jsx)(en,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,$.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Reconnecting in `,le,`s...`]})]})}),ne&&!se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,$.jsxs)(`div`,{className:`text-center p-2`,children:[(0,$.jsx)(Ot,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:s(`camera.unavailable`)}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,$.jsx)(`button`,{onClick:Ue,className:`px-2 py-1 text-xs bg-bambu-green text-white rounded hover:bg-bambu-green/80`,children:s(`camera.retry`)}),(0,$.jsx)(`button`,{onClick:()=>K(!0),className:`px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:s(`camera.diagnose.button`)})]})]})}),(0,$.jsx)(`img`,{ref:pe,src:Je,alt:`Camera stream`,className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${O}) translate(${A.x/O}px, ${A.y/O}px) rotate(${Ce?.camera_rotation||0}deg)`,...Ce?.camera_rotation===90||Ce?.camera_rotation===270?{maxWidth:`100%`,maxHeight:`100%`}:{},cursor:O>1?M?`grabbing`:`grab`:`default`},onError:Ve,onLoad:He,onMouseDown:je,draggable:!1},ie),(0,$.jsxs)(`div`,{className:`absolute bottom-2 left-2 flex items-center gap-1 bg-black/60 rounded px-1.5 py-1 no-drag`,children:[(0,$.jsx)(`button`,{onClick:ke,disabled:O<=1,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom out`,children:(0,$.jsx)(It,{className:`w-3.5 h-3.5 text-white`})}),(0,$.jsxs)(`button`,{onClick:Be,className:`px-1.5 py-0.5 text-xs text-white hover:bg-white/10 rounded min-w-[32px]`,title:`Reset zoom`,children:[Math.round(O*100),`%`]}),(0,$.jsx)(`button`,{onClick:Oe,disabled:O>=4,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom in`,children:(0,$.jsx)(Ft,{className:`w-3.5 h-3.5 text-white`})})]}),!E&&(0,$.jsx)(`div`,{className:`absolute bottom-0 right-0 w-6 h-6 cursor-se-resize no-drag hover:bg-white/10 rounded-tl transition-colors`,onMouseDown:Ke,onTouchStart:qe,title:`Drag to resize`,children:(0,$.jsx)(`svg`,{className:`w-6 h-6 text-bambu-gray/70 hover:text-bambu-gray`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,$.jsx)(`path`,{d:`M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22ZM22 14H20V12H22V14ZM18 18H16V16H18V18ZM14 22H12V20H14V22ZM22 10H20V8H22V10ZM18 14H16V12H18V14ZM14 18H12V16H14V18ZM10 22H8V20H10V22Z`})})})]}),(0,$.jsx)(ye,{printerId:e,isOpen:be,onClose:()=>xe(!1)}),Se&&(0,$.jsx)(W,{printerId:e,printerName:Ce?.name||null,onClose:()=>K(!1)})]})}function Yi({printerId:e,printerName:t,onClose:n}){let{t:r}=l(),a=f(),[o,s]=(0,X.useState)(!0),[c,u]=(0,X.useState)(new Set),[d,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(`all`),v=(0,X.useRef)(null),{data:y,isLoading:b,refetch:x}=p({queryKey:[`mqtt-logs`,e],queryFn:()=>i.getMQTTLogs(e),refetchInterval:1e3}),C=m({mutationFn:()=>i.enableMQTTLogging(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),w=m({mutationFn:()=>i.disableMQTTLogging(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),T=m({mutationFn:()=>i.clearMQTTLogs(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,X.useEffect)(()=>{o&&v.current&&(v.current.scrollTop=v.current.scrollHeight)},[y?.logs,o]);let D=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},O=e=>new Date(e).toLocaleTimeString(`en-US`,{hour12:!1,fractionalSecondDigits:3}),k=(e,t)=>{if(e==null)return``;let n=typeof e==`string`?JSON.parse(e):e,r=JSON.stringify(n,null,t?2:0);return!t&&r.length>100?r.substring(0,100)+`...`:r},A=y?.logging_enabled??!1,j=(0,X.useMemo)(()=>y?.logs??[],[y?.logs]),M=(0,X.useMemo)(()=>j.filter(e=>{if(g!==`all`&&e.direction!==g)return!1;if(d.trim()){let t=d.toLowerCase(),n=e.topic.toLowerCase().includes(t),r=JSON.stringify(e.payload).toLowerCase().includes(t);return n||r}return!0}),[j,d,g]);return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[85vh] flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`mqttDebug.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]}),(0,$.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[A?(0,$.jsxs)(Y,{size:`sm`,variant:`secondary`,onClick:()=>w.mutate(),disabled:w.isPending,children:[(0,$.jsx)(fn,{className:`w-4 h-4`}),r(`mqttDebug.stopLogging`)]}):(0,$.jsxs)(Y,{size:`sm`,onClick:()=>C.mutate(),disabled:C.isPending,children:[(0,$.jsx)(ke,{className:`w-4 h-4`}),r(`mqttDebug.startLogging`)]}),(0,$.jsxs)(Y,{size:`sm`,variant:`secondary`,onClick:()=>T.mutate(),disabled:T.isPending||j.length===0,children:[(0,$.jsx)(Qt,{className:`w-4 h-4`}),r(`mqttDebug.clearLog`)]}),(0,$.jsx)(Y,{size:`sm`,variant:`secondary`,onClick:()=>x(),disabled:b,children:(0,$.jsx)(dn,{className:`w-4 h-4 ${b?`animate-spin`:``}`})}),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,$.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[M.length,`/`,j.length]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(Ae,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,placeholder:r(`mqttDebug.searchPlaceholder`),value:d,onChange:e=>h(e.target.value),className:`w-full pl-8 pr-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),d&&(0,$.jsx)(`button`,{onClick:()=>h(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,$.jsx)(Pt,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded border border-bambu-dark-tertiary`,children:[(0,$.jsx)(`button`,{onClick:()=>_(`all`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${g===`all`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:r(`mqttDebug.all`)}),(0,$.jsxs)(`button`,{onClick:()=>_(`in`),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${g===`in`?`bg-blue-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,$.jsx)(S,{className:`w-3 h-3`}),r(`mqttDebug.incoming`)]}),(0,$.jsxs)(`button`,{onClick:()=>_(`out`),className:`px-2 py-1.5 text-xs rounded-r transition-colors flex items-center gap-1 ${g===`out`?`bg-green-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,$.jsx)(E,{className:`w-3 h-3`}),r(`mqttDebug.outgoing`)]})]})]})]}),(0,$.jsx)(`div`,{ref:v,className:`flex-1 overflow-auto p-4 font-mono text-xs bg-black min-h-[400px]`,children:j.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,$.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessages`)}),!A&&(0,$.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.startLoggingHint`)})]}):M.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,$.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessagesMatch`)}),(0,$.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.adjustFilterHint`)})]}):(0,$.jsx)(`div`,{className:`space-y-1`,children:M.map((e,t)=>{let n=c.has(t),i=e.direction===`in`;return(0,$.jsxs)(`div`,{className:`p-2 rounded cursor-pointer hover:bg-bambu-dark-secondary transition-colors ${n?`bg-bambu-dark-secondary`:``}`,onClick:()=>D(t),children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:O(e.timestamp)}),(0,$.jsx)(`span`,{className:`shrink-0 ${i?`text-blue-400`:`text-green-400`}`,title:r(i?`mqttDebug.incoming`:`mqttDebug.outgoing`),children:i?(0,$.jsx)(S,{className:`w-3 h-3`}):(0,$.jsx)(E,{className:`w-3 h-3`})}),(0,$.jsx)(`span`,{className:`text-purple-400 shrink-0`,children:e.topic})]}),n?(0,$.jsx)(`pre`,{className:`mt-2 p-3 bg-gray-900 border border-gray-700 rounded text-green-400 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto text-xs`,children:k(e.payload,!0)}):(0,$.jsx)(`pre`,{className:`mt-1 text-white/80 truncate`,children:k(e.payload,!1)})]},t)})})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:[(0,$.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:A?(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),r(`mqttDebug.loggingActive`)]}):(0,$.jsx)(`span`,{children:r(`mqttDebug.loggingStopped`)})}),(0,$.jsx)(Y,{variant:`secondary`,onClick:n,children:r(`common.close`)})]})]})})}function Xi(e){if(!e)return`idle`;switch(e.class){case`failure`:case`warning`:case`safe`:case`error`:return e.class;default:return`unknown`}}function Zi(e){return e===`failure`||e===`warning`||e===`safe`}function Qi({printerName:e,detection:t,lastError:n,onClose:r}){let{t:i}=l(),a=Tn();(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let o=Xi(t),s=o===`failure`?`text-status-error`:o===`warning`?`text-status-warning`:o===`safe`?`text-status-ok`:o===`error`?`text-amber-600 dark:text-amber-400`:`text-bambu-gray`,c=t?.error??n;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg shadow-xl max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(K,{className:`w-5 h-5 text-bambu-green`}),(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`printers.aiDetection.modalTitle`,{name:e})})]}),(0,$.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,"aria-label":i(`common.close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4 text-sm`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.currentStatus`)}),(0,$.jsx)(`span`,{className:`font-medium ${s}`,children:i(`printers.aiDetection.${o}`)})]}),t&&Zi(o)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.score`)}),(0,$.jsx)(`span`,{className:`text-white font-mono`,children:t.score.toFixed(3)})]}),(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.framesAnalyzed`)}),(0,$.jsx)(`span`,{className:`text-white font-mono`,children:t.frame_count})]})]}),o===`error`&&(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.errorHint`)}),!t&&(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.idleHint`)})]}),c&&(0,$.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:[(0,$.jsx)(R,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-red-700 dark:text-red-400`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`font-medium text-red-700 dark:text-red-400`,children:i(`printers.aiDetection.lastError`)}),(0,$.jsx)(`p`,{className:`text-red-700/80 dark:text-red-300/80 break-words mt-1`,children:c})]})]})]}),(0,$.jsx)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex items-center justify-end`,children:(0,$.jsxs)(`button`,{onClick:()=>a(`/settings?tab=failure-detection`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(En,{className:`w-4 h-4`}),i(`printers.aiDetection.openSettings`)]})})]})})}function $i({printerId:e,printerModel:t,loadedFilamentTypes:n,loadedFilaments:r,loadedVariants:a,variant:o=`card`}){let{t:s}=l(),{data:c}=p({queryKey:[`queue`,e,`pending`,t],queryFn:()=>i.getQueue(e,`pending`,t||void 0),refetchInterval:3e4}),u=c?nn(c,n,r,a):void 0,d=u?.length||0;if(d===0)return null;let f=u?.[0];return(0,$.jsx)(bn,{to:`/queue`,className:o===`panelExtension`?`block mt-2 border-t border-bambu-dark-tertiary pt-2 pl-1 hover:opacity-90 transition-opacity`:`block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,$.jsx)(P,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:s(`queue.nextInQueue`)}),(0,$.jsx)(`p`,{className:`text-sm text-white truncate`,children:f?_r(f):``})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[(0,$.jsx)(vn,{className:`w-3 h-3`}),f?.scheduled_time?Kt(f.scheduled_time,`system`,s):s(`time.waiting`)]}),d>1&&(0,$.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-400/20 text-yellow-700 dark:text-yellow-400 rounded`,children:[`+`,d-1]}),(0,$.jsx)(pn,{className:`w-4 h-4 text-bambu-gray`})]})]})})}function ea({printerId:e}){let{t}=l(),{data:n}=p({queryKey:[`haSensorReadings`,e],queryFn:()=>i.getHASensorReadings(e),refetchInterval:15e3});if(!n?.length)return null;let r=e=>v(e,t);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,$.jsx)(ue,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t(`haSensors.label`)}),(0,$.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>{let n=b(e),i=!e.reachable||e.state===null;return(0,$.jsxs)(`span`,{title:e.block_print?t(`haSensors.blocksPrints`,{entity:e.entity_id}):e.entity_id,className:`px-2 py-0.5 text-xs rounded flex items-center gap-1 ${i?`bg-bambu-dark-tertiary/50 text-bambu-gray`:e.alerting?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,$.jsx)(n,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),(0,$.jsx)(`span`,{children:e.name}),(0,$.jsx)(`span`,{className:`font-medium`,children:r(e)})]},e.id)})})]})}var ta=[{value:`6h`,label:`6h`,hours:6},{value:`24h`,label:`24h`,hours:24},{value:`48h`,label:`48h`,hours:48},{value:`7d`,label:`7d`,hours:168}];function na({isOpen:e,onClose:t,printerId:n,printerName:r,amsId:a,amsLabel:o,initialMode:s=`humidity`,thresholds:c}){let{t:u}=l(),[d,f]=(0,X.useState)(`24h`),[m,h]=(0,X.useState)(s),{data:g}=p({queryKey:[`settings`],queryFn:i.getSettings}),v=g?.time_format||`system`;(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let b=ta.find(e=>e.value===d)?.hours||24,{data:x,isLoading:S,error:C}=p({queryKey:[`ams-history`,n,a,b],queryFn:()=>i.getAMSHistory(n,a,b),enabled:e,refetchInterval:6e4});if(!e)return null;let w=x?.data.map(e=>({time:(qt(e.recorded_at)||new Date).getTime(),humidity:e.humidity,temperature:e.temperature}))||[],T=Date.now()-b*60*60*1e3,E=Date.now(),D=[...w];if(D.length>0){let e=D[0];e.time>T&&D.unshift({...e,time:T});let t=D[D.length-1];t.time{let t=e.filter(e=>e!=null);if(t.length<4)return`stable`;let n=t.slice(0,Math.floor(t.length/4)),r=t.slice(-Math.floor(t.length/4)),i=n.reduce((e,t)=>e+t,0)/n.length,a=r.reduce((e,t)=>e+t,0)/r.length-i;return Math.abs(a)<2?`stable`:a>0?`up`:`down`},R=L(D.map(e=>e.humidity)),ee=L(D.map(e=>e.temperature)),te=({trend:e})=>e===`up`?(0,$.jsx)(_,{className:`w-4 h-4 text-red-600 dark:text-red-400`}):e===`down`?(0,$.jsx)(Ke,{className:`w-4 h-4 text-green-600 dark:text-green-400`}):(0,$.jsx)(G,{className:`w-4 h-4 text-gray-400 dark:text-bambu-gray`}),ne=e=>e==null?`#9ca3af`:e<=k?`#22a352`:e<=j?`#d4a017`:`#c62828`,z=e=>e==null?`#9ca3af`:e<=M?`#22a352`:e<=N?`#d4a017`:`#c62828`,re=`var(--bg-secondary)`,B=`var(--bg-primary)`,ie=`var(--border-color)`,ae=`var(--text-primary)`,V=`var(--text-secondary)`,oe=`var(--text-muted)`;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,onClick:t,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-4xl max-h-[90vh] overflow-hidden shadow-xl`,style:{backgroundColor:re},onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b`,style:{borderColor:ie},children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h2`,{className:`text-lg font-semibold`,style:{color:ae},children:[o,` `,u(`common.history`,`History`)]}),(0,$.jsx)(`p`,{className:`text-sm`,style:{color:V},children:r})]}),(0,$.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg transition-colors`,style:{color:V},children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`p-6 space-y-6 overflow-y-auto max-h-[calc(90vh-80px)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between max-[550px]:flex-col max-[550px]:items-start max-[550px]:gap-3`,children:[(0,$.jsxs)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:B},children:[(0,$.jsxs)(`button`,{onClick:()=>h(`humidity`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${m===`humidity`?`bg-blue-600 text-white`:``}`,style:m===`humidity`?void 0:{color:V},children:[(0,$.jsx)(y,{className:`w-4 h-4`}),u(`common.humidity`,`Humidity`)]}),(0,$.jsxs)(`button`,{onClick:()=>h(`temperature`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${m===`temperature`?`bg-orange-600 text-white`:``}`,style:m===`temperature`?void 0:{color:V},children:[(0,$.jsx)(Me,{className:`w-4 h-4`}),u(`common.temperature`,`Temperature`)]})]}),(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:B},children:ta.map(e=>(0,$.jsx)(`button`,{onClick:()=>f(e.value),className:`px-3 py-1 text-sm rounded-md transition-colors ${d===e.value?`bg-bambu-green text-white`:``}`,style:d===e.value?void 0:{color:V},children:e.label},e.value))})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-4 gap-4 max-[550px]:grid-cols-2`,children:m===`humidity`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-2`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ne(F)},children:F==null?`—`:`${F}%`}),(0,$.jsx)(te,{trend:R})]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-4`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ae},children:x?.avg_humidity==null?`—`:`${x.avg_humidity}%`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-1`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-green-500`,children:x?.min_humidity==null?`—`:`${x.min_humidity}%`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-3`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:x?.max_humidity==null?`—`:`${x.max_humidity}%`})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-2`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:z(I)},children:I==null?`—`:`${I}°C`}),(0,$.jsx)(te,{trend:ee})]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-4`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ae},children:x?.avg_temperature==null?`—`:`${x.avg_temperature}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-1`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-blue-500`,children:x?.min_temperature==null?`—`:`${x.min_temperature}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-3`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:x?.max_temperature==null?`—`:`${x.max_temperature}°C`})]})]})}),(0,$.jsx)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:B},children:S?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center`,style:{color:V},children:u(`common.loading`,`Loading...`)}):C?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center text-red-500`,children:u(`common.error`,`Error loading data`)}):D.length===0?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center`,style:{color:V},children:u(`common.noData`,`No data available for this time range`)}):(0,$.jsx)(Qe,{width:`100%`,height:300,children:(0,$.jsxs)(hi,{data:D,children:[(0,$.jsx)(gt,{strokeDasharray:`3 3`,stroke:ie}),(0,$.jsx)(rt,{dataKey:`time`,type:`number`,domain:[Date.now()-b*60*60*1e3,Date.now()],tickFormatter:e=>{let t=new Date(e);return b>24?t.toLocaleDateString([],{day:`numeric`,month:`short`}):t.toLocaleTimeString([],Gt({hour:`2-digit`,minute:`2-digit`},v))},stroke:oe,tick:{fontSize:12}}),(0,$.jsx)(vt,{stroke:oe,tick:{fontSize:12},domain:m===`humidity`?[0,100]:[`auto`,`auto`],tickFormatter:e=>m===`humidity`?`${e}%`:`${e}°C`}),(0,$.jsx)(Re,{contentStyle:{backgroundColor:re,border:`1px solid ${ie}`,borderRadius:`8px`,color:ae},labelFormatter:e=>new Date(e).toLocaleString(void 0,Gt({year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`},v)),formatter:e=>[m===`humidity`?`${e??0}%`:`${e??0}°C`,m===`humidity`?`Humidity`:`Temperature`]}),(0,$.jsx)(O,{}),m===`humidity`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{y:k,stroke:`#22a352`,strokeDasharray:`5 5`,label:{value:`Good`,fill:`#22a352`,fontSize:10}}),(0,$.jsx)(A,{y:j,stroke:`#d4a017`,strokeDasharray:`5 5`,label:{value:`Fair`,fill:`#d4a017`,fontSize:10}})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{y:M,stroke:`#22a352`,strokeDasharray:`5 5`,label:{value:`Good`,fill:`#22a352`,fontSize:10}}),(0,$.jsx)(A,{y:N,stroke:`#d4a017`,strokeDasharray:`5 5`,label:{value:`Fair`,fill:`#d4a017`,fontSize:10}})]}),(0,$.jsx)(pi,{type:`monotone`,dataKey:m,name:m===`humidity`?`Humidity`:`Temperature`,stroke:m===`humidity`?`#3b82f6`:`#f97316`,strokeWidth:2,dot:!1,activeDot:{r:4},connectNulls:!0})]})})}),(0,$.jsx)(`div`,{className:`text-xs text-center`,style:{color:V},children:u(`amsHistory.recordingInfo`,`Data is recorded every 5 minutes while the printer is connected`)})]})]})})}function ra(e,t,n){let r=n===1||e>=128,i=e>=128?e-128:e,a=String.fromCharCode(65+i);return r?`HT·${t+1}`:`${a}·${t+1}`}function ia(e){let t=(e||``).replace(`#`,``).slice(0,6);if(t.length!==6)return`#FFFFFF`;let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);return[n,r,i].some(Number.isNaN)?`#FFFFFF`:(.2126*n+.7152*r+.0722*i)/255>.55?`#1A1A1A`:`#FFFFFF`}function aa({group:e,trayCountByAms:t,innerBg:n,textPrimary:r,textSecondary:i,showExtruderBadge:a,extruderLabel:o}){let s=Mn(e.trayColor||void 0),c=ia(e.trayColor),l=c===`#FFFFFF`?`rgba(0,0,0,0.45)`:`rgba(255,255,255,0.7)`,u=e.members.length;return(0,$.jsxs)(`div`,{className:`relative flex flex-col items-center`,children:[a&&(0,$.jsx)(`span`,{className:`absolute -top-1 -left-1 z-10 w-6 h-6 rounded-full flex items-center justify-center text-xs font-bold shadow`,style:{backgroundColor:r,color:n},"aria-label":o,title:o,children:o}),(0,$.jsxs)(`svg`,{viewBox:`-100 -100 200 200`,className:`w-44 h-44`,children:[(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`95`,fill:`none`,stroke:i,strokeOpacity:`0.25`,strokeWidth:`1`}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`92`,fill:s}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`56`,fill:n}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`56`,fill:`none`,stroke:i,strokeOpacity:`0.3`,strokeWidth:`1`}),(0,$.jsx)(`text`,{x:`0`,y:`-4`,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`14`,fontWeight:`700`,fill:r,children:e.displayName||`—`}),(0,$.jsx)(`text`,{x:`0`,y:`16`,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`11`,fontWeight:`500`,fill:i,children:`${u}× ↻`}),e.members.map((e,n)=>{let r=(n*360/u-90)*Math.PI/180,i=76*Math.cos(r),a=76*Math.sin(r),o=ra(e.amsId,e.slotIdx,t.get(e.amsId)??4),s=Math.max(22,o.length*7+8);return(0,$.jsxs)(`g`,{children:[(0,$.jsx)(`rect`,{x:i-s/2,y:a-9,width:s,height:18,rx:9,ry:9,fill:l}),(0,$.jsx)(`text`,{x:i,y:a,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`12`,fontWeight:`700`,fill:c,children:o})]},`${e.amsId}-${e.slotIdx}`)})]})]})}function oa({isOpen:e,state:t,amsUnits:n,amsExtruderMap:r,isDualNozzle:i,canToggle:a,pending:o,onToggle:s,onClose:c}){let{t:u}=l();if((0,X.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&(e.stopPropagation(),c())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,c]),!e)return null;let d=`var(--bg-secondary)`,f=`var(--border-color)`,p=`var(--text-primary)`,m=`var(--text-secondary)`,h=(()=>{if(!i||!r)return!1;let e=new Set;for(let t of n||[]){let n=r[String(t.id)];if(n!==void 0&&(e.add(Number(n)),e.size>1))return!0}return!1})(),g=wn(n,r,h),_=new Map((n||[]).map(e=>[e.id,e.tray.length])),v=g.filter(e=>e.members.length>=2),y=t===!0,b=t===null;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:c,"data-testid":`ams-backup-modal`,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-2xl max-h-[90vh] overflow-hidden shadow-xl flex flex-col`,style:{backgroundColor:d},onClick:e=>e.stopPropagation(),role:`dialog`,"aria-modal":`true`,"aria-labelledby":`ams-backup-modal-title`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b`,style:{borderColor:f},children:[(0,$.jsx)(`h2`,{id:`ams-backup-modal-title`,className:`text-base font-semibold`,style:{color:p},children:u(`printers.amsBackup.modalTitle`)}),(0,$.jsx)(`button`,{type:`button`,onClick:c,className:`p-1 rounded-md transition-colors hover:bg-black/10`,style:{color:m},"aria-label":u(`common.close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b`,style:{borderColor:f,backgroundColor:`var(--bg-primary)`},children:[(0,$.jsxs)(`div`,{className:`min-w-0 mr-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium`,style:{color:p},children:u(b?`printers.amsBackup.stateUnknown`:y?`printers.amsBackup.stateOn`:`printers.amsBackup.stateOff`)}),(0,$.jsx)(`p`,{className:`text-xs mt-0.5`,style:{color:m},children:u(`printers.amsBackup.modalHelp`)})]}),(0,$.jsx)(hr,{checked:y,onChange:s,disabled:!a||b||o})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto px-5 py-6`,children:v.length===0?(0,$.jsx)(`p`,{className:`text-sm text-center py-8`,style:{color:m},children:u(`printers.amsBackup.modalNoPairs`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-6 justify-items-center`,children:v.map(e=>(0,$.jsx)(aa,{group:e,trayCountByAms:_,innerBg:d,textPrimary:p,textSecondary:m,showExtruderBadge:h,extruderLabel:e.extruder===0?u(`printers.amsBackup.extruderRightShort`):u(`printers.amsBackup.extruderLeftShort`)},e.key))})})]})})}var sa=[{value:`6h`,label:`6h`,hours:6},{value:`24h`,label:`24h`,hours:24},{value:`48h`,label:`48h`,hours:48},{value:`7d`,label:`7d`,hours:168}],ca={nozzle:`#fb923c`,nozzle_2:`#f97316`,bed:`#60a5fa`,chamber:`#34d399`},la={nozzle:`#fed7aa`,nozzle_2:`#fdba74`,bed:`#bfdbfe`,chamber:`#a7f3d0`};function ua({isOpen:e,onClose:t,printerId:n,printerName:r,initialKind:a=`nozzle`,availableKinds:o=[`nozzle`,`bed`,`chamber`]}){let{t:s}=l(),[c,u]=(0,X.useState)(`24h`),[d,f]=(0,X.useState)(a);(0,X.useEffect)(()=>{f(a)},[a]);let{data:m}=p({queryKey:[`settings`],queryFn:i.getSettings}),h=m?.time_format||`system`;(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let g=sa.find(e=>e.value===c)?.hours||24,{data:v,isLoading:y,error:b}=p({queryKey:[`printer-sensor-history`,n,g,o.join(`,`)],queryFn:()=>i.getPrinterSensorHistory(n,g,o),enabled:e,refetchInterval:6e4});if(!e)return null;let x=v?.series.find(e=>e.sensor_kind===d),S=(x?.data||[]).map(e=>({time:(qt(e.recorded_at)||new Date).getTime(),value:e.value,target:e.target})),C=Date.now()-g*60*60*1e3,w=Date.now(),T=[...S];if(T.length>0){let e=T[0];e.time>C&&T.unshift({...e,time:C});let t=T[T.length-1];t.time{let t=e.filter(e=>e!=null);if(t.length<4)return`stable`;let n=t.slice(0,Math.floor(t.length/4)),r=t.slice(-Math.floor(t.length/4)),i=n.reduce((e,t)=>e+t,0)/n.length,a=r.reduce((e,t)=>e+t,0)/r.length-i;return Math.abs(a)<2?`stable`:a>0?`up`:`down`})(T.map(e=>e.value)),M=({trend:e})=>e===`up`?(0,$.jsx)(_,{className:`w-4 h-4 text-red-600 dark:text-red-400`}):e===`down`?(0,$.jsx)(Ke,{className:`w-4 h-4 text-green-600 dark:text-green-400`}):(0,$.jsx)(G,{className:`w-4 h-4 text-gray-400 dark:text-bambu-gray`}),N=`var(--bg-secondary)`,P=`var(--bg-primary)`,F=`var(--border-color)`,I=`var(--text-primary)`,L=`var(--text-secondary)`,R=`var(--text-muted)`,ee=e=>{switch(e){case`nozzle`:return s(`printers.heaterHistory.nozzle`,`Nozzle`);case`nozzle_2`:return s(`printers.heaterHistory.nozzle2`,`Nozzle 2`);case`bed`:return s(`printers.heaterHistory.bed`,`Bed`);case`chamber`:return s(`printers.heaterHistory.chamber`,`Chamber`)}},te=({k:e})=>e===`nozzle`||e===`nozzle_2`?(0,$.jsx)(Bn,{className:`w-4 h-4`}):e===`bed`?(0,$.jsx)(fn,{className:`w-4 h-4`}):(0,$.jsx)(j,{className:`w-4 h-4`});return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,onClick:t,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-4xl max-h-[90vh] overflow-hidden shadow-xl`,style:{backgroundColor:N},onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b`,style:{borderColor:F},children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,style:{color:I},children:s(`printers.heaterHistory.title`,`Heater History`)}),(0,$.jsx)(`p`,{className:`text-sm`,style:{color:L},children:r})]}),(0,$.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg transition-colors`,style:{color:L},"aria-label":s(`common.close`,`Close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`p-6 space-y-6 overflow-y-auto max-h-[calc(90vh-80px)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between max-[550px]:flex-col max-[550px]:items-start max-[550px]:gap-3`,children:[(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:P},children:o.map(e=>(0,$.jsxs)(`button`,{onClick:()=>f(e),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${d===e?`text-white`:``}`,style:d===e?{backgroundColor:ca[e]}:{color:L},children:[(0,$.jsx)(te,{k:e}),ee(e)]},e))}),(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:P},children:sa.map(e=>(0,$.jsx)(`button`,{onClick:()=>u(e.value),className:`px-3 py-1 text-sm rounded-md transition-colors ${c===e.value?`bg-bambu-green text-white`:``}`,style:c===e.value?void 0:{color:L},children:e.label},e.value))})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-4 gap-4 max-[550px]:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ca[d]},children:D==null?`—`:`${Math.round(D)}°C`}),(0,$.jsx)(M,{trend:A})]}),k!=null&&k>0&&(0,$.jsxs)(`p`,{className:`text-xs mt-1`,style:{color:L},children:[s(`common.target`,`Target`),`: `,Math.round(k),`°C`]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.avg_value==null?`—`:`${x.avg_value}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.min_value==null?`—`:`${Math.round(x.min_value)}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.max_value==null?`—`:`${Math.round(x.max_value)}°C`})]})]}),(0,$.jsx)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:y?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center`,style:{color:L},children:s(`common.loading`,`Loading...`)}):b?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center text-red-700 dark:text-red-400`,children:s(`printers.heaterHistory.error`,`Failed to load history`)}):T.length===0?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center`,style:{color:L},children:s(`printers.heaterHistory.empty`,`No data recorded yet`)}):(0,$.jsx)(Qe,{width:`100%`,height:300,children:(0,$.jsxs)(hi,{data:T,margin:{top:5,right:10,left:0,bottom:5},children:[(0,$.jsx)(gt,{strokeDasharray:`3 3`,stroke:F}),(0,$.jsx)(rt,{dataKey:`time`,type:`number`,domain:[C,w],tickFormatter:e=>new Date(e).toLocaleTimeString([],Gt({hour:`2-digit`,minute:`2-digit`},h)),stroke:R,fontSize:11}),(0,$.jsx)(vt,{stroke:R,fontSize:11,domain:[0,`auto`],tickFormatter:e=>`${Math.round(e)}°`}),(0,$.jsx)(Re,{contentStyle:{backgroundColor:N,border:`1px solid ${F}`,borderRadius:6,color:I},labelFormatter:e=>new Date(e).toLocaleString(void 0,Gt({month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`},h)),formatter:e=>e==null?`—`:`${Math.round(Number(e))}°C`}),(0,$.jsx)(O,{}),(0,$.jsx)(pi,{type:`monotone`,dataKey:`value`,name:s(`common.current`,`Current`),stroke:ca[d],strokeWidth:2,dot:!1,isAnimationActive:!1}),(0,$.jsx)(pi,{type:`stepAfter`,dataKey:`target`,name:s(`common.target`,`Target`),stroke:la[d],strokeDasharray:`4 4`,strokeWidth:1.5,dot:!1,isAnimationActive:!1})]})})})]})]})})}function da({data:e,children:t,disabled:n,className:r=``,spoolman:i,inventory:a,configureSlot:o,actions:s}){let{t:c}=l(),u=Tn(),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(`top`),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),S=(0,X.useRef)(null),C=(0,X.useRef)(null),w=(0,X.useRef)(null),T=()=>{let t=e.trayUuid;t&&(navigator.clipboard&&window.isSecureContext?navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),2e3)}).catch(()=>{E(t)}):E(t))},E=e=>{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{document.execCommand(`copy`),v(!0),setTimeout(()=>v(!1),2e3)}catch{console.error(`Failed to copy to clipboard`)}document.body.removeChild(t)};(0,X.useLayoutEffect)(()=>{if(!d){g(null);return}let e=()=>{if(!S.current||!C.current)return;let e=S.current.getBoundingClientRect(),t=C.current.offsetHeight,n=C.current.offsetWidth,r=e.top-56,i=window.innerHeight-e.bottom,a=rr?`bottom`:`top`,o=e.left+e.width/2,s=Math.max(8,Math.min(o-n/2,window.innerWidth-n-8)),c=a===`top`?e.top-t-8:e.bottom+8;m(a),g({top:c,left:s})};e();let t=requestAnimationFrame(e);return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{cancelAnimationFrame(t),window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[d]);let D=()=>{n||(w.current&&clearTimeout(w.current),w.current=setTimeout(()=>f(!0),80))},O=()=>{w.current&&clearTimeout(w.current),w.current=setTimeout(()=>f(!1),100)},k=()=>{w.current&&clearTimeout(w.current),f(!1)};(0,X.useEffect)(()=>()=>{w.current&&clearTimeout(w.current)},[]);let A=e=>e<=15?`#ef4444`:e<=30?`#f97316`:e<=50?`#eab308`:`#22c55e`,j=e.colorHex?`#${e.colorHex.replace(`#`,``)}`:null,M=(a?.assignedSpool?.color_name_is_synthesized?void 0:qn(a?.assignedSpool?.color_name??null,null)?.trim())||e.colorName,N=a?.assignedSpool?qn(a.assignedSpool.color_name,a.assignedSpool.rgba??null,a.assignedSpool.color_name_is_synthesized):null,P=a?.assignedSpool?.remainingWeightGrams??null,I=a?.assignedSpool??null,L=Yt(I?.extra_colors),R=!!I?.effect_type,ee=!!I&&(L.length>0||R),te=ee?Jt({effectSize:`card`,rgba:I?.rgba??j,extraColors:I?.extra_colors,effectType:I?.effect_type,subtype:I?.subtype}):null,ne=L.length>1,re=ee?L.length===1?L[0]:I?.rgba??j:j;return(0,$.jsxs)(`div`,{ref:S,"data-testid":`filament-slot`,className:`relative ${r}`,onMouseEnter:D,onMouseLeave:O,children:[t,d&&(0,gi.createPortal)((0,$.jsxs)(`div`,{ref:C,className:`fixed z-[60]`,style:{top:h?.top??-9999,left:h?.left??-9999,maxWidth:`calc(100vw - 24px)`,visibility:h?`visible`:`hidden`},onMouseEnter:D,onMouseLeave:O,children:[(0,$.jsxs)(`div`,{className:`
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,c as a,l as o,s,t as c,w as l,x as u}from"./client-BdOyoZJz.js";import{t as d}from"./react-dom-xhkz5--P.js";import{n as f}from"./QueryClientProvider-Clbyr4Jg.js";import{t as p}from"./useQuery-CCy0EwsM.js";import{t as m}from"./useMutation-qh3Iyscy.js";import{t as h}from"./createLucideIcon-Yo2YoYjm.js";import{c as g,i as _,n as v,o as y,r as b,s as x}from"./haSensorDisplay-CSo8Nw_c.js";import{t as S}from"./arrow-down-C4OBNDqJ.js";import{t as C}from"./arrow-left-MSgMxOFV.js";import{t as w}from"./arrow-right-Da96kh4S.js";import{t as T}from"./arrow-up-down-C-1Kkt1x.js";import{t as E}from"./arrow-up-Dam8cLfE.js";import{i as D,n as O,r as k,t as A}from"./ReferenceLine-l3CI8D5f.js";import{t as j}from"./box-BIRPxdgi.js";import{n as M,t as N}from"./fan-DSlOeWAh.js";import{t as P}from"./calendar-DiVEdzUw.js";import{t as F}from"./check-D1Pn8T1J.js";import{a as I,n as L,r as R,t as ee}from"./info-DcT0QU8O.js";import{n as te,r as ne}from"./ToastContext-VFOrCCoA.js";import{t as z}from"./copy-3N5VKzXz.js";import{t as re}from"./ellipsis-vertical-So0E77JK.js";import{t as B}from"./eye-off-B6dY82pM.js";import{t as ie}from"./file-box-BjB1o93N.js";import{t as ae}from"./GcodeToolpathViewer-D4M17KI8.js";import{n as V,t as oe}from"./ContextMenu-BVYxDFvf.js";import{n as se,t as ce}from"./scan-search-LN9I03Ga.js";import{t as le}from"./funnel-BtI48m95.js";import{t as ue}from"./gauge-xO5PdXj0.js";import{t as de}from"./grip-vertical-D4urhrwn.js";import{t as fe}from"./hard-drive-CN9rq6Uq.js";import{t as pe}from"./layout-grid-D4S7CgZJ.js";import{t as H}from"./loader-circle-CB4leTZa.js";import{t as me}from"./log-in-D7NdqHOf.js";import{t as he}from"./maximize-2-Cggm3z8J.js";import{t as U}from"./minimize-2-BLq3FJZO.js";import{a as ge,i as _e,n as ve,r as ye,t as W}from"./CameraDiagnoseModal-Ckpf5A9U.js";import{t as G}from"./minus-D0aY9wbr.js";import{a as be,c as xe,i as Se,l as K,n as Ce,r as we,s as Te,t as q,u as J}from"./CopyButton-CyNT06yS.js";import{t as Ee}from"./move-CEngqF8v.js";import{t as De}from"./package-D9xR0eOt.js";import{t as Oe}from"./pause-CPKrVlsD.js";import{t as ke}from"./play-DROvjtg7.js";import{t as Ae}from"./search-BpAJdxRw.js";import{t as je}from"./settings-2-DYB5IzKV.js";import{n as Me,t as Ne}from"./wind-CsHQYbhI.js";import{D as Pe,Fn as Fe,It as Ie,Kt as Le,L as Re,Ln as ze,Lt as Be,M as Ve,Mn as He,On as Ue,Pn as We,R as Ge,Rn as Ke,S as qe,Sn as Je,St as Ye,T as Xe,Ut as Ze,Xt as Qe,Zt as $e,an as et,at as tt,b as nt,c as rt,cn as it,d as at,f as ot,gn as st,j as ct,jt as lt,k as ut,l as dt,ln as ft,mn as pt,mt,nn as ht,p as gt,pt as _t,s as vt,sn as yt,t as bt,u as xt,vn as St,w as Ct,wn as wt,x as Tt,y as Et,z as Dt}from"./CartesianChart-DcboTNtX.js";import{t as Ot}from"./triangle-alert-gIik0G2C.js";import{t as kt}from"./unlink-DJBJ04VB.js";import{i as At,n as jt,r as Mt,t as Nt}from"./CameraWall-BdatIGJs.js";import{t as Pt}from"./x-Dctff5l9.js";import{n as Ft,t as It}from"./zoom-out-C85W_TC5.js";import{n as Lt,t as Rt}from"./Card-OUAj0Ayh.js";import{t as zt}from"./file-DDkFXH-b.js";import{t as Y}from"./Button-pwVKPiYn.js";import{a as Bt,c as Vt,i as Ht,o as Ut,s as Wt,t as Gt,u as Kt,v as qt}from"./date-G9KUauqz.js";import{n as Jt,r as Yt}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$ as Xt,$t as Zt,At as Qt,Cn as $t,Ct as en,D as tn,E as nn,Et as rn,Ft as an,G as on,H as sn,J as cn,Jt as ln,K as un,Kt as dn,Lt as fn,Mn as pn,Mt as mn,N as hn,Nt as gn,O as _n,On as vn,Ot as yn,Rn as bn,Rt as xn,Sn,U as Cn,V as wn,Vn as Tn,Vt as En,W as Dn,Wt as On,X as kn,Y as An,Yt as jn,Z as Mn,Zt as Nn,_ as Pn,_n as Fn,_t as In,an as Ln,at as Rn,b as zn,bn as Bn,bt as Vn,cn as Hn,ct as Un,dt as Wn,et as Gn,fn as Kn,ft as qn,h as Jn,jn as Yn,jt as Xn,k as Zn,q as Qn,sn as $n,tt as er,un as tr,ut as nr,v as rr,vt as ir,wn as ar,xn as or,xt as sr,y as cr,yt as lr,z as ur}from"./index-ggB_TpPo.js";import{n as dr,t as fr}from"./FileUploadModal-DfKGV0qu.js";import{n as pr,t as mr}from"./ErrorBarContext-6wvnfk_q.js";import{t as hr}from"./Toggle-CwMiiK0g.js";import{t as gr}from"./printerModel-DrNvERGQ.js";import{t as _r}from"./queueItemName-UFY7kpjG.js";import{n as vr,r as yr,t as br}from"./ConfigureAmsSlotModal-DX4oXmzT.js";var xr=h(`air-vent`,[[`path`,{d:`M18 17.5a2.5 2.5 0 1 1-4 2.03V12`,key:`yd12zl`}],[`path`,{d:`M6 12H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`larmp2`}],[`path`,{d:`M6 8h12`,key:`6g4wlu`}],[`path`,{d:`M6.6 15.572A2 2 0 1 0 10 17v-5`,key:`1x1kqn`}]]),Sr=h(`chart-line`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`m19 9-5 5-4-4-3 3`,key:`2osh9i`}]]),Cr=h(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),wr=h(`fullscreen`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`rect`,{width:`10`,height:`8`,x:`7`,y:`8`,rx:`1`,key:`vys8me`}]]),Tr=h(`hourglass`,[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]),Er=h(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),Dr=h(`picture-in-picture-2`,[[`path`,{d:`M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4`,key:`daa4of`}],[`rect`,{width:`10`,height:`7`,x:`12`,y:`13`,rx:`2`,key:`1nb8gs`}]]),Or=h(`repeat`,[[`path`,{d:`m17 2 4 4-4 4`,key:`nntrym`}],[`path`,{d:`M3 11v-1a4 4 0 0 1 4-4h14`,key:`84bu3i`}],[`path`,{d:`m7 22-4-4 4-4`,key:`1wqhfi`}],[`path`,{d:`M21 13v1a4 4 0 0 1-4 4H3`,key:`1rx37r`}]]),kr=h(`signal`,[[`path`,{d:`M2 20h.01`,key:`4haj6o`}],[`path`,{d:`M7 20v-4`,key:`j294jx`}],[`path`,{d:`M12 20v-8`,key:`i3yub9`}],[`path`,{d:`M17 20V8`,key:`1tkaf5`}],[`path`,{d:`M22 4v16`,key:`sih9yq`}]]),Ar=h(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),jr=h(`snowflake`,[[`path`,{d:`m10 20-1.25-2.5L6 18`,key:`18frcb`}],[`path`,{d:`M10 4 8.75 6.5 6 6`,key:`7mghy3`}],[`path`,{d:`m14 20 1.25-2.5L18 18`,key:`1chtki`}],[`path`,{d:`m14 4 1.25 2.5L18 6`,key:`1b4wsy`}],[`path`,{d:`m17 21-3-6h-4`,key:`15hhxa`}],[`path`,{d:`m17 3-3 6 1.5 3`,key:`11697g`}],[`path`,{d:`M2 12h6.5L10 9`,key:`kv9z4n`}],[`path`,{d:`m20 10-1.5 2 1.5 2`,key:`1swlpi`}],[`path`,{d:`M22 12h-6.5L14 15`,key:`1mxi28`}],[`path`,{d:`m4 10 1.5 2L4 14`,key:`k9enpj`}],[`path`,{d:`m7 21 3-6-1.5-3`,key:`j8hb9u`}],[`path`,{d:`m7 3 3 6h4`,key:`1otusx`}]]),Mr=h(`square-minus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]]),Nr=(e,t,n,r)=>tt(e,`xAxis`,t,r),Pr=(e,t,n,r)=>_t(e,`xAxis`,t,r),Fr=(e,t,n,r)=>tt(e,`yAxis`,n,r),Ir=(e,t,n,r)=>_t(e,`yAxis`,n,r),Lr=pt([Ze,Nr,Fr,Pr,Ir],(e,t,n,r,i)=>ft(e,`xAxis`)?ht(t,r,!1):ht(n,i,!1)),Rr=(e,t,n,r,i)=>i;function zr(e){return e.type===`line`}var Br=pt([Ze,Nr,Fr,Pr,Ir,pt([mt,Rr],(e,t)=>e.filter(zr).find(e=>e.id===t)),Lr,lt],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=s;if(!(a==null||t==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null||e!==`horizontal`&&e!==`vertical`)){var{dataKey:d,data:f}=a,p=f!=null&&f.length>0?f:c?.slice(l,u+1);if(p!=null)return di({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataKey:d,bandSize:o,displayedData:p})}}),X=e(n()),Vr=[`id`],Hr=[`type`,`layout`,`connectNulls`,`needClip`,`shape`],Ur=[`activeDot`,`animateNewValues`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`hide`,`isAnimationActive`,`label`,`legendType`,`xAxisId`,`yAxisId`,`id`];function Wr(){return Wr=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var{dataKey:t,name:n,stroke:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:yt(n,t),payload:e}]},Qr=X.memo(e=>{var{dataKey:t,data:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,unit:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:n,getPosition:Ue,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:yt(o,t),hide:s,type:l,color:r,unit:c,graphicalItemId:u}};return X.createElement(Pe,{tooltipEntrySettings:d})}),$r=(e,t)=>`${t}px ${e-t}px`;function ei(e,t){for(var n=e.length%2==0?e:[...e,0],r=[],i=0;i{var r=n.reduce((e,t)=>e+t);if(!r)return $r(t,e);for(var i=Math.floor(e/r),a=e%r,o=t-e,s=[],c=0,l=0;ca){s=[...n.slice(0,c),a-l];break}}var f=s.length%2==0?[0,o]:[o];return[...ei(n,i),...s,...f].map(e=>`${e}px`).join(`, `)};function ni(e){var{clipPathId:t,points:n,props:r}=e,{dot:i,dataKey:a,needClip:o}=r,{id:s}=r,c=Fe(Yr(r,Vr));return X.createElement(Tt,{points:n,dot:i,className:`recharts-line-dots`,dotClassName:`recharts-line-dot`,dataKey:a,baseProps:c,needClip:o,clipPathId:t})}function Q(e){var{showLabels:t,children:n,points:r}=e,i=(0,X.useMemo)(()=>r?.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return Z(Z({},t),{},{value:e.value,payload:e.payload,viewBox:t,parentViewBox:void 0,fill:void 0})}),[r]);return X.createElement(ct,{value:t?i:void 0},n)}function ri(e){var{clipPathId:t,pathRef:n,points:r,strokeDasharray:i,props:a}=e,{type:o,layout:s,connectNulls:c,needClip:l,shape:u}=a,d=Z(Z({},We(Yr(a,Hr))),{},{fill:`none`,className:`recharts-line-curve`,clipPath:l?`url(#clipPath-${t})`:void 0,points:r,type:o,layout:s,connectNulls:c,strokeDasharray:i??a.strokeDasharray});return X.createElement(X.Fragment,null,r?.length>1&&X.createElement(pr,Wr({shapeType:`curve`,option:u},d,{pathRef:n})),X.createElement(ni,{points:r,clipPathId:t,props:a}))}function ii(e){try{return e&&e.getTotalLength&&e.getTotalLength()||0}catch{return 0}}function ai(e){var{clipPathId:t,props:n,pathRef:r,previousPointsRef:i,longestAnimatedLengthRef:a}=e,{points:o,strokeDasharray:s,isAnimationActive:c,animationBegin:l,animationDuration:u,animationEasing:d,animateNewValues:f,width:p,height:m,onAnimationEnd:h,onAnimationStart:g}=n,_=i.current,v=Ie(o,`recharts-line-`),y=(0,X.useRef)(v),[b,x]=(0,X.useState)(!1),S=!b,C=(0,X.useCallback)(()=>{typeof h==`function`&&h(),x(!1)},[h]),w=(0,X.useCallback)(()=>{typeof g==`function`&&g(),x(!0)},[g]),T=ii(r.current),E=(0,X.useRef)(0);y.current!==v&&(E.current=a.current,y.current=v);var D=E.current;return X.createElement(Q,{points:o,showLabels:S},n.children,X.createElement(Be,{animationId:v,begin:l,duration:u,isActive:c,easing:d,onAnimationEnd:C,onAnimationStart:w,key:v},e=>{var l=Je(D,T+D,e),u=Math.min(l,T),d=c?s?ti(u,T,`${s}`.split(/[,\s]+/gim).map(e=>parseFloat(e))):$r(T,u):s==null?void 0:String(s);if(e>0&&T>0&&(i.current=o,a.current=Math.max(a.current,u)),_){var h=_.length/o.length,g=e===1?o:o.map((t,n)=>{var r=Math.floor(n*h);if(_[r]){var i=_[r];return Z(Z({},t),{},{x:Je(i.x,t.x,e),y:Je(i.y,t.y,e)})}return f?Z(Z({},t),{},{x:Je(p*2,t.x,e),y:Je(m/2,t.y,e)}):Z(Z({},t),{},{x:t.x,y:t.y})});return i.current=g,X.createElement(ri,{props:n,points:g,clipPathId:t,pathRef:r,strokeDasharray:d})}return X.createElement(ri,{props:n,points:o,clipPathId:t,pathRef:r,strokeDasharray:d})}),X.createElement(Ve,{label:n.label}))}function oi(e){var{clipPathId:t,props:n}=e,r=(0,X.useRef)(null),i=(0,X.useRef)(0),a=(0,X.useRef)(null);return X.createElement(ai,{props:n,clipPathId:t,previousPointsRef:r,longestAnimatedLengthRef:i,pathRef:a})}var si=(e,t)=>({x:e.x??void 0,y:e.y??void 0,value:e.value,errorVal:it(e.payload,t)}),ci=class extends X.Component{render(){var{hide:e,dot:t,points:n,className:r,xAxisId:i,yAxisId:a,top:o,left:s,width:c,height:l,id:u,needClip:d,zIndex:f}=this.props;if(e)return null;var p=ze(`recharts-line`,r),m=u,{r:h,strokeWidth:g}=xt(t),_=ut(t),v=h*2+g,y=d?`url(#clipPath-${_?``:`dots-`}${m})`:void 0;return X.createElement(Dt,{zIndex:f},X.createElement(He,{className:p},d&&X.createElement(`defs`,null,X.createElement(at,{clipPathId:m,xAxisId:i,yAxisId:a}),!_&&X.createElement(`clipPath`,{id:`clipPath-dots-${m}`},X.createElement(`rect`,{x:s-v/2,y:o-v/2,width:c+v,height:l+v}))),X.createElement(mr,{xAxisId:i,yAxisId:a,data:n,dataPointFormatter:si,errorBarOffset:0},X.createElement(oi,{props:this.props,clipPathId:m}))),X.createElement(Et,{activeDot:this.props.activeDot,points:n,mainColor:this.props.stroke,itemDataKey:this.props.dataKey,clipPath:y}))}},li={activeDot:!0,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,connectNulls:!1,dot:!0,fill:`#fff`,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,xAxisId:0,yAxisId:0,zIndex:Ye.line,type:`linear`};function ui(e){var t=St(e,li),{activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,connectNulls:s,dot:c,hide:l,isAnimationActive:u,label:d,legendType:f,xAxisId:p,yAxisId:m,id:h}=t,g=Yr(t,Ur),{needClip:_}=ot(p,m),v=nt(),y=Le(),b=$e(),x=st(e=>Br(e,p,m,b,h));if(y!==`horizontal`&&y!==`vertical`||x==null||v==null)return null;var{height:S,width:C,x:w,y:T}=v;return X.createElement(ci,Wr({},g,{id:h,connectNulls:s,dot:c,activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,isAnimationActive:u,hide:l,label:d,legendType:f,xAxisId:p,yAxisId:m,points:x,layout:y,height:S,width:C,left:w,top:T,needClip:_}))}function di(e){var{layout:t,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,dataKey:o,bandSize:s,displayedData:c}=e;return c.map((e,c)=>{var l=it(e,o);if(t===`horizontal`)return{x:et({axis:n,ticks:i,bandSize:s,entry:e,index:c}),y:(wt(l)?null:r.scale.map(l))??null,value:l,payload:e};var u=wt(l)?null:n.scale.map(l),d=et({axis:r,ticks:a,bandSize:s,entry:e,index:c});return u==null||d==null?null:{x:u,y:d,value:l,payload:e}}).filter(Boolean)}function fi(e){var t=St(e,li),n=$e();return X.createElement(Ct,{id:t.id,type:`line`},e=>X.createElement(X.Fragment,null,X.createElement(Xe,{legendPayload:Zr(t)}),X.createElement(Qr,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),X.createElement(qe,{type:`line`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,hide:t.hide,isPanorama:n}),X.createElement(ui,Wr({},t,{id:e}))))}var pi=X.memo(fi,dt);pi.displayName=`Line`;var mi=[`axis`],hi=(0,X.forwardRef)((e,t)=>X.createElement(bt,{chartName:`LineChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:mi,tooltipPayloadSearcher:Ge,categoricalChartProps:e,ref:t})),gi=e(d(),1);function _i(e,t){let n=e.split(`.`).map(e=>parseInt(e,10)||0),r=t.split(`.`).map(e=>parseInt(e,10)||0);for(;n.length<4;)n.push(0);for(;r.length<4;)r.push(0);for(let e=0;e<4;e++)if(n[e]!==r[e])return n[e]-r[e];return 0}function vi(e,t,n,r){if(!e)return``;if(r)return`${e} — ${r}`;if(!t)return e;let i=t.match(/plate_(\d+)\.gcode/);return i&&parseInt(i[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:i[1]})}`:e}var yi=new Set([`A1`,`A1MINI`,`A2L`,`A1M`,`N1`,`N2S`,`N9`,`A04`,`A11`,`A12`]);function bi(e){return e?yi.has(e.toUpperCase().replace(/[^A-Z0-9]/g,``)):!1}function xi(e){let t=typeof window<`u`&&window.visualViewport?window.visualViewport.height:typeof window<`u`?window.innerHeight:0,{triggerRect:n,popoverWidth:r,estimatedHeight:i,viewportHeight:a=t,viewportWidth:o=window.innerWidth,margin:s=8,gap:c=4,horizontalAlign:l=`right`}=e,u=n.bottom+c,d=`below`;if(u+i>a-s){let e=n.top-c-i;e>=s&&(u=e,d=`above`)}let f=n.left+(n.right-n.left)/2,p=l===`center`?f-r/2:n.right-r;po-s&&(p=Math.max(s,o-r-s));let m=d===`above`?n.top-c:u,h=Math.max(14,Math.min(r-14,f-p));return{top:u,left:p,placement:d,anchorY:m,arrowLeft:h}}var Si=`cameraViewMode`,Ci=`cameraWindowState`;function wi(e){return e===`window`||e===`embedded`}function Ti(){try{let e=localStorage.getItem(Si);return wi(e)?e:null}catch{return null}}function Ei(e){try{localStorage.setItem(Si,e)}catch{}}function Di(e){let t={width:640,height:400};try{let e=localStorage.getItem(Ci);if(e){let n=JSON.parse(e);n&&typeof n==`object`&&(t=n)}}catch{}let n=[`width=${t.width??640}`,`height=${t.height??400}`,t.left===void 0?``:`left=${t.left}`,t.top===void 0?``:`top=${t.top}`,`menubar=no,toolbar=no,location=no,status=no`].filter(Boolean).join(`,`);window.open(`/camera/${e}`,`camera-${e}`,n)}var Oi={NYLON:`PA`,PA6:`PA`,PA11:`PA`,PA12:`PA`,PAHT:`PA`,PPA:`PA`};function ki(e,t){let n=(e||``).split(` `)[0].toUpperCase();for(let e of[n,n.split(`-`)[0]]){let n=Oi[e]??e;if(t[n])return n}return`PLA`}function Ai(e,t,n,r=new Date){return e===`now`?null:e===`delay`?new Date(r.getTime()+t*6e4).toISOString():new Date(n).toISOString()}var ji=`printerHiddenExternalSpools`;function Mi(){try{let e=localStorage.getItem(ji);if(!e)return{};let t=JSON.parse(e);return!t||typeof t!=`object`||Array.isArray(t)?{}:t}catch{return{}}}function Ni(e){return Mi()[String(e)]===!0}function Pi(e,t){let n=Mi();t?n[String(e)]=!0:delete n[String(e)];try{localStorage.setItem(ji,JSON.stringify(n))}catch{}}var $=t(),Fi=[{key:`printing`,dot:`bg-bambu-green`},{key:`paused`,dot:`bg-status-warning`},{key:`finished`,dot:`bg-blue-400`},{key:`idle`,dot:`bg-bambu-green`},{key:`error`,dot:`bg-status-error`},{key:`offline`,dot:`bg-gray-400`}];function Ii({selectedIds:e,printers:t,onClose:n,onSelectAll:r,onSelectByLocation:i,onSelectByState:a,onAction:o,actionPending:s}){let{t:c}=l(),{hasPermission:u}=lr(),d=f(),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),_=Array.from(e).map(e=>({id:e,status:d.getQueryData([`printerStatus`,e])})),v=_.some(({status:e})=>e?.connected&&e.state===`RUNNING`),y=_.some(({status:e})=>e?.connected&&e.state===`PAUSE`),b=v||y,x=_.some(({status:e})=>!!(e?.connected&&e.awaiting_plate_clear)),S=_.some(({status:e})=>!e?.connected||!e.hms_errors?!1:Mt(e.hms_errors).length>0),C=u(`printers:control`),w=u(`printers:clear_plate`),T=[...new Set(t.map(e=>e.location).filter(e=>!!e))].sort(),E={printing:0,paused:0,finished:0,idle:0,error:0,offline:0};t.forEach(e=>{let t=d.getQueryData([`printerStatus`,e.id]);if(!t||!t.connected){E.offline++;return}let n=t.hms_errors?Mt(t.hms_errors).length>0:!1;switch(n&&E.error++,t.state){case`RUNNING`:E.printing++;break;case`PAUSE`:E.paused++;break;case`FINISH`:E.finished++;break;case`FAILED`:n||E.finished++;break;default:E.idle++;break}});let O={printing:c(`printers.status.printing`),paused:c(`printers.status.paused`,`Paused`),finished:c(`printers.status.finished`,`Finished`),idle:c(`printers.status.idle`),error:c(`printers.status.problem`),offline:c(`printers.status.offline`)};return(0,$.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:n,children:(0,$.jsx)(Pt,{className:`w-4 h-4`})}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsx)(`span`,{className:`text-white font-medium text-sm`,children:c(`printers.bulk.selected`,{count:e.size})}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:r,children:c(`printers.bulk.selectAll`)}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>{g(!h),m(!1)},children:[c(`printers.bulk.selectByState`),(0,$.jsx)(I,{className:`w-3 h-3 transition-transform ${h?`rotate-180`:``}`})]}),h&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>g(!1)}),(0,$.jsx)(`div`,{className:`absolute bottom-full mb-2 left-0 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:Fi.filter(({key:e})=>E[e]>0).map(({key:e,dot:t})=>(0,$.jsxs)(`button`,{onClick:()=>{a(e),g(!1)},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full ${t}`}),O[e],(0,$.jsx)(`span`,{className:`ml-auto text-bambu-gray text-xs`,children:E[e]})]},e))})]})]}),T.length>0&&(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>{m(!p),g(!1)},children:[c(`printers.bulk.selectByLocation`),(0,$.jsx)(I,{className:`w-3 h-3 transition-transform ${p?`rotate-180`:``}`})]}),p&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>m(!1)}),(0,$.jsx)(`div`,{className:`absolute bottom-full mb-2 left-0 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:T.map(e=>(0,$.jsx)(`button`,{onClick:()=>{i(e),m(!1)},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors`,children:e},e))})]})]}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsxs)(Y,{size:`sm`,className:`bg-red-500 hover:bg-red-600`,onClick:()=>o(`stop`),disabled:s||!C||!b,title:C?b?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(fn,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.stop`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`pause`),disabled:s||!C||!v,title:C?v?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(Oe,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.pause`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`resume`),disabled:s||!C||!y,title:C?y?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(ke,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.resume`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`clearHMS`),disabled:s||!C||!S,title:C?S?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(D,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.clearHMS`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`clearPlate`),disabled:s||!w||!x,title:w?x?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(k,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.clearPlate`)]})]})}function Li({printerId:e,filePath:t,filename:n,onClose:r}){let[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)([]),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),p=n.toLowerCase().split(`.`).pop()||``,m=p===`3mf`||p===`stl`,h=p===`gcode`||p===`3mf`;(0,X.useEffect)(()=>{o(m?`3d`:h?`gcode`:null)},[m,h]),(0,X.useEffect)(()=>{c([]),f(null),m&&(u(!0),i.getPrinterFilePlates(e,t).then(e=>c(e.plates||[])).catch(()=>c([])).finally(()=>u(!1)))},[t,m,e]);let g=s.length>1,_=d==null?null:s.find(e=>e.index===d)??null;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-6`,onClick:r,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-4xl h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate flex-1 mr-4`,children:n}),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:r,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`button`,{onClick:()=>m&&o(`3d`),disabled:!m,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${a===`3d`?`text-bambu-green border-b-2 border-bambu-green`:m?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,$.jsx)(j,{className:`w-4 h-4`}),`3D Model`,!m&&(0,$.jsx)(`span`,{className:`text-xs`,children:`(not available)`})]}),(0,$.jsxs)(`button`,{onClick:()=>h&&o(`gcode`),disabled:!h,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${a===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:h?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,$.jsx)(or,{className:`w-4 h-4`}),`G-code Preview`,!h&&(0,$.jsx)(`span`,{className:`text-xs`,children:`(not sliced)`})]})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:a===`3d`&&m?(0,$.jsxs)(`div`,{className:`w-full h-full flex flex-col gap-3`,children:[g&&(0,$.jsxs)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,$.jsx)(j,{className:`w-4 h-4`}),`Plates`,l&&(0,$.jsx)(H,{className:`w-3 h-3 animate-spin`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(null),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${d==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,$.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,$.jsx)(j,{className:`w-5 h-5 text-bambu-gray`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:`All Plates`}),(0,$.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[s.length,` plate`,s.length===1?``:`s`]})]}),d==null&&(0,$.jsx)(xn,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]}),s.map(n=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(n.index),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${d===n.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[n.has_thumbnail?(0,$.jsx)(`img`,{src:i.getPrinterFilePlateThumbnail(e,n.index,t),alt:`Plate ${n.index}`,className:`w-10 h-10 rounded object-cover bg-bambu-dark-tertiary`}):(0,$.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,$.jsx)(j,{className:`w-5 h-5 text-bambu-gray`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:n.name||`Plate ${n.index}`}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:n.objects.length>0?n.objects.slice(0,2).join(`, `)+(n.objects.length>2?`…`:``):`${n.filaments.length} filament${n.filaments.length===1?``:`s`}`})]}),d===n.index&&(0,$.jsx)(xn,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]},n.index))]}),_&&(0,$.jsxs)(`div`,{className:`mt-3 text-xs text-bambu-gray flex flex-wrap gap-x-4 gap-y-1`,children:[(0,$.jsxs)(`span`,{children:[`Plate `,_.index]}),_.print_time_seconds!=null&&(0,$.jsxs)(`span`,{children:[`ETA `,Math.round(_.print_time_seconds/60),` min`]}),_.filament_used_grams!=null&&(0,$.jsxs)(`span`,{children:[_.filament_used_grams.toFixed(1),` g`]}),_.filaments.length>0&&(0,$.jsxs)(`span`,{children:[_.filaments.length,` filament`,_.filaments.length===1?``:`s`]})]})]}),(0,$.jsx)(`div`,{className:`flex-1`,children:(0,$.jsx)(dr,{url:i.getPrinterFileDownloadUrl(e,t),fileType:p,selectedPlateId:d,className:`w-full h-full`})})]}):a===`gcode`&&h?(0,$.jsx)(ae,{gcodeUrl:i.getPrinterFileGcodeUrl(e,t),className:`w-full h-full`}):(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:`No preview available for this file`})})]})})}function Ri(e){if(e===0)return`0 GB`;let t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function zi(e,t){if(t)return Fn;switch(e.toLowerCase().split(`.`).pop()||``){case`3mf`:return ie;case`gcode`:return or;case`mp4`:case`avi`:return se;case`png`:case`jpg`:case`jpeg`:return tr;default:return V}}var Bi=[{value:`name-asc`,label:`Name (A-Z)`},{value:`name-desc`,label:`Name (Z-A)`},{value:`size-asc`,label:`Size (smallest)`},{value:`size-desc`,label:`Size (largest)`},{value:`date-asc`,label:`Date (oldest)`},{value:`date-desc`,label:`Date (newest)`}];function Vi({printerId:e,printerName:t,onClose:n}){let{t:r}=l(),{showToast:a}=te(),o=f(),[s,c]=(0,X.useState)(`/`),[u,d]=(0,X.useState)(new Set),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)([]),[y,b]=(0,X.useState)(`name-asc`),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),E=(0,X.useRef)(null),D=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:O,isLoading:k,refetch:A}=p({queryKey:[`printerFiles`,e,s],queryFn:()=>i.getPrinterFiles(e,s)}),{data:M}=p({queryKey:[`printerStorage`,e],queryFn:()=>i.getPrinterStorage(e),staleTime:3e4}),N=(0,X.useMemo)(()=>[...O?.files??[]].filter(e=>!h||e.name.toLowerCase().includes(h.toLowerCase())).sort((e,t)=>{if(e.is_directory&&!t.is_directory)return-1;if(!e.is_directory&&t.is_directory)return 1;switch(y){case`name-asc`:return e.name.localeCompare(t.name);case`name-desc`:return t.name.localeCompare(e.name);case`size-asc`:return e.size-t.size;case`size-desc`:return t.size-e.size;case`date-asc`:return(e.mtime?qt(e.mtime)?.getTime()??0:0)-(t.mtime?qt(t.mtime)?.getTime()??0:0);case`date-desc`:{let n=e.mtime?qt(e.mtime)?.getTime()??0:0;return(t.mtime?qt(t.mtime)?.getTime()??0:0)-n}default:return e.name.localeCompare(t.name)}}),[O?.files,h,y]),P=!!O&&!O.warnings?.includes(`printer_unavailable`);(0,X.useEffect)(()=>{if(!P)return;let e=new Set(N.filter(e=>!e.is_directory).map(e=>e.path));d(t=>new Set([...t].filter(t=>e.has(t)))),E.current&&!e.has(E.current)&&(E.current=null)},[N,P]),(0,X.useEffect)(()=>()=>D.current?.abort(),[]);let F=m({mutationFn:async t=>{for(let n of t)await i.deletePrinterFile(e,n)},onSuccess:()=>{a(r(`printerFiles.toast.filesDeleted`,{count:_.length})),o.invalidateQueries({queryKey:[`printerFiles`,e]}),d(new Set),E.current=null,v([])},onError:e=>{a(r(`printerFiles.toast.deleteFailed`,{error:e.message}),`error`)}}),I=e=>{c(e),d(new Set),E.current=null},L=()=>{if(s===`/`)return;let e=s.split(`/`).filter(Boolean);e.pop(),c(e.length?`/`+e.join(`/`):`/`),d(new Set),E.current=null},R=(e,t)=>{t.stopPropagation();let n=N.filter(e=>!e.is_directory).map(e=>e.path),r=E.current?n.indexOf(E.current):-1,i=n.indexOf(e),a=t.shiftKey&&r!==-1&&i!==-1;a||(E.current=e),d(t=>{let o=new Set(t);if(a){let e=Math.min(r,i),t=Math.max(r,i);n.slice(e,t+1).forEach(e=>o.add(e))}else o.has(e)?o.delete(e):o.add(e);return o})};return(0,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,$.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(fe,{className:`w-5 h-5 text-bambu-green`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`printerFiles.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[M&&(M.used_bytes!=null||M.free_bytes!=null)&&(0,$.jsxs)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-2`,children:[M.used_bytes!=null&&(0,$.jsxs)(`span`,{children:[r(`printerFiles.storageUsed`),` `,Ri(M.used_bytes)]}),M.used_bytes!=null&&M.free_bytes!=null&&(0,$.jsx)(`span`,{className:`text-bambu-dark-tertiary`,children:`|`}),M.free_bytes!=null&&(0,$.jsxs)(`span`,{children:[r(`printerFiles.storageFree`),` `,Ri(M.free_bytes)]})]}),(0,$.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:`Close file manager`,"aria-label":`Close file manager`,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[[{path:`/`,label:`Root`},{path:`/cache`,label:`Cache`},{path:`/model`,label:`Models`},{path:`/timelapse`,label:`Timelapse`}].map(e=>(0,$.jsx)(`button`,{onClick:()=>{I(e.path),g(``)},className:`px-3 py-1 text-sm rounded-full transition-colors ${s===e.path?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:e.label},e.path)),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Ae,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,placeholder:r(`printerFiles.filterPlaceholder`),value:h,onChange:e=>g(e.target.value),className:`w-40 pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,$.jsxs)(`div`,{className:`relative flex items-center gap-1`,children:[(0,$.jsx)(T,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`select`,{value:y,onChange:e=>b(e.target.value),className:`appearance-none bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm py-1.5 pl-2 pr-6 focus:border-bambu-green focus:outline-none cursor-pointer`,title:`Sort files`,"aria-label":`Sort files`,children:Bi.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:()=>A(),disabled:k,"aria-label":r(`common.refresh`),title:r(`common.refresh`),children:(0,$.jsx)(dn,{className:`w-4 h-4 ${k?`animate-spin`:``}`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark text-sm flex-shrink-0`,children:[(0,$.jsx)(`button`,{onClick:L,disabled:s===`/`,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed`,title:`Go to parent folder`,"aria-label":`Go to parent folder`,children:(0,$.jsx)(Yn,{className:`w-4 h-4`})}),(0,$.jsx)(`span`,{className:`text-bambu-gray font-mono`,children:s})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:k?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,$.jsx)(H,{className:`w-8 h-8 text-bambu-green animate-spin`})}):O?.warnings?.includes(`printer_unavailable`)?(0,$.jsx)(`div`,{className:`text-center py-12 text-amber-600 dark:text-amber-400`,children:r(`printerFiles.printerUnavailable`)}):O?.files?.length?(0,$.jsx)(`div`,{className:`space-y-1`,children:N.map(e=>{let t=zi(e.name,e.is_directory),n=u.has(e.path);return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg cursor-pointer transition-colors ${n?`bg-bambu-green/20 border border-bambu-green/50`:`hover:bg-bambu-dark-tertiary`}`,onClick:t=>{e.is_directory?I(e.path):R(e.path,t)},children:[e.is_directory?null:(0,$.jsx)(`button`,{onClick:t=>R(e.path,t),className:`flex-shrink-0 text-bambu-gray hover:text-white`,"aria-label":r(n?`printerFiles.deselectFile`:`printerFiles.selectFile`,{name:e.name}),title:r(`printerFiles.shiftSelectHint`),children:n?(0,$.jsx)(xn,{className:`w-5 h-5 text-bambu-green`}):(0,$.jsx)(fn,{className:`w-5 h-5`})}),(0,$.jsx)(t,{className:`w-5 h-5 flex-shrink-0 ${e.is_directory?`text-bambu-green`:`text-bambu-gray`}`}),(0,$.jsx)(`span`,{className:`flex-1 text-white truncate`,children:e.name}),!e.is_directory&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:zt(e.size)}),(e.name.toLowerCase().endsWith(`.3mf`)||e.name.toLowerCase().endsWith(`.gcode`)||e.name.toLowerCase().endsWith(`.stl`))&&(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),w({path:e.path,name:e.name})},className:`p-1 rounded hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`,title:`3D View`,children:(0,$.jsx)(j,{className:`w-4 h-4`})})]}),e.is_directory&&(0,$.jsx)(Yn,{className:`w-4 h-4 text-bambu-gray rotate-180`})]},e.path)})}):(0,$.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`printerFiles.noFiles`)})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:u.size>0?`${u.size} selected`:h?`${O?.files?.filter(e=>e.name.toLowerCase().includes(h.toLowerCase())).length||0} of ${O?.files?.length||0} items`:`${O?.files?.length||0} items`}),O?.files?.some(e=>!e.is_directory)&&(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:u.size>0?(0,$.jsxs)(`button`,{onClick:()=>{d(new Set),E.current=null},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(Mr,{className:`w-4 h-4`}),`Deselect All`]}):(0,$.jsxs)(`button`,{onClick:()=>{let e=N.filter(e=>!e.is_directory).map(e=>e.path);d(new Set(e)),E.current=null},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(xn,{className:`w-4 h-4`}),`Select All`]})})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Y,{variant:`secondary`,disabled:u.size===0||x!==null,onClick:async()=>{if(u.size===0)return;let n=N.filter(e=>!e.is_directory&&u.has(e.path)).map(e=>e.path);if(n.length===0)return;let o=new AbortController;D.current=o,S({current:0,total:n.length});try{let s=Object.fromEntries(n.map(e=>[e,O?.files.find(t=>t.path===e)?.size??0])),c=await i.downloadPrinterFilesAsZip(e,n,s,n.length===1?O?.files.find(e=>e.path===n[0])?.name??`printer-file`:`${t.replace(/[^a-zA-Z0-9]/g,`_`)}-files.zip`,n.length>1,o.signal,(e,t)=>S({current:e,total:t}));c.failed>0?a(r(`printerFiles.zipPartial`,{successful:c.successful,total:c.requested}),`warning`):a(r(`printerFiles.zipStarted`,{count:c.successful})),d(new Set),E.current=null}catch(e){a(r(`printerFiles.downloadFailed`,{error:e instanceof Error?e.message:r(`printerFiles.unknownError`)}),`error`)}finally{D.current===o&&(D.current=null),S(null)}},children:x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{className:`w-4 h-4 animate-spin`}),x.current,`/`,x.total]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ar,{className:`w-4 h-4`}),`Download`,u.size>1?` (${u.size})`:``]})}),(0,$.jsxs)(Y,{variant:`secondary`,disabled:u.size===0||F.isPending,onClick:()=>{u.size!==0&&v(N.filter(e=>!e.is_directory&&u.has(e.path)).map(e=>e.path))},className:`text-red-700 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300`,children:[F.isPending?(0,$.jsx)(H,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(Qt,{className:`w-4 h-4`}),r(`printerFiles.deleteButton`),u.size>1?` (${u.size})`:``]})]})]})]}),_.length>0&&(0,$.jsx)(In,{title:_.length>1?r(`printerFiles.deleteFiles`,{count:_.length}):r(`fileManager.deleteFile`),message:_.length>1?r(`printerFiles.deleteFilesConfirm`,{count:_.length}):r(`printerFiles.deleteFileConfirm`,{name:_[0].split(`/`).pop()}),confirmText:r(`common.delete`),variant:`danger`,onConfirm:()=>{F.mutate(_)},onCancel:()=>v([])}),C&&(0,$.jsx)(Li,{printerId:e,filePath:C.path,filename:C.name,onClose:()=>w(null)})]})}var Hi=`embeddedCameraState_`,Ui=5,Wi=2e3,Gi=3e4,Ki=5e3,qi={x:window.innerWidth-420,y:20,width:400,height:300};function Ji({printerId:e,printerName:t,viewerIndex:n=0,onClose:a}){let{t:s}=l(),c=f(),{showToast:u}=te(),{hasPermission:d}=lr(),h=`${Hi}${e}`,[g,_]=(0,X.useState)(()=>{try{let e=localStorage.getItem(h);if(e){let t=JSON.parse(e);return{x:Math.min(Math.max(0,t.x),window.innerWidth-100),y:Math.min(Math.max(0,t.y),window.innerHeight-100),width:Math.max(200,Math.min(t.width,window.innerWidth-20)),height:Math.max(150,Math.min(t.height,window.innerHeight-20))}}}catch{}let e=n*30;return{...qi,x:Math.max(0,qi.x-e),y:Math.max(0,qi.y+e)}}),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)({x:0,y:0}),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(1),[A,j]=(0,X.useState)({x:0,y:0}),[M,N]=(0,X.useState)(!1),[P,F]=(0,X.useState)({x:0,y:0}),[I,L]=(0,X.useState)(null),[R,ee]=(0,X.useState)(null),[ne,z]=(0,X.useState)(!1),[re,B]=(0,X.useState)(!0),[ie,ae]=(0,X.useState)(Date.now()),[V,oe]=(0,X.useState)(0),[se,ce]=(0,X.useState)(!1),[le,ue]=(0,X.useState)(0),fe=(0,X.useRef)(null),pe=(0,X.useRef)(null),H=(0,X.useRef)(null),me=(0,X.useRef)(null),G=(0,X.useRef)(null),[be,xe]=(0,X.useState)(!1),[Se,K]=(0,X.useState)(!1),{data:Ce}=p({queryKey:[`printer`,e],queryFn:()=>i.getPrinter(e),enabled:e>0}),{data:we}=p({queryKey:[`printerStatus`,e],queryFn:()=>i.getPrinterStatus(e),refetchInterval:3e4,enabled:e>0}),Te=m({mutationFn:t=>i.setChamberLight(e,t),onMutate:async t=>{await c.cancelQueries({queryKey:[`printerStatus`,e]});let n=c.getQueryData([`printerStatus`,e]);return c.setQueryData([`printerStatus`,e],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{u(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&c.setQueryData([`printerStatus`,e],r.previousStatus),u(t.message||s(`printers.toast.failedToControlChamberLight`),`error`)}}),q=(we?.state===`RUNNING`||we?.state===`PAUSE`)&&(we?.printable_objects_count??0)>=2;(0,X.useEffect)(()=>{let e=setTimeout(()=>{localStorage.setItem(h,JSON.stringify(g))},500);return()=>clearTimeout(e)},[g,h]);let J=(0,X.useRef)(!1);(0,X.useEffect)(()=>{J.current=!1;let t=`/api/v1/printers/${e}/camera/stop`,n=()=>{if(e>0&&!J.current){J.current=!0;let e={},n=o();n&&(e.Authorization=`Bearer ${n}`),fetch(t,{method:`POST`,keepalive:!0,headers:e}).catch(()=>{})}},r=pe.current;return()=>{r&&(r.src=``),n(),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current),G.current&&clearInterval(G.current)}},[e]),(0,X.useEffect)(()=>{if(re){let e=setTimeout(()=>B(!1),3e3);return()=>clearTimeout(e)}},[re,ie]);let Ee=(0,X.useCallback)(()=>{if(V>=Ui){ce(!1),z(!0);return}let e=Math.min(Wi*2**V,Gi);ce(!0),ue(Math.ceil(e/1e3)),me.current=setInterval(()=>{ue(e=>e<=1?(me.current&&clearInterval(me.current),0):e-1)},1e3),H.current=setTimeout(()=>{oe(e=>e+1),ce(!1),B(!0),z(!1),pe.current&&(pe.current.src=``),ae(Date.now())},e)},[V]);(0,X.useEffect)(()=>{if(re||se||w){G.current&&=(clearInterval(G.current),null);return}return G.current=setInterval(async()=>{try{let t=await i.getCameraStatus(e);(t.stalled||!t.active&&!ne)&&(G.current&&=(clearInterval(G.current),null),B(!1),Ee())}catch{}},Ki),()=>{G.current&&=(clearInterval(G.current),null)}},[re,ne,se,w,e,Ee]),(0,X.useEffect)(()=>{let e=()=>{let e=!!document.fullscreenElement;D(e),e||(k(1),j({x:0,y:0}))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let De=()=>{fe.current&&(document.fullscreenElement?document.exitFullscreen():fe.current.requestFullscreen())},Oe=()=>{k(e=>Math.min(e+.5,4))},ke=()=>{k(e=>{let t=Math.max(e-.5,1);return t===1&&j({x:0,y:0}),t})},Ae=e=>{e.preventDefault(),e.deltaY<0?Oe():ke()},je=e=>{O>1&&(e.preventDefault(),N(!0),F({x:e.clientX-A.x,y:e.clientY-A.y}))},Me=(0,X.useCallback)(()=>{if(!fe.current||!pe.current)return{x:200,y:150};let e=fe.current.getBoundingClientRect(),t=e.width*(O-1)/2,n=e.height*(O-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[O]),Ne=e=>{if(M&&O>1){let t=e.clientX-P.x,n=e.clientY-P.y,r=Me();j({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Pe=()=>{N(!1)},Fe=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Ie=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},Le=e=>{e.touches.length===2?(e.preventDefault(),L(Fe(e.touches)),ee(Ie(e.touches))):e.touches.length===1&&O>1&&(e.preventDefault(),N(!0),F({x:e.touches[0].clientX-A.x,y:e.touches[0].clientY-A.y}))},Re=e=>{if(e.touches.length===2&&I!==null){e.preventDefault();let t=Fe(e.touches),n=t/I;k(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&j({x:0,y:0}),t}),L(t);let r=Ie(e.touches);if(R){let e=Me();j(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-R.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-R.y)))}))}ee(r)}else if(e.touches.length===1&&M&&O>1){e.preventDefault();let t=e.touches[0].clientX-P.x,n=e.touches[0].clientY-P.y,r=Me();j({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},ze=e=>{e.touches.length<2&&(L(null),ee(null)),e.touches.length===0&&N(!1)},Be=()=>{k(1),j({x:0,y:0})},Ve=()=>{B(!1),V{B(!1),z(!1),oe(0),ce(!1),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current)},Ue=()=>{B(!0),z(!1),oe(0),ce(!1),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current);let t={},n=o();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,headers:t}).catch(()=>{}),pe.current&&(pe.current.src=``),setTimeout(()=>ae(Date.now()),100)},We=e=>{e.target.closest(`.no-drag`)||(y(!0),C({x:e.clientX-g.x,y:e.clientY-g.y}))},Ge=e=>{if(e.target.closest(`.no-drag`))return;let t=e.touches[0];y(!0),C({x:t.clientX-g.x,y:t.clientY-g.y})},Ke=e=>{e.stopPropagation(),x(!0)},qe=e=>{e.stopPropagation(),x(!0)};(0,X.useEffect)(()=>{let e=e=>{if(v)_(t=>({...t,x:Math.max(0,Math.min(e.clientX-S.x,window.innerWidth-t.width)),y:Math.max(0,Math.min(e.clientY-S.y,window.innerHeight-t.height))}));else if(b&&fe.current){let t=fe.current.getBoundingClientRect();_(n=>({...n,width:Math.max(200,Math.min(e.clientX-t.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(e.clientY-t.top,window.innerHeight-n.y-10))}))}},t=e=>{if(!v&&!b)return;e.preventDefault();let t=e.touches[0];if(v)_(e=>({...e,x:Math.max(0,Math.min(t.clientX-S.x,window.innerWidth-e.width)),y:Math.max(0,Math.min(t.clientY-S.y,window.innerHeight-e.height))}));else if(b&&fe.current){let e=fe.current.getBoundingClientRect();_(n=>({...n,width:Math.max(200,Math.min(t.clientX-e.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(t.clientY-e.top,window.innerHeight-n.y-10))}))}},n=()=>{y(!1),x(!1)};if(v||b)return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,n),document.addEventListener(`touchmove`,t,{passive:!1}),document.addEventListener(`touchend`,n),document.addEventListener(`touchcancel`,n),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,n),document.removeEventListener(`touchmove`,t),document.removeEventListener(`touchend`,n),document.removeEventListener(`touchcancel`,n)}},[v,b,S]);let Je=r(`/api/v1/printers/${e}/camera/stream?fps=15&t=${ie}`);return(0,$.jsxs)(`div`,{ref:fe,className:`${E?`fixed inset-0 z-[100]`:`fixed z-40 rounded-lg shadow-2xl border border-bambu-dark-tertiary`} bg-bambu-dark-secondary overflow-hidden`,style:E?void 0:{left:g.x,top:g.y,width:w?200:g.width,height:w?40:g.height,cursor:v?`grabbing`:`default`},children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-bambu-dark border-b border-bambu-dark-tertiary cursor-grab active:cursor-grabbing`,onMouseDown:We,onTouchStart:Ge,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-white truncate`,children:[(0,$.jsx)(de,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:Ce?.name||t})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 no-drag`,children:[(0,$.jsx)(`button`,{onClick:()=>Te.mutate(!we?.chamber_light),disabled:!we?.connected||Te.isPending||!d(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${we?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:d(`printers:control`)?s(`camera.chamberLight`):s(`printers.permission.noControl`),children:(0,$.jsx)(_e,{on:we?.chamber_light??!1,className:`w-3.5 h-3.5`})}),(0,$.jsx)(`button`,{onClick:()=>xe(!0),disabled:!q||!d(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${q&&d(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:d(`printers:control`)?s(q?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):s(`printers.permission.noControl`),children:(0,$.jsx)(ve,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:Ue,disabled:re||se,className:`p-1 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:`Refresh stream`,children:(0,$.jsx)(dn,{className:`w-3.5 h-3.5 text-bambu-gray ${re?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:()=>K(!0),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:s(`camera.diagnose.button`),children:(0,$.jsx)(an,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:De,className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:E?`Exit fullscreen`:`Fullscreen`,children:E?(0,$.jsx)(ge,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,$.jsx)(wr,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:()=>T(!w),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:w?`Expand`:`Minimize`,children:w?(0,$.jsx)(he,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,$.jsx)(U,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:a,className:`p-1 hover:bg-red-500/20 rounded`,title:`Close`,children:(0,$.jsx)(Pt,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`})})]})]}),!w&&(0,$.jsxs)(`div`,{className:`relative w-full bg-black flex items-center justify-center overflow-hidden h-[calc(100%-40px)]`,onWheel:Ae,onMouseMove:Ne,onMouseUp:Pe,onMouseLeave:Pe,onTouchStart:Le,onTouchMove:Re,onTouchEnd:ze,style:{touchAction:`none`},children:[re&&!se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,$.jsx)(dn,{className:`w-6 h-6 text-bambu-gray animate-spin`})}),se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,$.jsxs)(`div`,{className:`text-center p-2`,children:[(0,$.jsx)(en,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,$.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Reconnecting in `,le,`s...`]})]})}),ne&&!se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,$.jsxs)(`div`,{className:`text-center p-2`,children:[(0,$.jsx)(Ot,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:s(`camera.unavailable`)}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,$.jsx)(`button`,{onClick:Ue,className:`px-2 py-1 text-xs bg-bambu-green text-white rounded hover:bg-bambu-green/80`,children:s(`camera.retry`)}),(0,$.jsx)(`button`,{onClick:()=>K(!0),className:`px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:s(`camera.diagnose.button`)})]})]})}),(0,$.jsx)(`img`,{ref:pe,src:Je,alt:`Camera stream`,className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${O}) translate(${A.x/O}px, ${A.y/O}px) rotate(${Ce?.camera_rotation||0}deg)`,...Ce?.camera_rotation===90||Ce?.camera_rotation===270?{maxWidth:`100%`,maxHeight:`100%`}:{},cursor:O>1?M?`grabbing`:`grab`:`default`},onError:Ve,onLoad:He,onMouseDown:je,draggable:!1},ie),(0,$.jsxs)(`div`,{className:`absolute bottom-2 left-2 flex items-center gap-1 bg-black/60 rounded px-1.5 py-1 no-drag`,children:[(0,$.jsx)(`button`,{onClick:ke,disabled:O<=1,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom out`,children:(0,$.jsx)(It,{className:`w-3.5 h-3.5 text-white`})}),(0,$.jsxs)(`button`,{onClick:Be,className:`px-1.5 py-0.5 text-xs text-white hover:bg-white/10 rounded min-w-[32px]`,title:`Reset zoom`,children:[Math.round(O*100),`%`]}),(0,$.jsx)(`button`,{onClick:Oe,disabled:O>=4,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom in`,children:(0,$.jsx)(Ft,{className:`w-3.5 h-3.5 text-white`})})]}),!E&&(0,$.jsx)(`div`,{className:`absolute bottom-0 right-0 w-6 h-6 cursor-se-resize no-drag hover:bg-white/10 rounded-tl transition-colors`,onMouseDown:Ke,onTouchStart:qe,title:`Drag to resize`,children:(0,$.jsx)(`svg`,{className:`w-6 h-6 text-bambu-gray/70 hover:text-bambu-gray`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,$.jsx)(`path`,{d:`M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22ZM22 14H20V12H22V14ZM18 18H16V16H18V18ZM14 22H12V20H14V22ZM22 10H20V8H22V10ZM18 14H16V12H18V14ZM14 18H12V16H14V18ZM10 22H8V20H10V22Z`})})})]}),(0,$.jsx)(ye,{printerId:e,isOpen:be,onClose:()=>xe(!1)}),Se&&(0,$.jsx)(W,{printerId:e,printerName:Ce?.name||null,onClose:()=>K(!1)})]})}function Yi({printerId:e,printerName:t,onClose:n}){let{t:r}=l(),a=f(),[o,s]=(0,X.useState)(!0),[c,u]=(0,X.useState)(new Set),[d,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(`all`),v=(0,X.useRef)(null),{data:y,isLoading:b,refetch:x}=p({queryKey:[`mqtt-logs`,e],queryFn:()=>i.getMQTTLogs(e),refetchInterval:1e3}),C=m({mutationFn:()=>i.enableMQTTLogging(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),w=m({mutationFn:()=>i.disableMQTTLogging(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),T=m({mutationFn:()=>i.clearMQTTLogs(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,X.useEffect)(()=>{o&&v.current&&(v.current.scrollTop=v.current.scrollHeight)},[y?.logs,o]);let D=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},O=e=>new Date(e).toLocaleTimeString(`en-US`,{hour12:!1,fractionalSecondDigits:3}),k=(e,t)=>{if(e==null)return``;let n=typeof e==`string`?JSON.parse(e):e,r=JSON.stringify(n,null,t?2:0);return!t&&r.length>100?r.substring(0,100)+`...`:r},A=y?.logging_enabled??!1,j=(0,X.useMemo)(()=>y?.logs??[],[y?.logs]),M=(0,X.useMemo)(()=>j.filter(e=>{if(g!==`all`&&e.direction!==g)return!1;if(d.trim()){let t=d.toLowerCase(),n=e.topic.toLowerCase().includes(t),r=JSON.stringify(e.payload).toLowerCase().includes(t);return n||r}return!0}),[j,d,g]);return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[85vh] flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`mqttDebug.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]}),(0,$.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[A?(0,$.jsxs)(Y,{size:`sm`,variant:`secondary`,onClick:()=>w.mutate(),disabled:w.isPending,children:[(0,$.jsx)(fn,{className:`w-4 h-4`}),r(`mqttDebug.stopLogging`)]}):(0,$.jsxs)(Y,{size:`sm`,onClick:()=>C.mutate(),disabled:C.isPending,children:[(0,$.jsx)(ke,{className:`w-4 h-4`}),r(`mqttDebug.startLogging`)]}),(0,$.jsxs)(Y,{size:`sm`,variant:`secondary`,onClick:()=>T.mutate(),disabled:T.isPending||j.length===0,children:[(0,$.jsx)(Qt,{className:`w-4 h-4`}),r(`mqttDebug.clearLog`)]}),(0,$.jsx)(Y,{size:`sm`,variant:`secondary`,onClick:()=>x(),disabled:b,children:(0,$.jsx)(dn,{className:`w-4 h-4 ${b?`animate-spin`:``}`})}),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,$.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[M.length,`/`,j.length]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(Ae,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,placeholder:r(`mqttDebug.searchPlaceholder`),value:d,onChange:e=>h(e.target.value),className:`w-full pl-8 pr-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),d&&(0,$.jsx)(`button`,{onClick:()=>h(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,$.jsx)(Pt,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded border border-bambu-dark-tertiary`,children:[(0,$.jsx)(`button`,{onClick:()=>_(`all`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${g===`all`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:r(`mqttDebug.all`)}),(0,$.jsxs)(`button`,{onClick:()=>_(`in`),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${g===`in`?`bg-blue-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,$.jsx)(S,{className:`w-3 h-3`}),r(`mqttDebug.incoming`)]}),(0,$.jsxs)(`button`,{onClick:()=>_(`out`),className:`px-2 py-1.5 text-xs rounded-r transition-colors flex items-center gap-1 ${g===`out`?`bg-green-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,$.jsx)(E,{className:`w-3 h-3`}),r(`mqttDebug.outgoing`)]})]})]})]}),(0,$.jsx)(`div`,{ref:v,className:`flex-1 overflow-auto p-4 font-mono text-xs bg-black min-h-[400px]`,children:j.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,$.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessages`)}),!A&&(0,$.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.startLoggingHint`)})]}):M.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,$.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessagesMatch`)}),(0,$.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.adjustFilterHint`)})]}):(0,$.jsx)(`div`,{className:`space-y-1`,children:M.map((e,t)=>{let n=c.has(t),i=e.direction===`in`;return(0,$.jsxs)(`div`,{className:`p-2 rounded cursor-pointer hover:bg-bambu-dark-secondary transition-colors ${n?`bg-bambu-dark-secondary`:``}`,onClick:()=>D(t),children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:O(e.timestamp)}),(0,$.jsx)(`span`,{className:`shrink-0 ${i?`text-blue-400`:`text-green-400`}`,title:r(i?`mqttDebug.incoming`:`mqttDebug.outgoing`),children:i?(0,$.jsx)(S,{className:`w-3 h-3`}):(0,$.jsx)(E,{className:`w-3 h-3`})}),(0,$.jsx)(`span`,{className:`text-purple-400 shrink-0`,children:e.topic})]}),n?(0,$.jsx)(`pre`,{className:`mt-2 p-3 bg-gray-900 border border-gray-700 rounded text-green-400 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto text-xs`,children:k(e.payload,!0)}):(0,$.jsx)(`pre`,{className:`mt-1 text-white/80 truncate`,children:k(e.payload,!1)})]},t)})})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:[(0,$.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:A?(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),r(`mqttDebug.loggingActive`)]}):(0,$.jsx)(`span`,{children:r(`mqttDebug.loggingStopped`)})}),(0,$.jsx)(Y,{variant:`secondary`,onClick:n,children:r(`common.close`)})]})]})})}function Xi(e){if(!e)return`idle`;switch(e.class){case`failure`:case`warning`:case`safe`:case`error`:return e.class;default:return`unknown`}}function Zi(e){return e===`failure`||e===`warning`||e===`safe`}function Qi({printerName:e,detection:t,lastError:n,onClose:r}){let{t:i}=l(),a=Tn();(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let o=Xi(t),s=o===`failure`?`text-status-error`:o===`warning`?`text-status-warning`:o===`safe`?`text-status-ok`:o===`error`?`text-amber-600 dark:text-amber-400`:`text-bambu-gray`,c=t?.error??n;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg shadow-xl max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(K,{className:`w-5 h-5 text-bambu-green`}),(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`printers.aiDetection.modalTitle`,{name:e})})]}),(0,$.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,"aria-label":i(`common.close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4 text-sm`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.currentStatus`)}),(0,$.jsx)(`span`,{className:`font-medium ${s}`,children:i(`printers.aiDetection.${o}`)})]}),t&&Zi(o)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.score`)}),(0,$.jsx)(`span`,{className:`text-white font-mono`,children:t.score.toFixed(3)})]}),(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.framesAnalyzed`)}),(0,$.jsx)(`span`,{className:`text-white font-mono`,children:t.frame_count})]})]}),o===`error`&&(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.errorHint`)}),!t&&(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.idleHint`)})]}),c&&(0,$.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:[(0,$.jsx)(R,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-red-700 dark:text-red-400`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`font-medium text-red-700 dark:text-red-400`,children:i(`printers.aiDetection.lastError`)}),(0,$.jsx)(`p`,{className:`text-red-700/80 dark:text-red-300/80 break-words mt-1`,children:c})]})]})]}),(0,$.jsx)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex items-center justify-end`,children:(0,$.jsxs)(`button`,{onClick:()=>a(`/settings?tab=failure-detection`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(En,{className:`w-4 h-4`}),i(`printers.aiDetection.openSettings`)]})})]})})}function $i({printerId:e,printerModel:t,loadedFilamentTypes:n,loadedFilaments:r,loadedVariants:a,variant:o=`card`}){let{t:s}=l(),{data:c}=p({queryKey:[`queue`,e,`pending`,t],queryFn:()=>i.getQueue(e,`pending`,t||void 0),refetchInterval:3e4}),u=c?nn(c,n,r,a):void 0,d=u?.length||0;if(d===0)return null;let f=u?.[0];return(0,$.jsx)(bn,{to:`/queue`,className:o===`panelExtension`?`block mt-2 border-t border-bambu-dark-tertiary pt-2 pl-1 hover:opacity-90 transition-opacity`:`block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,$.jsx)(P,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:s(`queue.nextInQueue`)}),(0,$.jsx)(`p`,{className:`text-sm text-white truncate`,children:f?_r(f):``})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[(0,$.jsx)(vn,{className:`w-3 h-3`}),f?.scheduled_time?Kt(f.scheduled_time,`system`,s):s(`time.waiting`)]}),d>1&&(0,$.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-400/20 text-yellow-700 dark:text-yellow-400 rounded`,children:[`+`,d-1]}),(0,$.jsx)(pn,{className:`w-4 h-4 text-bambu-gray`})]})]})})}function ea({printerId:e}){let{t}=l(),{data:n}=p({queryKey:[`haSensorReadings`,e],queryFn:()=>i.getHASensorReadings(e),refetchInterval:15e3});if(!n?.length)return null;let r=e=>v(e,t);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,$.jsx)(ue,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t(`haSensors.label`)}),(0,$.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>{let n=b(e),i=!e.reachable||e.state===null;return(0,$.jsxs)(`span`,{title:e.block_print?t(`haSensors.blocksPrints`,{entity:e.entity_id}):e.entity_id,className:`px-2 py-0.5 text-xs rounded flex items-center gap-1 ${i?`bg-bambu-dark-tertiary/50 text-bambu-gray`:e.alerting?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,$.jsx)(n,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),(0,$.jsx)(`span`,{children:e.name}),(0,$.jsx)(`span`,{className:`font-medium`,children:r(e)})]},e.id)})})]})}var ta=[{value:`6h`,label:`6h`,hours:6},{value:`24h`,label:`24h`,hours:24},{value:`48h`,label:`48h`,hours:48},{value:`7d`,label:`7d`,hours:168}];function na({isOpen:e,onClose:t,printerId:n,printerName:r,amsId:a,amsLabel:o,initialMode:s=`humidity`,thresholds:c}){let{t:u}=l(),[d,f]=(0,X.useState)(`24h`),[m,h]=(0,X.useState)(s),{data:g}=p({queryKey:[`settings`],queryFn:i.getSettings}),v=g?.time_format||`system`;(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let b=ta.find(e=>e.value===d)?.hours||24,{data:x,isLoading:S,error:C}=p({queryKey:[`ams-history`,n,a,b],queryFn:()=>i.getAMSHistory(n,a,b),enabled:e,refetchInterval:6e4});if(!e)return null;let w=x?.data.map(e=>({time:(qt(e.recorded_at)||new Date).getTime(),humidity:e.humidity,temperature:e.temperature}))||[],T=Date.now()-b*60*60*1e3,E=Date.now(),D=[...w];if(D.length>0){let e=D[0];e.time>T&&D.unshift({...e,time:T});let t=D[D.length-1];t.time{let t=e.filter(e=>e!=null);if(t.length<4)return`stable`;let n=t.slice(0,Math.floor(t.length/4)),r=t.slice(-Math.floor(t.length/4)),i=n.reduce((e,t)=>e+t,0)/n.length,a=r.reduce((e,t)=>e+t,0)/r.length-i;return Math.abs(a)<2?`stable`:a>0?`up`:`down`},R=L(D.map(e=>e.humidity)),ee=L(D.map(e=>e.temperature)),te=({trend:e})=>e===`up`?(0,$.jsx)(_,{className:`w-4 h-4 text-red-600 dark:text-red-400`}):e===`down`?(0,$.jsx)(Ke,{className:`w-4 h-4 text-green-600 dark:text-green-400`}):(0,$.jsx)(G,{className:`w-4 h-4 text-gray-400 dark:text-bambu-gray`}),ne=e=>e==null?`#9ca3af`:e<=k?`#22a352`:e<=j?`#d4a017`:`#c62828`,z=e=>e==null?`#9ca3af`:e<=M?`#22a352`:e<=N?`#d4a017`:`#c62828`,re=`var(--bg-secondary)`,B=`var(--bg-primary)`,ie=`var(--border-color)`,ae=`var(--text-primary)`,V=`var(--text-secondary)`,oe=`var(--text-muted)`;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,onClick:t,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-4xl max-h-[90vh] overflow-hidden shadow-xl`,style:{backgroundColor:re},onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b`,style:{borderColor:ie},children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h2`,{className:`text-lg font-semibold`,style:{color:ae},children:[o,` `,u(`common.history`,`History`)]}),(0,$.jsx)(`p`,{className:`text-sm`,style:{color:V},children:r})]}),(0,$.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg transition-colors`,style:{color:V},children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`p-6 space-y-6 overflow-y-auto max-h-[calc(90vh-80px)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between max-[550px]:flex-col max-[550px]:items-start max-[550px]:gap-3`,children:[(0,$.jsxs)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:B},children:[(0,$.jsxs)(`button`,{onClick:()=>h(`humidity`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${m===`humidity`?`bg-blue-600 text-white`:``}`,style:m===`humidity`?void 0:{color:V},children:[(0,$.jsx)(y,{className:`w-4 h-4`}),u(`common.humidity`,`Humidity`)]}),(0,$.jsxs)(`button`,{onClick:()=>h(`temperature`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${m===`temperature`?`bg-orange-600 text-white`:``}`,style:m===`temperature`?void 0:{color:V},children:[(0,$.jsx)(Me,{className:`w-4 h-4`}),u(`common.temperature`,`Temperature`)]})]}),(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:B},children:ta.map(e=>(0,$.jsx)(`button`,{onClick:()=>f(e.value),className:`px-3 py-1 text-sm rounded-md transition-colors ${d===e.value?`bg-bambu-green text-white`:``}`,style:d===e.value?void 0:{color:V},children:e.label},e.value))})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-4 gap-4 max-[550px]:grid-cols-2`,children:m===`humidity`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-2`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ne(F)},children:F==null?`—`:`${F}%`}),(0,$.jsx)(te,{trend:R})]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-4`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ae},children:x?.avg_humidity==null?`—`:`${x.avg_humidity}%`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-1`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-green-500`,children:x?.min_humidity==null?`—`:`${x.min_humidity}%`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-3`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:x?.max_humidity==null?`—`:`${x.max_humidity}%`})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-2`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:z(I)},children:I==null?`—`:`${I}°C`}),(0,$.jsx)(te,{trend:ee})]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-4`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ae},children:x?.avg_temperature==null?`—`:`${x.avg_temperature}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-1`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-blue-500`,children:x?.min_temperature==null?`—`:`${x.min_temperature}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-3`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:x?.max_temperature==null?`—`:`${x.max_temperature}°C`})]})]})}),(0,$.jsx)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:B},children:S?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center`,style:{color:V},children:u(`common.loading`,`Loading...`)}):C?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center text-red-500`,children:u(`common.error`,`Error loading data`)}):D.length===0?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center`,style:{color:V},children:u(`common.noData`,`No data available for this time range`)}):(0,$.jsx)(Qe,{width:`100%`,height:300,children:(0,$.jsxs)(hi,{data:D,children:[(0,$.jsx)(gt,{strokeDasharray:`3 3`,stroke:ie}),(0,$.jsx)(rt,{dataKey:`time`,type:`number`,domain:[Date.now()-b*60*60*1e3,Date.now()],tickFormatter:e=>{let t=new Date(e);return b>24?t.toLocaleDateString([],{day:`numeric`,month:`short`}):t.toLocaleTimeString([],Gt({hour:`2-digit`,minute:`2-digit`},v))},stroke:oe,tick:{fontSize:12}}),(0,$.jsx)(vt,{stroke:oe,tick:{fontSize:12},domain:m===`humidity`?[0,100]:[`auto`,`auto`],tickFormatter:e=>m===`humidity`?`${e}%`:`${e}°C`}),(0,$.jsx)(Re,{contentStyle:{backgroundColor:re,border:`1px solid ${ie}`,borderRadius:`8px`,color:ae},labelFormatter:e=>new Date(e).toLocaleString(void 0,Gt({year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`},v)),formatter:e=>[m===`humidity`?`${e??0}%`:`${e??0}°C`,m===`humidity`?`Humidity`:`Temperature`]}),(0,$.jsx)(O,{}),m===`humidity`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{y:k,stroke:`#22a352`,strokeDasharray:`5 5`,label:{value:`Good`,fill:`#22a352`,fontSize:10}}),(0,$.jsx)(A,{y:j,stroke:`#d4a017`,strokeDasharray:`5 5`,label:{value:`Fair`,fill:`#d4a017`,fontSize:10}})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{y:M,stroke:`#22a352`,strokeDasharray:`5 5`,label:{value:`Good`,fill:`#22a352`,fontSize:10}}),(0,$.jsx)(A,{y:N,stroke:`#d4a017`,strokeDasharray:`5 5`,label:{value:`Fair`,fill:`#d4a017`,fontSize:10}})]}),(0,$.jsx)(pi,{type:`monotone`,dataKey:m,name:m===`humidity`?`Humidity`:`Temperature`,stroke:m===`humidity`?`#3b82f6`:`#f97316`,strokeWidth:2,dot:!1,activeDot:{r:4},connectNulls:!0})]})})}),(0,$.jsx)(`div`,{className:`text-xs text-center`,style:{color:V},children:u(`amsHistory.recordingInfo`,`Data is recorded every 5 minutes while the printer is connected`)})]})]})})}function ra(e,t,n){let r=n===1||e>=128,i=e>=128?e-128:e,a=String.fromCharCode(65+i);return r?`HT·${t+1}`:`${a}·${t+1}`}function ia(e){let t=(e||``).replace(`#`,``).slice(0,6);if(t.length!==6)return`#FFFFFF`;let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);return[n,r,i].some(Number.isNaN)?`#FFFFFF`:(.2126*n+.7152*r+.0722*i)/255>.55?`#1A1A1A`:`#FFFFFF`}function aa({group:e,trayCountByAms:t,innerBg:n,textPrimary:r,textSecondary:i,showExtruderBadge:a,extruderLabel:o}){let s=Mn(e.trayColor||void 0),c=ia(e.trayColor),l=c===`#FFFFFF`?`rgba(0,0,0,0.45)`:`rgba(255,255,255,0.7)`,u=e.members.length;return(0,$.jsxs)(`div`,{className:`relative flex flex-col items-center`,children:[a&&(0,$.jsx)(`span`,{className:`absolute -top-1 -left-1 z-10 w-6 h-6 rounded-full flex items-center justify-center text-xs font-bold shadow`,style:{backgroundColor:r,color:n},"aria-label":o,title:o,children:o}),(0,$.jsxs)(`svg`,{viewBox:`-100 -100 200 200`,className:`w-44 h-44`,children:[(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`95`,fill:`none`,stroke:i,strokeOpacity:`0.25`,strokeWidth:`1`}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`92`,fill:s}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`56`,fill:n}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`56`,fill:`none`,stroke:i,strokeOpacity:`0.3`,strokeWidth:`1`}),(0,$.jsx)(`text`,{x:`0`,y:`-4`,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`14`,fontWeight:`700`,fill:r,children:e.displayName||`—`}),(0,$.jsx)(`text`,{x:`0`,y:`16`,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`11`,fontWeight:`500`,fill:i,children:`${u}× ↻`}),e.members.map((e,n)=>{let r=(n*360/u-90)*Math.PI/180,i=76*Math.cos(r),a=76*Math.sin(r),o=ra(e.amsId,e.slotIdx,t.get(e.amsId)??4),s=Math.max(22,o.length*7+8);return(0,$.jsxs)(`g`,{children:[(0,$.jsx)(`rect`,{x:i-s/2,y:a-9,width:s,height:18,rx:9,ry:9,fill:l}),(0,$.jsx)(`text`,{x:i,y:a,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`12`,fontWeight:`700`,fill:c,children:o})]},`${e.amsId}-${e.slotIdx}`)})]})]})}function oa({isOpen:e,state:t,amsUnits:n,amsExtruderMap:r,isDualNozzle:i,canToggle:a,pending:o,onToggle:s,onClose:c}){let{t:u}=l();if((0,X.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&(e.stopPropagation(),c())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,c]),!e)return null;let d=`var(--bg-secondary)`,f=`var(--border-color)`,p=`var(--text-primary)`,m=`var(--text-secondary)`,h=(()=>{if(!i||!r)return!1;let e=new Set;for(let t of n||[]){let n=r[String(t.id)];if(n!==void 0&&(e.add(Number(n)),e.size>1))return!0}return!1})(),g=wn(n,r,h),_=new Map((n||[]).map(e=>[e.id,e.tray.length])),v=g.filter(e=>e.members.length>=2),y=t===!0,b=t===null;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:c,"data-testid":`ams-backup-modal`,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-2xl max-h-[90vh] overflow-hidden shadow-xl flex flex-col`,style:{backgroundColor:d},onClick:e=>e.stopPropagation(),role:`dialog`,"aria-modal":`true`,"aria-labelledby":`ams-backup-modal-title`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b`,style:{borderColor:f},children:[(0,$.jsx)(`h2`,{id:`ams-backup-modal-title`,className:`text-base font-semibold`,style:{color:p},children:u(`printers.amsBackup.modalTitle`)}),(0,$.jsx)(`button`,{type:`button`,onClick:c,className:`p-1 rounded-md transition-colors hover:bg-black/10`,style:{color:m},"aria-label":u(`common.close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b`,style:{borderColor:f,backgroundColor:`var(--bg-primary)`},children:[(0,$.jsxs)(`div`,{className:`min-w-0 mr-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium`,style:{color:p},children:u(b?`printers.amsBackup.stateUnknown`:y?`printers.amsBackup.stateOn`:`printers.amsBackup.stateOff`)}),(0,$.jsx)(`p`,{className:`text-xs mt-0.5`,style:{color:m},children:u(`printers.amsBackup.modalHelp`)})]}),(0,$.jsx)(hr,{checked:y,onChange:s,disabled:!a||b||o})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto px-5 py-6`,children:v.length===0?(0,$.jsx)(`p`,{className:`text-sm text-center py-8`,style:{color:m},children:u(`printers.amsBackup.modalNoPairs`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-6 justify-items-center`,children:v.map(e=>(0,$.jsx)(aa,{group:e,trayCountByAms:_,innerBg:d,textPrimary:p,textSecondary:m,showExtruderBadge:h,extruderLabel:e.extruder===0?u(`printers.amsBackup.extruderRightShort`):u(`printers.amsBackup.extruderLeftShort`)},e.key))})})]})})}var sa=[{value:`6h`,label:`6h`,hours:6},{value:`24h`,label:`24h`,hours:24},{value:`48h`,label:`48h`,hours:48},{value:`7d`,label:`7d`,hours:168}],ca={nozzle:`#fb923c`,nozzle_2:`#f97316`,bed:`#60a5fa`,chamber:`#34d399`},la={nozzle:`#fed7aa`,nozzle_2:`#fdba74`,bed:`#bfdbfe`,chamber:`#a7f3d0`};function ua({isOpen:e,onClose:t,printerId:n,printerName:r,initialKind:a=`nozzle`,availableKinds:o=[`nozzle`,`bed`,`chamber`]}){let{t:s}=l(),[c,u]=(0,X.useState)(`24h`),[d,f]=(0,X.useState)(a);(0,X.useEffect)(()=>{f(a)},[a]);let{data:m}=p({queryKey:[`settings`],queryFn:i.getSettings}),h=m?.time_format||`system`;(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let g=sa.find(e=>e.value===c)?.hours||24,{data:v,isLoading:y,error:b}=p({queryKey:[`printer-sensor-history`,n,g,o.join(`,`)],queryFn:()=>i.getPrinterSensorHistory(n,g,o),enabled:e,refetchInterval:6e4});if(!e)return null;let x=v?.series.find(e=>e.sensor_kind===d),S=(x?.data||[]).map(e=>({time:(qt(e.recorded_at)||new Date).getTime(),value:e.value,target:e.target})),C=Date.now()-g*60*60*1e3,w=Date.now(),T=[...S];if(T.length>0){let e=T[0];e.time>C&&T.unshift({...e,time:C});let t=T[T.length-1];t.time{let t=e.filter(e=>e!=null);if(t.length<4)return`stable`;let n=t.slice(0,Math.floor(t.length/4)),r=t.slice(-Math.floor(t.length/4)),i=n.reduce((e,t)=>e+t,0)/n.length,a=r.reduce((e,t)=>e+t,0)/r.length-i;return Math.abs(a)<2?`stable`:a>0?`up`:`down`})(T.map(e=>e.value)),M=({trend:e})=>e===`up`?(0,$.jsx)(_,{className:`w-4 h-4 text-red-600 dark:text-red-400`}):e===`down`?(0,$.jsx)(Ke,{className:`w-4 h-4 text-green-600 dark:text-green-400`}):(0,$.jsx)(G,{className:`w-4 h-4 text-gray-400 dark:text-bambu-gray`}),N=`var(--bg-secondary)`,P=`var(--bg-primary)`,F=`var(--border-color)`,I=`var(--text-primary)`,L=`var(--text-secondary)`,R=`var(--text-muted)`,ee=e=>{switch(e){case`nozzle`:return s(`printers.heaterHistory.nozzle`,`Nozzle`);case`nozzle_2`:return s(`printers.heaterHistory.nozzle2`,`Nozzle 2`);case`bed`:return s(`printers.heaterHistory.bed`,`Bed`);case`chamber`:return s(`printers.heaterHistory.chamber`,`Chamber`)}},te=({k:e})=>e===`nozzle`||e===`nozzle_2`?(0,$.jsx)(Bn,{className:`w-4 h-4`}):e===`bed`?(0,$.jsx)(fn,{className:`w-4 h-4`}):(0,$.jsx)(j,{className:`w-4 h-4`});return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,onClick:t,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-4xl max-h-[90vh] overflow-hidden shadow-xl`,style:{backgroundColor:N},onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b`,style:{borderColor:F},children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,style:{color:I},children:s(`printers.heaterHistory.title`,`Heater History`)}),(0,$.jsx)(`p`,{className:`text-sm`,style:{color:L},children:r})]}),(0,$.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg transition-colors`,style:{color:L},"aria-label":s(`common.close`,`Close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`p-6 space-y-6 overflow-y-auto max-h-[calc(90vh-80px)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between max-[550px]:flex-col max-[550px]:items-start max-[550px]:gap-3`,children:[(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:P},children:o.map(e=>(0,$.jsxs)(`button`,{onClick:()=>f(e),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${d===e?`text-white`:``}`,style:d===e?{backgroundColor:ca[e]}:{color:L},children:[(0,$.jsx)(te,{k:e}),ee(e)]},e))}),(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:P},children:sa.map(e=>(0,$.jsx)(`button`,{onClick:()=>u(e.value),className:`px-3 py-1 text-sm rounded-md transition-colors ${c===e.value?`bg-bambu-green text-white`:``}`,style:c===e.value?void 0:{color:L},children:e.label},e.value))})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-4 gap-4 max-[550px]:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ca[d]},children:D==null?`—`:`${Math.round(D)}°C`}),(0,$.jsx)(M,{trend:A})]}),k!=null&&k>0&&(0,$.jsxs)(`p`,{className:`text-xs mt-1`,style:{color:L},children:[s(`common.target`,`Target`),`: `,Math.round(k),`°C`]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.avg_value==null?`—`:`${x.avg_value}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.min_value==null?`—`:`${Math.round(x.min_value)}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.max_value==null?`—`:`${Math.round(x.max_value)}°C`})]})]}),(0,$.jsx)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:y?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center`,style:{color:L},children:s(`common.loading`,`Loading...`)}):b?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center text-red-700 dark:text-red-400`,children:s(`printers.heaterHistory.error`,`Failed to load history`)}):T.length===0?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center`,style:{color:L},children:s(`printers.heaterHistory.empty`,`No data recorded yet`)}):(0,$.jsx)(Qe,{width:`100%`,height:300,children:(0,$.jsxs)(hi,{data:T,margin:{top:5,right:10,left:0,bottom:5},children:[(0,$.jsx)(gt,{strokeDasharray:`3 3`,stroke:F}),(0,$.jsx)(rt,{dataKey:`time`,type:`number`,domain:[C,w],tickFormatter:e=>new Date(e).toLocaleTimeString([],Gt({hour:`2-digit`,minute:`2-digit`},h)),stroke:R,fontSize:11}),(0,$.jsx)(vt,{stroke:R,fontSize:11,domain:[0,`auto`],tickFormatter:e=>`${Math.round(e)}°`}),(0,$.jsx)(Re,{contentStyle:{backgroundColor:N,border:`1px solid ${F}`,borderRadius:6,color:I},labelFormatter:e=>new Date(e).toLocaleString(void 0,Gt({month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`},h)),formatter:e=>e==null?`—`:`${Math.round(Number(e))}°C`}),(0,$.jsx)(O,{}),(0,$.jsx)(pi,{type:`monotone`,dataKey:`value`,name:s(`common.current`,`Current`),stroke:ca[d],strokeWidth:2,dot:!1,isAnimationActive:!1}),(0,$.jsx)(pi,{type:`stepAfter`,dataKey:`target`,name:s(`common.target`,`Target`),stroke:la[d],strokeDasharray:`4 4`,strokeWidth:1.5,dot:!1,isAnimationActive:!1})]})})})]})]})})}function da({data:e,children:t,disabled:n,className:r=``,spoolman:i,inventory:a,configureSlot:o,actions:s}){let{t:c}=l(),u=Tn(),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(`top`),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),S=(0,X.useRef)(null),C=(0,X.useRef)(null),w=(0,X.useRef)(null),T=()=>{let t=e.trayUuid;t&&(navigator.clipboard&&window.isSecureContext?navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),2e3)}).catch(()=>{E(t)}):E(t))},E=e=>{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{document.execCommand(`copy`),v(!0),setTimeout(()=>v(!1),2e3)}catch{console.error(`Failed to copy to clipboard`)}document.body.removeChild(t)};(0,X.useLayoutEffect)(()=>{if(!d){g(null);return}let e=()=>{if(!S.current||!C.current)return;let e=S.current.getBoundingClientRect(),t=C.current.offsetHeight,n=C.current.offsetWidth,r=e.top-56,i=window.innerHeight-e.bottom,a=rr?`bottom`:`top`,o=e.left+e.width/2,s=Math.max(8,Math.min(o-n/2,window.innerWidth-n-8)),c=a===`top`?e.top-t-8:e.bottom+8;m(a),g({top:c,left:s})};e();let t=requestAnimationFrame(e);return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{cancelAnimationFrame(t),window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[d]);let D=()=>{n||(w.current&&clearTimeout(w.current),w.current=setTimeout(()=>f(!0),80))},O=()=>{w.current&&clearTimeout(w.current),w.current=setTimeout(()=>f(!1),100)},k=()=>{w.current&&clearTimeout(w.current),f(!1)};(0,X.useEffect)(()=>()=>{w.current&&clearTimeout(w.current)},[]);let A=e=>e<=15?`#ef4444`:e<=30?`#f97316`:e<=50?`#eab308`:`#22c55e`,j=e.colorHex?`#${e.colorHex.replace(`#`,``)}`:null,M=(a?.assignedSpool?.color_name_is_synthesized?void 0:qn(a?.assignedSpool?.color_name??null,null)?.trim())||e.colorName,N=a?.assignedSpool?qn(a.assignedSpool.color_name,a.assignedSpool.rgba??null,a.assignedSpool.color_name_is_synthesized):null,P=a?.assignedSpool?.remainingWeightGrams??null,I=a?.assignedSpool??null,L=Yt(I?.extra_colors),R=!!I?.effect_type,ee=!!I&&(L.length>0||R),te=ee?Jt({effectSize:`card`,rgba:I?.rgba??j,extraColors:I?.extra_colors,effectType:I?.effect_type,subtype:I?.subtype}):null,ne=L.length>1,re=ee?L.length===1?L[0]:I?.rgba??j:j;return(0,$.jsxs)(`div`,{ref:S,"data-testid":`filament-slot`,className:`relative ${r}`,onMouseEnter:D,onMouseLeave:O,children:[t,d&&(0,gi.createPortal)((0,$.jsxs)(`div`,{ref:C,className:`fixed z-[60]`,style:{top:h?.top??-9999,left:h?.left??-9999,maxWidth:`calc(100vw - 24px)`,visibility:h?`visible`:`hidden`},onMouseEnter:D,onMouseLeave:O,children:[(0,$.jsxs)(`div`,{className:`
w-52 bg-bambu-dark-secondary border border-bambu-dark-tertiary
rounded-lg shadow-xl overflow-hidden
backdrop-blur-sm
diff --git a/static/assets/ProfilesPage-CN3SHdd_.js b/static/assets/ProfilesPage-v1drfQ01.js
similarity index 99%
rename from static/assets/ProfilesPage-CN3SHdd_.js
rename to static/assets/ProfilesPage-v1drfQ01.js
index eb1d17572..ea80f6658 100644
--- a/static/assets/ProfilesPage-CN3SHdd_.js
+++ b/static/assets/ProfilesPage-v1drfQ01.js
@@ -1,4 +1,4 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as c}from"./createLucideIcon-Yo2YoYjm.js";import{t as l}from"./arrow-right-Da96kh4S.js";import{t as u}from"./arrow-up-Dam8cLfE.js";import{t as d}from"./check-D1Pn8T1J.js";import{a as f,i as p,r as m}from"./info-DcT0QU8O.js";import{n as h}from"./ToastContext-VFOrCCoA.js";import{t as g}from"./copy-3N5VKzXz.js";import{t as _}from"./droplet-PpnaB65N.js";import{t as v}from"./eye-off-B6dY82pM.js";import{t as y}from"./funnel-BtI48m95.js";import{t as b}from"./gauge-xO5PdXj0.js";import{t as x}from"./git-compare-DbgnTP6k.js";import{t as S}from"./hard-drive-CN9rq6Uq.js";import{t as C}from"./list-CBXEiN6g.js";import{t as w}from"./loader-circle-CB4leTZa.js";import{t as T}from"./log-in-D7NdqHOf.js";import{t as E}from"./minus-D0aY9wbr.js";import{t as ee}from"./search-BpAJdxRw.js";import{t as te}from"./settings-2-DYB5IzKV.js";import{t as D}from"./sparkles-AUof3WTI.js";import{t as O}from"./sticky-note-C75KNLfY.js";import{t as k}from"./triangle-alert-gIik0G2C.js";import{t as A}from"./x-Dctff5l9.js";import{n as j,t as M}from"./Card-OUAj0Ayh.js";import{t as N}from"./Button-pwVKPiYn.js";import{u as P}from"./date-G9KUauqz.js";import{$t as F,At as I,Bt as L,Cn as R,Ct as ne,Dn as z,En as B,Jt as re,Kt as ie,Lt as V,On as ae,Rt as oe,Sn as H,Ut as U,Zt as se,an as W,cn as ce,kt as le,ln as G,wn as ue,yt as de}from"./index-Bw-_P2Fg.js";import{p as K,u as q}from"./utils-D29gNIio.js";import{t as fe}from"./useCancellableTimeout-CXuQGelB.js";var J=c(`equal`,[[`line`,{x1:`5`,x2:`19`,y1:`9`,y2:`9`,key:`1nwqeh`}],[`line`,{x1:`5`,x2:`19`,y1:`15`,y2:`15`,key:`g8yjpy`}]]),pe=c(`sliders-vertical`,[[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M12 21v-9`,key:`17s77i`}],[`path`,{d:`M12 8V3`,key:`13r4qs`}],[`path`,{d:`M17 16h4`,key:`h1uq16`}],[`path`,{d:`M19 12V3`,key:`o1uvq1`}],[`path`,{d:`M19 21v-5`,key:`qua636`}],[`path`,{d:`M3 14h4`,key:`bcjad9`}],[`path`,{d:`M5 10V3`,key:`cb8scm`}],[`path`,{d:`M5 21v-7`,key:`1w1uti`}]]),Y=e(n(),1),X={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};function me(e){let t=(e||``).toUpperCase().trim();return t&&(X[t]||X[t.replace(/[-\s]?CF$/,``)]||X[t.replace(/\+$/,``)]||X[t.split(/[-\s]/)[0]])||``}function he(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var ge={local:0,orca_cloud:1,cloud:2,builtin:3};function _e(e){let{localPresets:t,orcaProfiles:n,cloudSettings:r,builtinFilaments:i}=e,a=[],o=e=>e.trim().toLowerCase(),s=new Set,c=new Set,l=new Set,u=(e,t,...n)=>{let r=n.filter(e=>!!e);if(r.some(e=>s.has(e)))return!1;let i=`${e}|${o(t)}`;return c.has(i)?!1:(r.forEach(e=>s.add(e)),c.add(i),l.add(o(t)),!0)};for(let e of t??[]){let t=he(e.name),n=e.filament_type||q(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:me(n),filamentType:n||``})}for(let e of n??[]){let t=he(e.name),n=q(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:me(n),filamentType:n})}for(let e of r??[]){let t=he(e.name),n=e.setting_id.startsWith(`GFS`)?K(e.setting_id):``;u(`cloud`,t,e.setting_id,n||void 0)&&a.push({id:e.setting_id,name:t,source:`cloud`,filamentId:n,filamentType:q(t).material})}for(let e of i??[]){let t=e.filament_id.startsWith(`GF`)?`GFS${e.filament_id.slice(2)}`:e.filament_id;l.has(o(e.name))||u(`builtin`,e.name,e.filament_id,t)&&a.push({id:`builtin_${e.filament_id}`,name:e.name,source:`builtin`,filamentId:e.filament_id,filamentType:q(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):ge[e.source]-ge[t.source])}async function ve(e,t){if(e.filamentId)return e.filamentId;if(e.source!==`cloud`||!t)return``;try{return(await t(e.id)).filament_id||``}catch{return``}}var Z=t(),ye=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),be=`HS00`,xe=`HH00`,Se=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:be},Q=e=>Se(e)===xe?`HF`:`S`,Ce=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function we({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=Q(e.nozzle_id),c=e.nozzle_diameter;return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,Z.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,Z.jsx)(oe,{className:`w-4 h-4 text-bambu-green`}):(0,Z.jsx)(V,{className:`w-4 h-4`})}),(0,Z.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:ye(e.k_value)}),(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,Z.jsx)(`span`,{title:`Has note`,children:(0,Z.jsx)(O,{className:`w-3 h-3 text-yellow-500`})}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,Z.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,Z.jsx)(g,{className:`w-4 h-4`})})]})}function Te({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:a=[],builtinFilaments:o=[],filamentPresets:c=[],isDualNozzle:l=!1,supportsFlowType:u=!0,initialNote:d=``,initialNoteKey:f=null,onClose:p,onSave:m,onSaveNote:g,hasPermission:_}){let{t:v}=i(),{showToast:y}=h(),[x,S]=(0,Y.useState)(e?.name||``),[C,T]=(0,Y.useState)(e?.k_value?ye(e.k_value):`0.020`),[E,te]=(0,Y.useState)(e?.filament_id||``),[D,O]=(0,Y.useState)(e?Se(e.nozzle_id):be),[k,P]=(0,Y.useState)(e?.nozzle_diameter||n),[F,L]=(0,Y.useState)(e?[e.extruder_id]:l?[0,1]:[0]),[R,ne]=(0,Y.useState)(!1),[z,B]=(0,Y.useState)({current:0,total:0}),[re,ie]=(0,Y.useState)(d),[V,ae]=(0,Y.useState)(``),{schedule:oe}=fe(),H=Y.useMemo(()=>e?.filament_id?o.find(t=>t.filament_id===e.filament_id)?.name||Ce(a.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,a,o]),U=Y.useMemo(()=>{let e=[[`local`,v(`kProfiles.modal.source.local`)],[`orca_cloud`,v(`kProfiles.modal.source.orcaCloud`)],[`cloud`,v(`kProfiles.modal.source.bambuCloud`)],[`builtin`,v(`kProfiles.modal.source.builtin`)]],t=V.trim().toLowerCase(),n=t?c.filter(e=>e.name.toLowerCase().includes(t)):c;return e.map(([e,t])=>({source:e,label:t,items:n.filter(t=>t.source===e)})).filter(e=>e.items.length>0)},[c,V,v]),se=s({mutationFn:e=>(console.log(`[KProfile] Calling API...`),r.setKProfile(t,e)),onSuccess:(t,n)=>{if(console.log(`[KProfile] Save success:`,t),y(v(`kProfiles.toast.profileSaved`)),g&&re!==d){let t;t=re===``&&f?f:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${x}_${n.filament_id}`,g(t,re)}ne(!0),oe(()=>{ne(!1),m()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),y(e.message,`error`),ne(!1)}}),W=s({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),r.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),y(v(`kProfiles.toast.profileDeleted`)),ne(!0),oe(()=>{ne(!1),p()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),y(e.message,`error`),ne(!1)}}),[ce,le]=(0,Y.useState)(!1),G=()=>{e&&W.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,Z.jsxs)(M,{className:`w-full max-w-md relative`,children:[R&&(0,Z.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:z.total>1?v(`kProfiles.modal.savingExtruder`,{current:z.current,total:z.total}):v(`kProfiles.modal.syncing`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:v(`kProfiles.modal.pleaseWait`)})]}),(0,Z.jsxs)(j,{className:`p-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:v(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,Z.jsx)(`button`,{onClick:p,className:`text-bambu-gray hover:text-white transition-colors`,disabled:R,children:(0,Z.jsx)(A,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),l&&!e&&F.length===0){y(v(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let i=parseFloat(C).toFixed(6),a=`${D}-${k}`,o=e&&e.nozzle_id||a,s=e?e.nozzle_diameter:k,u=e?.filament_id||``;if(!e){let e=c.find(e=>e.id===E);if(!e){y(v(`kProfiles.toast.selectFilament`),`error`);return}if(u=await ve(e,r.getCloudSettingDetail),!u){y(v(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||F.length===1){let t={name:x,k_value:i,filament_id:u,nozzle_id:o,nozzle_diameter:s,extruder_id:e?e.extruder_id:F[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),se.mutate(t);return}ne(!0),B({current:1,total:F.length});let d=F.map(e=>({name:x,k_value:i,filament_id:u,nozzle_id:a,nozzle_diameter:k,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${d.length} profiles in batch:`,d);try{await r.setKProfilesBatch(t,d),y(v(`kProfiles.toast.profilesSaved`,{count:F.length})),g&&re&&g(`name_${x}_${u}`,re)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),y(v(`kProfiles.toast.failedToSaveBatch`),`error`),ne(!1),B({current:0,total:0});return}B({current:F.length,total:F.length}),oe(()=>{ne(!1),B({current:0,total:0}),m()},3e3)},className:`p-4 space-y-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.profileName`)}),(0,Z.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:v(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.kValue`)}),(0,Z.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:C,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&T(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||T((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:v(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.kValueHelp`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.filament`)}),e?(0,Z.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:H||e.filament_id}):(0,Z.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`relative border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:V,onChange:e=>ae(e.target.value),placeholder:v(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,Z.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:U.length===0?(0,Z.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:c.length===0?v(`kProfiles.modal.noFilamentsHelp`):v(`kProfiles.modal.noFilamentMatches`)}):U.map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-secondary border-y border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-bambu-green`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:e.items.length})]}),e.items.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{te(e.id),x||S(`${D===xe?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${E===e.id?`bg-bambu-green/20 text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))]},e.source))})]})]}),(0,Z.jsxs)(`div`,{className:u?`grid grid-cols-2 gap-4`:``,children:[(0,Z.jsxs)(`div`,{className:u?``:`hidden`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.flowType`)}),(0,Z.jsxs)(`select`,{value:D,onChange:t=>{let n=t.target.value;if(O(n),!e&&E&&!x){let e=c.find(e=>e.id===E);e&&S(`${n===xe?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,Z.jsx)(`option`,{value:xe,children:v(`kProfiles.modal.highFlow`)}),(0,Z.jsx)(`option`,{value:be,children:v(`kProfiles.modal.standard`)})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.nozzleSize`)}),(0,Z.jsxs)(`select`,{value:k,onChange:e=>P(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,Z.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,Z.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,Z.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,Z.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),l&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,Z.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?v(`kProfiles.modal.left`):v(`kProfiles.modal.right`)}):(0,Z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(1),onChange:e=>{e.target.checked?L([...F,1]):L(F.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,Z.jsx)(`span`,{className:`text-white`,children:v(`kProfiles.modal.left`)})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(0),onChange:e=>{e.target.checked?L([...F,0]):L(F.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,Z.jsx)(`span`,{className:`text-white`,children:v(`kProfiles.modal.right`)})]})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.notes`)}),(0,Z.jsx)(`textarea`,{value:re,onChange:e=>ie(e.target.value),placeholder:v(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none`}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.notesHelp`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:()=>le(!0),disabled:W.isPending||R||!_(`kprofiles:delete`),title:_(`kprofiles:delete`)?void 0:v(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:W.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`})}),(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:p,disabled:R,className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(N,{type:`submit`,disabled:se.isPending||R||!_(e?`kprofiles:update`:`kprofiles:create`),title:_(e?`kprofiles:update`:`kprofiles:create`)?void 0:v(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[se.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(b,{className:`w-4 h-4`}),v(`common.save`)]})]})]})]})]}),ce&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,Z.jsx)(M,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(j,{className:`p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,Z.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,Z.jsx)(I,{className:`w-5 h-5 text-red-500`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:v(`kProfiles.deleteConfirm.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:v(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:v(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(N,{variant:`secondary`,onClick:()=>le(!1),className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(N,{onClick:()=>{le(!1),G()},disabled:W.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[W.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),v(`common.delete`)]})]})]})})})]})}var Ee={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function De(){let{t:e}=i(),{showToast:t}=h(),{hasPermission:n}=de(),[a,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(()=>localStorage.getItem(Ee.NOZZLE_DIAMETER)||`0.4`),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(``),[x,S]=(0,Y.useState)(`all`),[C,T]=(0,Y.useState)(`all`),[E,te]=(0,Y.useState)(()=>localStorage.getItem(Ee.SORT_OPTION)||`name`),[D,O]=(0,Y.useState)(!1),[k,P]=(0,Y.useState)(new Set),[F,L]=(0,Y.useState)(!1),[R,z]=(0,Y.useState)(!1),B=(0,Y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,Y.useEffect)(()=>{localStorage.setItem(Ee.NOZZLE_DIAMETER,c)},[c]),(0,Y.useEffect)(()=>{localStorage.setItem(Ee.SORT_OPTION,E)},[E]);let{data:V,isLoading:ae}=o({queryKey:[`printers`],queryFn:r.getPrinters}),{data:H,isLoading:U,isFetching:W,error:ce,refetch:G}=o({queryKey:[`kprofiles`,a,c],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,a,`nozzle`,c);let e=await r.getKProfiles(a,c);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!a,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:K}=o({queryKey:[`builtinFilaments`],queryFn:()=>r.getBuiltinFilaments(),staleTime:3e5}),{data:q}=o({queryKey:[`filamentIdMap`],queryFn:()=>r.getFilamentIdMap(),staleTime:3e5}),{data:fe}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets(),retry:!1}),{data:J}=o({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>r.orcaCloudListProfiles(),retry:!1}),{data:pe}=o({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),retry:!1}),{data:X,refetch:me}=o({queryKey:[`kprofile-notes`,a],queryFn:()=>r.getKProfileNotes(a),enabled:!!a,staleTime:3e4}),he=ce?.message?.includes(`not connected`);(0,Y.useEffect)(()=>{if(!a&&V&&V.length>0){let e=V.find(e=>e.is_active);e&&s(e.id)}},[a,V]),(0,Y.useEffect)(()=>{if(a){let e=setTimeout(()=>{G()},150);return()=>clearTimeout(e)}},[a,c]);let ge=V?.filter(e=>e.is_active)||[],ve=Y.useMemo(()=>{let e=new Map;if(K)for(let t of K)e.set(t.filament_id,t.name);if(q)for(let[t,n]of Object.entries(q))e.has(t)||e.set(t,n);return e},[K,q]),ye=Y.useMemo(()=>Array.from(ve.entries()).map(([e,t])=>({filament_id:e,name:t})),[ve]),xe=Y.useMemo(()=>_e({localPresets:fe?.filament,orcaProfiles:J?.filament,cloudSettings:pe?.filament,builtinFilaments:K}),[fe?.filament,J?.filament,pe?.filament,K]),Se=Y.useCallback(e=>ve.get(e.filament_id)||Ce(e.name),[ve]),Q=Y.useMemo(()=>H?.profiles?H.profiles.filter(e=>{let t=v.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=x===`all`||x===`left`&&e.extruder_id===1||x===`right`&&e.extruder_id===0,i=C===`all`||C===`hf`&&e.nozzle_id.startsWith(`HH`)||C===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(E){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return Se(e).localeCompare(Se(t));default:return e.name.localeCompare(t.name)}}):[],[H?.profiles,v,x,C,E,Se]),De=V?.find(e=>e.id===a),$=De?.nozzle_count===2,Oe=De?.supports_nozzle_flow_type??!0;(0,Y.useEffect)(()=>{Oe||T(`all`)},[Oe]),(0,Y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||u||f||g||(e.key===`r`||e.key===`R`?(e.preventDefault(),G()):e.key===`n`||e.key===`N`?(e.preventDefault(),p(!0)):e.key===`Escape`&&D&&(e.preventDefault(),O(!1),P(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,f,g,D,G]);let ke=(0,Y.useCallback)(()=>{if(!H?.profiles||H.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:De?.name||`Unknown`,nozzle_diameter:c,profiles:H.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`kprofiles_${De?.name||`printer`}_${c}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:H.profiles.length}))},[H?.profiles,De,c,t,e]),Ae=(0,Y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await r.setKProfile(a,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${be}-${c}`,nozzle_diameter:e.nozzle_diameter||c,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),G()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[a,c,t,G,e]),je=(0,Y.useCallback)(e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Me=(0,Y.useCallback)(()=>{P(new Set(Q.map(e=>B(e))))},[Q,B]),Ne=(0,Y.useCallback)(()=>{k.size!==0&&L(!0)},[k.size]),Pe=(0,Y.useCallback)(async()=>{let n=Q.filter(e=>k.has(B(e)));z(!0);let i=0;for(let e of n)try{await r.deleteKProfile(a,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),z(!1),L(!1),O(!1),P(new Set),G()},[a,k,Q,t,G,B,e]),Fe=(0,Y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),Ie=(0,Y.useCallback)(async(n,i)=>{if(a)try{await r.setKProfileNote(a,n,i),me()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[a,me,t,e]),Le=(0,Y.useCallback)(e=>{if(!X?.notes)return{note:``,key:null};let t=Fe(e);for(let e of t)if(X.notes[e])return{note:X.notes[e],key:e};return{note:``,key:null}},[X,Fe]),Re=(0,Y.useCallback)(e=>Le(e).note,[Le]);return ae?(0,Z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!V||V.length===0?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(m,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):ge.length===0?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(re,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,Z.jsxs)(Z.Fragment,{children:[W&&!U&&(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,Z.jsx)(w,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,Z.jsx)(`select`,{value:a||``,onChange:e=>s(parseInt(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:ge.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Z.jsxs)(`div`,{className:`w-32`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,Z.jsxs)(`select`,{value:c,onChange:e=>l(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,Z.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,Z.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,Z.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,Z.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>G(),disabled:W||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,Z.jsx)(ie,{className:`w-4 h-4 ${W?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,Z.jsxs)(N,{onClick:()=>p(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,Z.jsx)(se,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),$&&(0,Z.jsx)(`div`,{className:`w-36`,children:(0,Z.jsxs)(`select`,{value:x,onChange:e=>S(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,Z.jsx)(`option`,{value:`all`,children:e(`kProfiles.allExtruders`)}),(0,Z.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,Z.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),Oe&&(0,Z.jsx)(`div`,{className:`w-32`,children:(0,Z.jsxs)(`select`,{value:C,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 focus:border-bambu-green focus:outline-none`,children:[(0,Z.jsx)(`option`,{value:`all`,children:e(`kProfiles.allFlow`)}),(0,Z.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,Z.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,Z.jsx)(`div`,{className:`w-32`,children:(0,Z.jsxs)(`select`,{value:E,onChange:e=>te(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,Z.jsx)(`option`,{value:`name`,children:e(`kProfiles.sortName`)}),(0,Z.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,Z.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:ke,disabled:!H?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,Z.jsx)(ue,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:Ae,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,Z.jsx)(le,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,Z.jsx)(`div`,{className:`flex-1`}),D?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:Me,children:[(0,Z.jsx)(oe,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:Ne,disabled:k.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,k.size,`)`]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>{O(!1),P(new Set)},children:[(0,Z.jsx)(A,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>O(!0),disabled:!Q.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,Z.jsx)(oe,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),U?(0,Z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):he?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(ne,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>G(),children:[(0,Z.jsx)(ie,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):Q.length>0?$?(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.filter(e=>e.extruder_id===1).map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.filter(e=>e.extruder_id===0).map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))})]})]}):(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))}):v||x!==`all`||C!==`all`?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(ee,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(b,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:c})}),(0,Z.jsxs)(N,{onClick:()=>p(!0),children:[(0,Z.jsx)(se,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),u&&a&&(()=>{let{note:e,key:t}=Le(u);return(0,Z.jsx)(Te,{profile:u,printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,initialNote:e,initialNoteKey:t,onSaveNote:Ie,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),d(null),G()},onSave:()=>{d(null),G()}})})(),f&&a&&(0,Z.jsx)(Te,{printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,onSaveNote:Ie,hasPermission:n,onClose:()=>{p(!1),G()},onSave:()=>{p(!1),G()}}),g&&a&&(0,Z.jsx)(Te,{printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,onSaveNote:Ie,hasPermission:n,profile:{...g,slot_id:0,name:`${g.name} (Copy)`},onClose:()=>{_(null),G()},onSave:()=>{_(null),G()}}),F&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(M,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(j,{className:`p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,Z.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,Z.jsx)(I,{className:`w-5 h-5 text-red-500`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:k.size})}),(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(N,{variant:`secondary`,onClick:()=>L(!1),disabled:R,className:`flex-1`,children:e(`common.cancel`)}),(0,Z.jsxs)(N,{onClick:Pe,disabled:R,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[R?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var $=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],Oe={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function ke(e){let t=e.toUpperCase();for(let e of $)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function Ae(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of $){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function je({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:a}=i(),{hasPermission:o}=de(),s=e.filament_type||ke(e.name),c=e.filament_vendor||Ae(e.name),l=null,u=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(l=n.replace(`#`,``).slice(0,6),u=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(l=t.replace(`#`,``).slice(0,6),u=!0)}return!l&&s&&(l=Oe[s.toUpperCase()]||null),(0,Z.jsx)(M,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,Z.jsxs)(j,{className:`p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,Z.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!u&&!l?`opacity-25`:u?``:`opacity-50`}`,style:{backgroundColor:l?`#${l}`:`#666`}}),(0,Z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s&&(0,Z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:s}),c&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c}),(0,Z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:a(`profiles.localProfiles.badge`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[o(`settings:update`)&&(0,Z.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:a(`profiles.localProfiles.delete`),children:(0,Z.jsx)(I,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,Z.jsx)(p,{className:`w-3.5 h-3.5`}):(0,Z.jsx)(f,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,Z.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[s&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.filamentType`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:s})]}),c&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.vendor`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:c})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.nozzleTemp`)}),(0,Z.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.cost`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.density`)}),(0,Z.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.pressureAdvance`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.compatiblePrinters`)}),(0,Z.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.inheritsFrom`)}),(0,Z.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.source`)}),(0,Z.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function Me(){let{t:e}=i(),{hasPermission:t}=de(),n=a(),{showToast:c}=h(),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(null),[p,g]=(0,Y.useState)(!1),[v,y]=(0,Y.useState)(null),{data:b,isLoading:x}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets()}),C=s({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await r.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let r=0,i=0,a=0;for(let e of t)r+=e.imported,i+=e.skipped,a+=e.errors.length;r>0&&c(e(`profiles.localProfiles.toast.importSuccess`,{count:r})),i>0&&c(e(`profiles.localProfiles.toast.importSkipped`,{count:i}),`warning`),a>0&&c(e(`profiles.localProfiles.toast.importError`,{count:a}),`error`)},onError:e=>{c(e.message,`error`)}}),T=s({mutationFn:e=>r.deleteLocalPreset(e),onSuccess:(t,r)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==r),printer:e.printer.filter(e=>e.id!==r),process:e.process.filter(e=>e.id!==r)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),y(null),c(e(`profiles.localProfiles.toast.deleted`))}}),E=(0,Y.useCallback)(e=>{!e||e.length===0||C.mutate(e)},[C]),D=(0,Y.useCallback)(e=>{e.preventDefault(),g(!1),E(e.dataTransfer.files)},[E]),O=(0,Y.useCallback)(e=>{if(!l)return e;let t=l.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[l]),k=(0,Y.useMemo)(()=>O(b?.filament||[]),[b?.filament,O]),A=(0,Y.useMemo)(()=>O(b?.printer||[]),[b?.printer,O]),j=(0,Y.useMemo)(()=>O(b?.process||[]),[b?.process,O]),M=k.length+A.length+j.length,P=(b?.filament?.length??0)+(b?.printer?.length??0)+(b?.process?.length??0)>0;return x?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,Z.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:D,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${p?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,Z.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>E(e.target.files)}),C.isPending?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Z.jsx)(w,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(le,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,Z.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),P&&(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!P&&!x&&(0,Z.jsxs)(`div`,{className:`text-center py-12`,children:[(0,Z.jsx)(S,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),P&&M===0&&!x&&(0,Z.jsxs)(`div`,{className:`text-center py-12`,children:[(0,Z.jsx)(ee,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),M>0&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[k.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(_,{className:`w-4 h-4 text-bambu-green`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,k.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:k.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),j.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(ce,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,j.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:j.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),A.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(te,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,A.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:A.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]})]}),v!==null&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(m,{className:`w-5 h-5 text-red-600 dark:text-red-400`}),(0,Z.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(N,{variant:`secondary`,size:`sm`,onClick:()=>y(null),children:e(`profiles.localProfiles.cancel`)}),(0,Z.jsxs)(N,{variant:`danger`,size:`sm`,onClick:()=>T.mutate(v),disabled:T.isPending,children:[T.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function Ne(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function Pe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(`all`),[u,d]=(0,Y.useState)(`all`),[f,p]=(0,Y.useState)(`all`),[m,h]=(0,Y.useState)(`all`),[g,v]=(0,Y.useState)(`all`),[b,x]=(0,Y.useState)(null),S=(0,Y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:Ne(e.name)})),[e]),C=(0,Y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return S.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[S,i]),w=(0,Y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),T=(0,Y.useMemo)(()=>S.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!w)return!0;let t=e.meta.printer?.toLowerCase()||``,n=w.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[S,c,u,w,f,m,g,o]),E=()=>{l(`all`),d(`all`),p(`all`),h(`all`),v(`all`),s(``)},D=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,O=e.filament.length+e.printer.length+e.process.length,k=e=>T.filter(t=>t.type===e);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,Z.jsx)(`div`,{className:`flex gap-2`,children:(0,Z.jsxs)(N,{variant:`secondary`,onClick:n,disabled:r,children:[(0,Z.jsx)(ie,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(y,{className:`w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:O},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),C.printers.length>0&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),C.nozzles.length>0&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.nozzles.map(e=>({value:e,label:e}))],onChange:p}),C.filaments.length>0&&(c===`all`||c===`filament`)&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.filaments.map(e=>({value:e,label:e}))],onChange:h}),C.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.layerHeights.map(e=>({value:e,label:e}))],onChange:v}),D&&(0,Z.jsx)(`button`,{onClick:E,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(ae,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,P(t.toISOString(),`system`,a)]}),(0,Z.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:T.length,total:O})})]}),T.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(ce,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),D&&(0,Z.jsx)(`button`,{onClick:E,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(_,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:k(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:x}),(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(te,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:k(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:x}),(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(re,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:k(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:x})]}),b&&(0,Z.jsx)(Le,{setting:b,onClose:()=>x(null),t:a})]})}function Fe({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,Z.jsx)(Ie,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function Ie({preset:e,onClick:t}){return(0,Z.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function Le({setting:e,onClose:t,t:n}){let{data:i,isLoading:a,error:s}=o({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>r.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,Z.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,Z.jsx)(A,{className:`w-5 h-5`})})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:a?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):s?(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:s.message}):i?(0,Z.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(i.setting,null,2)}):(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function Re(){let{t:e}=i(),t=a(),{showToast:n}=h(),{hasPermission:c}=de(),l=c(`orca_cloud:auth`),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(5e3),[m,g]=(0,Y.useState)(null),{data:_,isLoading:v}=o({queryKey:[`orcaCloudStatus`],queryFn:r.orcaCloudStatus}),y=!!_?.connected,{data:b,isLoading:x,refetch:S,isRefetching:C,error:T,dataUpdatedAt:E}=o({queryKey:[`orcaCloudProfiles`],queryFn:r.orcaCloudListProfiles,enabled:y,retry:!1,staleTime:1e3*60*5}),{data:ee=[]}=o({queryKey:[`printers`],queryFn:r.getPrinters,enabled:y}),[te,D]=(0,Y.useState)();(0,Y.useEffect)(()=>{E&&D(new Date(E))},[E]);let O=()=>{d(null),p(5e3)},k=t=>{t===`access_denied`?g(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&g(e(`profiles.orcaCloud.errors.expired`)),O()},A=s({mutationFn:r.orcaCloudDeviceStart,onSuccess:e=>{g(null),p(Math.max(1,e.interval)*1e3),d(e)},onError:t=>{g(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),j=s({mutationFn:r.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:M,error:P}=o({queryKey:[`orcaCloudDevicePoll`,u?.user_code??`none`],queryFn:r.orcaCloudDevicePoll,enabled:u!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:u===null?!1:f}),F=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{if(!u||!M)return;let r=M.status;if(r===`slow_down`){p(e=>e+5e3);return}r!==`authorization_pending`&&F.current!==r&&(F.current=r,r===`complete`?(O(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.connectedShort`))):k(r))},[M,u]),(0,Y.useEffect)(()=>{u&&P&&(g(e(`profiles.orcaCloud.errors.pollFailed`)),O())},[P,u]),(0,Y.useEffect)(()=>{u&&(F.current=null)},[u]),v?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,Z.jsxs)(`div`,{children:[y&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,Z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:_?.email?(0,Z.jsxs)(Z.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,Z.jsx)(`span`,{className:`text-white`,children:_.email})]}):(0,Z.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,Z.jsxs)(N,{variant:`secondary`,size:`sm`,onClick:()=>j.mutate(),disabled:j.isPending||!l,title:l?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,Z.jsx)(W,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),y?x?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):T?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:T.message}),(0,Z.jsx)(N,{onClick:()=>S(),children:e(`profiles.orcaCloud.retry`)})]}):b?(0,Z.jsx)(Pe,{settings:b,lastSyncTime:te,onRefresh:()=>S(),isRefreshing:C,printers:ee,t:e}):null:(0,Z.jsx)(ze,{pairing:u,connectError:m,onConnect:()=>A.mutate(),onCancel:O,isStarting:A.isPending,canManage:l,t:e})]})}function ze({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,Z.jsx)(z,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,Z.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.device.title`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:o(`profiles.orcaCloud.device.instruction`)}),(0,Z.jsx)(`p`,{className:`text-xs uppercase tracking-wide text-bambu-gray mb-2`,children:o(`profiles.orcaCloud.device.codeLabel`)}),(0,Z.jsx)(`div`,{className:`mb-6 py-3 px-4 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:(0,Z.jsx)(`span`,{className:`text-2xl font-mono font-bold tracking-[0.3em] text-white select-all`,children:e.user_code})}),(0,Z.jsx)(`a`,{href:e.verification_uri_complete,target:`_blank`,rel:`noopener noreferrer`,children:(0,Z.jsxs)(N,{className:`w-full mb-3`,children:[(0,Z.jsx)(R,{className:`w-4 h-4`}),o(`profiles.orcaCloud.device.openButton`)]})}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray break-all mb-6`,children:o(`profiles.orcaCloud.device.manualHint`,{url:e.verification_uri})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-bambu-gray mb-4`,children:[(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin text-bambu-green`}),o(`profiles.orcaCloud.device.waiting`)]}),(0,Z.jsx)(`button`,{type:`button`,onClick:r,className:`text-bambu-gray hover:text-white text-sm`,children:o(`profiles.orcaCloud.device.cancel`)})]})}):(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`p-8 text-center`,children:[(0,Z.jsx)(z,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,Z.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.connect.title`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:o(`profiles.orcaCloud.connect.description`)}),(0,Z.jsxs)(`div`,{className:`max-w-sm mx-auto`,children:[(0,Z.jsxs)(N,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(d,{className:`w-4 h-4`}),o(`profiles.orcaCloud.connectButton`)]}),t&&(0,Z.jsxs)(`p`,{className:`mt-3 text-sm text-red-700 dark:text-red-400 flex items-center justify-center gap-2`,children:[(0,Z.jsx)(m,{className:`w-4 h-4 flex-shrink-0`}),t]})]})]})})}function Be(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function Ve(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function He({onSuccess:e,t}){let{showToast:n}=h(),[i,a]=(0,Y.useState)(`email`),[o,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(`global`),[v,y]=(0,Y.useState)(null),[b,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(!1),E=s({mutationFn:()=>r.cloudLogin(o,l,g),onSuccess:r=>{if(C(r.reason===`captcha`),r.success)n(t(`profiles.login.toast.loggedIn`)),e();else if(r.reason===`captcha`)return;else r.needs_verification?(y(r.verification_type||`email`),x(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),a(`code`)):n(r.message,`error`)},onError:e=>{C(!1),n(e.message,`error`)}}),ee=s({mutationFn:()=>r.cloudVerify(o,d,b||void 0,g),onSuccess:r=>{C(r.reason===`captcha`),r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.reason!==`captcha`&&n(r.message,`error`)},onError:e=>{C(!1),n(e.message,`error`)}}),te=s({mutationFn:()=>r.cloudSetToken(p,g),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),D=e=>{e.preventDefault(),i===`email`?E.mutate():i===`code`?ee.mutate():i===`token`&&te.mutate()},O=E.isPending||ee.isPending||te.isPending;return(0,Z.jsx)(M,{className:`max-w-md mx-auto`,children:(0,Z.jsxs)(j,{children:[(0,Z.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,Z.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,Z.jsx)(z,{className:`w-6 h-6 text-bambu-green`})}),(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),S&&i!==`token`&&(0,Z.jsx)(`div`,{role:`alert`,className:`mb-4 p-3 rounded-lg border border-amber-500/40 bg-amber-500/10`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(L,{className:`w-4 h-4 text-amber-400 shrink-0 mt-0.5`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-amber-300`,children:t(`profiles.login.captchaTitle`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`profiles.login.captchaBody`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{C(!1),a(`token`)},className:`mt-2 text-xs text-bambu-green hover:underline flex items-center gap-1`,children:[(0,Z.jsx)(G,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,Z.jsxs)(`form`,{onSubmit:D,className:`space-y-4`,children:[i===`email`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,Z.jsx)(`input`,{type:`email`,value:o,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,Z.jsx)(`input`,{type:`password`,value:l,onChange:e=>u(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,Z.jsxs)(`select`,{value:g,onChange:e=>_(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,Z.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,Z.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),i===`code`&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(v===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:v===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:o})}),(0,Z.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),i===`token`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,Z.jsx)(`textarea`,{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 text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,Z.jsxs)(`select`,{value:g,onChange:e=>_(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,Z.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,Z.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[i===`code`&&(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:()=>a(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,Z.jsxs)(N,{type:`submit`,disabled:O,className:`flex-1`,children:[O?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(T,{className:`w-4 h-4`}),t(i===`email`?`profiles.login.loginButton`:i===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),i===`email`&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,Z.jsx)(G,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),i===`token`&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,Z.jsx)(T,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function Ue({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,Y.useState)(!1),o=n.find(e=>e.value===t);return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,Z.jsx)(`span`,{children:o?.label||`All`}),(0,Z.jsx)(f,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,Z.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,Z.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,Z.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function We(){let[e,t]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,Z.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-24 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,Z.jsx)(u,{className:`w-5 h-5`})}):null}function Ge({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=Be(e.name),l=Ve(e.setting_id);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,Z.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,Z.jsx)(g,{className:`w-4 h-4`})})]})}function Ke(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(`
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as c}from"./createLucideIcon-Yo2YoYjm.js";import{t as l}from"./arrow-right-Da96kh4S.js";import{t as u}from"./arrow-up-Dam8cLfE.js";import{t as d}from"./check-D1Pn8T1J.js";import{a as f,i as p,r as m}from"./info-DcT0QU8O.js";import{n as h}from"./ToastContext-VFOrCCoA.js";import{t as g}from"./copy-3N5VKzXz.js";import{t as _}from"./droplet-PpnaB65N.js";import{t as v}from"./eye-off-B6dY82pM.js";import{t as y}from"./funnel-BtI48m95.js";import{t as b}from"./gauge-xO5PdXj0.js";import{t as x}from"./git-compare-DbgnTP6k.js";import{t as S}from"./hard-drive-CN9rq6Uq.js";import{t as C}from"./list-CBXEiN6g.js";import{t as w}from"./loader-circle-CB4leTZa.js";import{t as T}from"./log-in-D7NdqHOf.js";import{t as E}from"./minus-D0aY9wbr.js";import{t as ee}from"./search-BpAJdxRw.js";import{t as te}from"./settings-2-DYB5IzKV.js";import{t as D}from"./sparkles-AUof3WTI.js";import{t as O}from"./sticky-note-C75KNLfY.js";import{t as k}from"./triangle-alert-gIik0G2C.js";import{t as A}from"./x-Dctff5l9.js";import{n as j,t as M}from"./Card-OUAj0Ayh.js";import{t as N}from"./Button-pwVKPiYn.js";import{u as P}from"./date-G9KUauqz.js";import{$t as F,At as I,Bt as L,Cn as R,Ct as ne,Dn as z,En as B,Jt as re,Kt as ie,Lt as V,On as ae,Rt as oe,Sn as H,Ut as U,Zt as se,an as W,cn as ce,kt as le,ln as G,wn as ue,yt as de}from"./index-ggB_TpPo.js";import{p as K,u as q}from"./utils--AXHSbgQ.js";import{t as fe}from"./useCancellableTimeout-CXuQGelB.js";var J=c(`equal`,[[`line`,{x1:`5`,x2:`19`,y1:`9`,y2:`9`,key:`1nwqeh`}],[`line`,{x1:`5`,x2:`19`,y1:`15`,y2:`15`,key:`g8yjpy`}]]),pe=c(`sliders-vertical`,[[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M12 21v-9`,key:`17s77i`}],[`path`,{d:`M12 8V3`,key:`13r4qs`}],[`path`,{d:`M17 16h4`,key:`h1uq16`}],[`path`,{d:`M19 12V3`,key:`o1uvq1`}],[`path`,{d:`M19 21v-5`,key:`qua636`}],[`path`,{d:`M3 14h4`,key:`bcjad9`}],[`path`,{d:`M5 10V3`,key:`cb8scm`}],[`path`,{d:`M5 21v-7`,key:`1w1uti`}]]),Y=e(n(),1),X={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};function me(e){let t=(e||``).toUpperCase().trim();return t&&(X[t]||X[t.replace(/[-\s]?CF$/,``)]||X[t.replace(/\+$/,``)]||X[t.split(/[-\s]/)[0]])||``}function he(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var ge={local:0,orca_cloud:1,cloud:2,builtin:3};function _e(e){let{localPresets:t,orcaProfiles:n,cloudSettings:r,builtinFilaments:i}=e,a=[],o=e=>e.trim().toLowerCase(),s=new Set,c=new Set,l=new Set,u=(e,t,...n)=>{let r=n.filter(e=>!!e);if(r.some(e=>s.has(e)))return!1;let i=`${e}|${o(t)}`;return c.has(i)?!1:(r.forEach(e=>s.add(e)),c.add(i),l.add(o(t)),!0)};for(let e of t??[]){let t=he(e.name),n=e.filament_type||q(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:me(n),filamentType:n||``})}for(let e of n??[]){let t=he(e.name),n=q(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:me(n),filamentType:n})}for(let e of r??[]){let t=he(e.name),n=e.setting_id.startsWith(`GFS`)?K(e.setting_id):``;u(`cloud`,t,e.setting_id,n||void 0)&&a.push({id:e.setting_id,name:t,source:`cloud`,filamentId:n,filamentType:q(t).material})}for(let e of i??[]){let t=e.filament_id.startsWith(`GF`)?`GFS${e.filament_id.slice(2)}`:e.filament_id;l.has(o(e.name))||u(`builtin`,e.name,e.filament_id,t)&&a.push({id:`builtin_${e.filament_id}`,name:e.name,source:`builtin`,filamentId:e.filament_id,filamentType:q(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):ge[e.source]-ge[t.source])}async function ve(e,t){if(e.filamentId)return e.filamentId;if(e.source!==`cloud`||!t)return``;try{return(await t(e.id)).filament_id||``}catch{return``}}var Z=t(),ye=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),be=`HS00`,xe=`HH00`,Se=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:be},Q=e=>Se(e)===xe?`HF`:`S`,Ce=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function we({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=Q(e.nozzle_id),c=e.nozzle_diameter;return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,Z.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,Z.jsx)(oe,{className:`w-4 h-4 text-bambu-green`}):(0,Z.jsx)(V,{className:`w-4 h-4`})}),(0,Z.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:ye(e.k_value)}),(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,Z.jsx)(`span`,{title:`Has note`,children:(0,Z.jsx)(O,{className:`w-3 h-3 text-yellow-500`})}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,Z.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,Z.jsx)(g,{className:`w-4 h-4`})})]})}function Te({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:a=[],builtinFilaments:o=[],filamentPresets:c=[],isDualNozzle:l=!1,supportsFlowType:u=!0,initialNote:d=``,initialNoteKey:f=null,onClose:p,onSave:m,onSaveNote:g,hasPermission:_}){let{t:v}=i(),{showToast:y}=h(),[x,S]=(0,Y.useState)(e?.name||``),[C,T]=(0,Y.useState)(e?.k_value?ye(e.k_value):`0.020`),[E,te]=(0,Y.useState)(e?.filament_id||``),[D,O]=(0,Y.useState)(e?Se(e.nozzle_id):be),[k,P]=(0,Y.useState)(e?.nozzle_diameter||n),[F,L]=(0,Y.useState)(e?[e.extruder_id]:l?[0,1]:[0]),[R,ne]=(0,Y.useState)(!1),[z,B]=(0,Y.useState)({current:0,total:0}),[re,ie]=(0,Y.useState)(d),[V,ae]=(0,Y.useState)(``),{schedule:oe}=fe(),H=Y.useMemo(()=>e?.filament_id?o.find(t=>t.filament_id===e.filament_id)?.name||Ce(a.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,a,o]),U=Y.useMemo(()=>{let e=[[`local`,v(`kProfiles.modal.source.local`)],[`orca_cloud`,v(`kProfiles.modal.source.orcaCloud`)],[`cloud`,v(`kProfiles.modal.source.bambuCloud`)],[`builtin`,v(`kProfiles.modal.source.builtin`)]],t=V.trim().toLowerCase(),n=t?c.filter(e=>e.name.toLowerCase().includes(t)):c;return e.map(([e,t])=>({source:e,label:t,items:n.filter(t=>t.source===e)})).filter(e=>e.items.length>0)},[c,V,v]),se=s({mutationFn:e=>(console.log(`[KProfile] Calling API...`),r.setKProfile(t,e)),onSuccess:(t,n)=>{if(console.log(`[KProfile] Save success:`,t),y(v(`kProfiles.toast.profileSaved`)),g&&re!==d){let t;t=re===``&&f?f:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${x}_${n.filament_id}`,g(t,re)}ne(!0),oe(()=>{ne(!1),m()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),y(e.message,`error`),ne(!1)}}),W=s({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),r.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),y(v(`kProfiles.toast.profileDeleted`)),ne(!0),oe(()=>{ne(!1),p()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),y(e.message,`error`),ne(!1)}}),[ce,le]=(0,Y.useState)(!1),G=()=>{e&&W.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,Z.jsxs)(M,{className:`w-full max-w-md relative`,children:[R&&(0,Z.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:z.total>1?v(`kProfiles.modal.savingExtruder`,{current:z.current,total:z.total}):v(`kProfiles.modal.syncing`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:v(`kProfiles.modal.pleaseWait`)})]}),(0,Z.jsxs)(j,{className:`p-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:v(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,Z.jsx)(`button`,{onClick:p,className:`text-bambu-gray hover:text-white transition-colors`,disabled:R,children:(0,Z.jsx)(A,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),l&&!e&&F.length===0){y(v(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let i=parseFloat(C).toFixed(6),a=`${D}-${k}`,o=e&&e.nozzle_id||a,s=e?e.nozzle_diameter:k,u=e?.filament_id||``;if(!e){let e=c.find(e=>e.id===E);if(!e){y(v(`kProfiles.toast.selectFilament`),`error`);return}if(u=await ve(e,r.getCloudSettingDetail),!u){y(v(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||F.length===1){let t={name:x,k_value:i,filament_id:u,nozzle_id:o,nozzle_diameter:s,extruder_id:e?e.extruder_id:F[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),se.mutate(t);return}ne(!0),B({current:1,total:F.length});let d=F.map(e=>({name:x,k_value:i,filament_id:u,nozzle_id:a,nozzle_diameter:k,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${d.length} profiles in batch:`,d);try{await r.setKProfilesBatch(t,d),y(v(`kProfiles.toast.profilesSaved`,{count:F.length})),g&&re&&g(`name_${x}_${u}`,re)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),y(v(`kProfiles.toast.failedToSaveBatch`),`error`),ne(!1),B({current:0,total:0});return}B({current:F.length,total:F.length}),oe(()=>{ne(!1),B({current:0,total:0}),m()},3e3)},className:`p-4 space-y-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.profileName`)}),(0,Z.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:v(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.kValue`)}),(0,Z.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:C,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&T(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||T((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:v(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.kValueHelp`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.filament`)}),e?(0,Z.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:H||e.filament_id}):(0,Z.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`relative border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:V,onChange:e=>ae(e.target.value),placeholder:v(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,Z.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:U.length===0?(0,Z.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:c.length===0?v(`kProfiles.modal.noFilamentsHelp`):v(`kProfiles.modal.noFilamentMatches`)}):U.map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-secondary border-y border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-bambu-green`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:e.items.length})]}),e.items.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{te(e.id),x||S(`${D===xe?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${E===e.id?`bg-bambu-green/20 text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))]},e.source))})]})]}),(0,Z.jsxs)(`div`,{className:u?`grid grid-cols-2 gap-4`:``,children:[(0,Z.jsxs)(`div`,{className:u?``:`hidden`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.flowType`)}),(0,Z.jsxs)(`select`,{value:D,onChange:t=>{let n=t.target.value;if(O(n),!e&&E&&!x){let e=c.find(e=>e.id===E);e&&S(`${n===xe?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,Z.jsx)(`option`,{value:xe,children:v(`kProfiles.modal.highFlow`)}),(0,Z.jsx)(`option`,{value:be,children:v(`kProfiles.modal.standard`)})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.nozzleSize`)}),(0,Z.jsxs)(`select`,{value:k,onChange:e=>P(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,Z.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,Z.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,Z.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,Z.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),l&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,Z.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?v(`kProfiles.modal.left`):v(`kProfiles.modal.right`)}):(0,Z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(1),onChange:e=>{e.target.checked?L([...F,1]):L(F.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,Z.jsx)(`span`,{className:`text-white`,children:v(`kProfiles.modal.left`)})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(0),onChange:e=>{e.target.checked?L([...F,0]):L(F.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,Z.jsx)(`span`,{className:`text-white`,children:v(`kProfiles.modal.right`)})]})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.notes`)}),(0,Z.jsx)(`textarea`,{value:re,onChange:e=>ie(e.target.value),placeholder:v(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none`}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.notesHelp`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:()=>le(!0),disabled:W.isPending||R||!_(`kprofiles:delete`),title:_(`kprofiles:delete`)?void 0:v(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:W.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`})}),(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:p,disabled:R,className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(N,{type:`submit`,disabled:se.isPending||R||!_(e?`kprofiles:update`:`kprofiles:create`),title:_(e?`kprofiles:update`:`kprofiles:create`)?void 0:v(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[se.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(b,{className:`w-4 h-4`}),v(`common.save`)]})]})]})]})]}),ce&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,Z.jsx)(M,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(j,{className:`p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,Z.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,Z.jsx)(I,{className:`w-5 h-5 text-red-500`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:v(`kProfiles.deleteConfirm.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:v(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:v(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(N,{variant:`secondary`,onClick:()=>le(!1),className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(N,{onClick:()=>{le(!1),G()},disabled:W.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[W.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),v(`common.delete`)]})]})]})})})]})}var Ee={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function De(){let{t:e}=i(),{showToast:t}=h(),{hasPermission:n}=de(),[a,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(()=>localStorage.getItem(Ee.NOZZLE_DIAMETER)||`0.4`),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(``),[x,S]=(0,Y.useState)(`all`),[C,T]=(0,Y.useState)(`all`),[E,te]=(0,Y.useState)(()=>localStorage.getItem(Ee.SORT_OPTION)||`name`),[D,O]=(0,Y.useState)(!1),[k,P]=(0,Y.useState)(new Set),[F,L]=(0,Y.useState)(!1),[R,z]=(0,Y.useState)(!1),B=(0,Y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,Y.useEffect)(()=>{localStorage.setItem(Ee.NOZZLE_DIAMETER,c)},[c]),(0,Y.useEffect)(()=>{localStorage.setItem(Ee.SORT_OPTION,E)},[E]);let{data:V,isLoading:ae}=o({queryKey:[`printers`],queryFn:r.getPrinters}),{data:H,isLoading:U,isFetching:W,error:ce,refetch:G}=o({queryKey:[`kprofiles`,a,c],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,a,`nozzle`,c);let e=await r.getKProfiles(a,c);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!a,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:K}=o({queryKey:[`builtinFilaments`],queryFn:()=>r.getBuiltinFilaments(),staleTime:3e5}),{data:q}=o({queryKey:[`filamentIdMap`],queryFn:()=>r.getFilamentIdMap(),staleTime:3e5}),{data:fe}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets(),retry:!1}),{data:J}=o({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>r.orcaCloudListProfiles(),retry:!1}),{data:pe}=o({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),retry:!1}),{data:X,refetch:me}=o({queryKey:[`kprofile-notes`,a],queryFn:()=>r.getKProfileNotes(a),enabled:!!a,staleTime:3e4}),he=ce?.message?.includes(`not connected`);(0,Y.useEffect)(()=>{if(!a&&V&&V.length>0){let e=V.find(e=>e.is_active);e&&s(e.id)}},[a,V]),(0,Y.useEffect)(()=>{if(a){let e=setTimeout(()=>{G()},150);return()=>clearTimeout(e)}},[a,c]);let ge=V?.filter(e=>e.is_active)||[],ve=Y.useMemo(()=>{let e=new Map;if(K)for(let t of K)e.set(t.filament_id,t.name);if(q)for(let[t,n]of Object.entries(q))e.has(t)||e.set(t,n);return e},[K,q]),ye=Y.useMemo(()=>Array.from(ve.entries()).map(([e,t])=>({filament_id:e,name:t})),[ve]),xe=Y.useMemo(()=>_e({localPresets:fe?.filament,orcaProfiles:J?.filament,cloudSettings:pe?.filament,builtinFilaments:K}),[fe?.filament,J?.filament,pe?.filament,K]),Se=Y.useCallback(e=>ve.get(e.filament_id)||Ce(e.name),[ve]),Q=Y.useMemo(()=>H?.profiles?H.profiles.filter(e=>{let t=v.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=x===`all`||x===`left`&&e.extruder_id===1||x===`right`&&e.extruder_id===0,i=C===`all`||C===`hf`&&e.nozzle_id.startsWith(`HH`)||C===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(E){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return Se(e).localeCompare(Se(t));default:return e.name.localeCompare(t.name)}}):[],[H?.profiles,v,x,C,E,Se]),De=V?.find(e=>e.id===a),$=De?.nozzle_count===2,Oe=De?.supports_nozzle_flow_type??!0;(0,Y.useEffect)(()=>{Oe||T(`all`)},[Oe]),(0,Y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||u||f||g||(e.key===`r`||e.key===`R`?(e.preventDefault(),G()):e.key===`n`||e.key===`N`?(e.preventDefault(),p(!0)):e.key===`Escape`&&D&&(e.preventDefault(),O(!1),P(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,f,g,D,G]);let ke=(0,Y.useCallback)(()=>{if(!H?.profiles||H.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:De?.name||`Unknown`,nozzle_diameter:c,profiles:H.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`kprofiles_${De?.name||`printer`}_${c}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:H.profiles.length}))},[H?.profiles,De,c,t,e]),Ae=(0,Y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await r.setKProfile(a,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${be}-${c}`,nozzle_diameter:e.nozzle_diameter||c,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),G()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[a,c,t,G,e]),je=(0,Y.useCallback)(e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Me=(0,Y.useCallback)(()=>{P(new Set(Q.map(e=>B(e))))},[Q,B]),Ne=(0,Y.useCallback)(()=>{k.size!==0&&L(!0)},[k.size]),Pe=(0,Y.useCallback)(async()=>{let n=Q.filter(e=>k.has(B(e)));z(!0);let i=0;for(let e of n)try{await r.deleteKProfile(a,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),z(!1),L(!1),O(!1),P(new Set),G()},[a,k,Q,t,G,B,e]),Fe=(0,Y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),Ie=(0,Y.useCallback)(async(n,i)=>{if(a)try{await r.setKProfileNote(a,n,i),me()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[a,me,t,e]),Le=(0,Y.useCallback)(e=>{if(!X?.notes)return{note:``,key:null};let t=Fe(e);for(let e of t)if(X.notes[e])return{note:X.notes[e],key:e};return{note:``,key:null}},[X,Fe]),Re=(0,Y.useCallback)(e=>Le(e).note,[Le]);return ae?(0,Z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!V||V.length===0?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(m,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):ge.length===0?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(re,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,Z.jsxs)(Z.Fragment,{children:[W&&!U&&(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,Z.jsx)(w,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,Z.jsx)(`select`,{value:a||``,onChange:e=>s(parseInt(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:ge.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Z.jsxs)(`div`,{className:`w-32`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,Z.jsxs)(`select`,{value:c,onChange:e=>l(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,Z.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,Z.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,Z.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,Z.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>G(),disabled:W||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,Z.jsx)(ie,{className:`w-4 h-4 ${W?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,Z.jsxs)(N,{onClick:()=>p(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,Z.jsx)(se,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),$&&(0,Z.jsx)(`div`,{className:`w-36`,children:(0,Z.jsxs)(`select`,{value:x,onChange:e=>S(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,Z.jsx)(`option`,{value:`all`,children:e(`kProfiles.allExtruders`)}),(0,Z.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,Z.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),Oe&&(0,Z.jsx)(`div`,{className:`w-32`,children:(0,Z.jsxs)(`select`,{value:C,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 focus:border-bambu-green focus:outline-none`,children:[(0,Z.jsx)(`option`,{value:`all`,children:e(`kProfiles.allFlow`)}),(0,Z.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,Z.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,Z.jsx)(`div`,{className:`w-32`,children:(0,Z.jsxs)(`select`,{value:E,onChange:e=>te(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,Z.jsx)(`option`,{value:`name`,children:e(`kProfiles.sortName`)}),(0,Z.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,Z.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:ke,disabled:!H?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,Z.jsx)(ue,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:Ae,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,Z.jsx)(le,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,Z.jsx)(`div`,{className:`flex-1`}),D?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:Me,children:[(0,Z.jsx)(oe,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:Ne,disabled:k.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,k.size,`)`]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>{O(!1),P(new Set)},children:[(0,Z.jsx)(A,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>O(!0),disabled:!Q.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,Z.jsx)(oe,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),U?(0,Z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):he?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(ne,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>G(),children:[(0,Z.jsx)(ie,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):Q.length>0?$?(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.filter(e=>e.extruder_id===1).map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.filter(e=>e.extruder_id===0).map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))})]})]}):(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))}):v||x!==`all`||C!==`all`?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(ee,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(b,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:c})}),(0,Z.jsxs)(N,{onClick:()=>p(!0),children:[(0,Z.jsx)(se,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),u&&a&&(()=>{let{note:e,key:t}=Le(u);return(0,Z.jsx)(Te,{profile:u,printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,initialNote:e,initialNoteKey:t,onSaveNote:Ie,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),d(null),G()},onSave:()=>{d(null),G()}})})(),f&&a&&(0,Z.jsx)(Te,{printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,onSaveNote:Ie,hasPermission:n,onClose:()=>{p(!1),G()},onSave:()=>{p(!1),G()}}),g&&a&&(0,Z.jsx)(Te,{printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,onSaveNote:Ie,hasPermission:n,profile:{...g,slot_id:0,name:`${g.name} (Copy)`},onClose:()=>{_(null),G()},onSave:()=>{_(null),G()}}),F&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(M,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(j,{className:`p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,Z.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,Z.jsx)(I,{className:`w-5 h-5 text-red-500`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:k.size})}),(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(N,{variant:`secondary`,onClick:()=>L(!1),disabled:R,className:`flex-1`,children:e(`common.cancel`)}),(0,Z.jsxs)(N,{onClick:Pe,disabled:R,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[R?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var $=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],Oe={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function ke(e){let t=e.toUpperCase();for(let e of $)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function Ae(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of $){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function je({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:a}=i(),{hasPermission:o}=de(),s=e.filament_type||ke(e.name),c=e.filament_vendor||Ae(e.name),l=null,u=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(l=n.replace(`#`,``).slice(0,6),u=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(l=t.replace(`#`,``).slice(0,6),u=!0)}return!l&&s&&(l=Oe[s.toUpperCase()]||null),(0,Z.jsx)(M,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,Z.jsxs)(j,{className:`p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,Z.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!u&&!l?`opacity-25`:u?``:`opacity-50`}`,style:{backgroundColor:l?`#${l}`:`#666`}}),(0,Z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s&&(0,Z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:s}),c&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c}),(0,Z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:a(`profiles.localProfiles.badge`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[o(`settings:update`)&&(0,Z.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:a(`profiles.localProfiles.delete`),children:(0,Z.jsx)(I,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,Z.jsx)(p,{className:`w-3.5 h-3.5`}):(0,Z.jsx)(f,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,Z.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[s&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.filamentType`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:s})]}),c&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.vendor`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:c})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.nozzleTemp`)}),(0,Z.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.cost`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.density`)}),(0,Z.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.pressureAdvance`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.compatiblePrinters`)}),(0,Z.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.inheritsFrom`)}),(0,Z.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.source`)}),(0,Z.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function Me(){let{t:e}=i(),{hasPermission:t}=de(),n=a(),{showToast:c}=h(),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(null),[p,g]=(0,Y.useState)(!1),[v,y]=(0,Y.useState)(null),{data:b,isLoading:x}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets()}),C=s({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await r.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let r=0,i=0,a=0;for(let e of t)r+=e.imported,i+=e.skipped,a+=e.errors.length;r>0&&c(e(`profiles.localProfiles.toast.importSuccess`,{count:r})),i>0&&c(e(`profiles.localProfiles.toast.importSkipped`,{count:i}),`warning`),a>0&&c(e(`profiles.localProfiles.toast.importError`,{count:a}),`error`)},onError:e=>{c(e.message,`error`)}}),T=s({mutationFn:e=>r.deleteLocalPreset(e),onSuccess:(t,r)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==r),printer:e.printer.filter(e=>e.id!==r),process:e.process.filter(e=>e.id!==r)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),y(null),c(e(`profiles.localProfiles.toast.deleted`))}}),E=(0,Y.useCallback)(e=>{!e||e.length===0||C.mutate(e)},[C]),D=(0,Y.useCallback)(e=>{e.preventDefault(),g(!1),E(e.dataTransfer.files)},[E]),O=(0,Y.useCallback)(e=>{if(!l)return e;let t=l.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[l]),k=(0,Y.useMemo)(()=>O(b?.filament||[]),[b?.filament,O]),A=(0,Y.useMemo)(()=>O(b?.printer||[]),[b?.printer,O]),j=(0,Y.useMemo)(()=>O(b?.process||[]),[b?.process,O]),M=k.length+A.length+j.length,P=(b?.filament?.length??0)+(b?.printer?.length??0)+(b?.process?.length??0)>0;return x?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,Z.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:D,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${p?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,Z.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>E(e.target.files)}),C.isPending?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Z.jsx)(w,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(le,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,Z.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),P&&(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!P&&!x&&(0,Z.jsxs)(`div`,{className:`text-center py-12`,children:[(0,Z.jsx)(S,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),P&&M===0&&!x&&(0,Z.jsxs)(`div`,{className:`text-center py-12`,children:[(0,Z.jsx)(ee,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),M>0&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[k.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(_,{className:`w-4 h-4 text-bambu-green`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,k.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:k.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),j.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(ce,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,j.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:j.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),A.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(te,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,A.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:A.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]})]}),v!==null&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(m,{className:`w-5 h-5 text-red-600 dark:text-red-400`}),(0,Z.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(N,{variant:`secondary`,size:`sm`,onClick:()=>y(null),children:e(`profiles.localProfiles.cancel`)}),(0,Z.jsxs)(N,{variant:`danger`,size:`sm`,onClick:()=>T.mutate(v),disabled:T.isPending,children:[T.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function Ne(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function Pe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(`all`),[u,d]=(0,Y.useState)(`all`),[f,p]=(0,Y.useState)(`all`),[m,h]=(0,Y.useState)(`all`),[g,v]=(0,Y.useState)(`all`),[b,x]=(0,Y.useState)(null),S=(0,Y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:Ne(e.name)})),[e]),C=(0,Y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return S.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[S,i]),w=(0,Y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),T=(0,Y.useMemo)(()=>S.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!w)return!0;let t=e.meta.printer?.toLowerCase()||``,n=w.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[S,c,u,w,f,m,g,o]),E=()=>{l(`all`),d(`all`),p(`all`),h(`all`),v(`all`),s(``)},D=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,O=e.filament.length+e.printer.length+e.process.length,k=e=>T.filter(t=>t.type===e);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,Z.jsx)(`div`,{className:`flex gap-2`,children:(0,Z.jsxs)(N,{variant:`secondary`,onClick:n,disabled:r,children:[(0,Z.jsx)(ie,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(y,{className:`w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:O},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),C.printers.length>0&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),C.nozzles.length>0&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.nozzles.map(e=>({value:e,label:e}))],onChange:p}),C.filaments.length>0&&(c===`all`||c===`filament`)&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.filaments.map(e=>({value:e,label:e}))],onChange:h}),C.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.layerHeights.map(e=>({value:e,label:e}))],onChange:v}),D&&(0,Z.jsx)(`button`,{onClick:E,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(ae,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,P(t.toISOString(),`system`,a)]}),(0,Z.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:T.length,total:O})})]}),T.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(ce,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),D&&(0,Z.jsx)(`button`,{onClick:E,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(_,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:k(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:x}),(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(te,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:k(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:x}),(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(re,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:k(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:x})]}),b&&(0,Z.jsx)(Le,{setting:b,onClose:()=>x(null),t:a})]})}function Fe({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,Z.jsx)(Ie,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function Ie({preset:e,onClick:t}){return(0,Z.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function Le({setting:e,onClose:t,t:n}){let{data:i,isLoading:a,error:s}=o({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>r.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,Z.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,Z.jsx)(A,{className:`w-5 h-5`})})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:a?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):s?(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:s.message}):i?(0,Z.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(i.setting,null,2)}):(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function Re(){let{t:e}=i(),t=a(),{showToast:n}=h(),{hasPermission:c}=de(),l=c(`orca_cloud:auth`),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(5e3),[m,g]=(0,Y.useState)(null),{data:_,isLoading:v}=o({queryKey:[`orcaCloudStatus`],queryFn:r.orcaCloudStatus}),y=!!_?.connected,{data:b,isLoading:x,refetch:S,isRefetching:C,error:T,dataUpdatedAt:E}=o({queryKey:[`orcaCloudProfiles`],queryFn:r.orcaCloudListProfiles,enabled:y,retry:!1,staleTime:1e3*60*5}),{data:ee=[]}=o({queryKey:[`printers`],queryFn:r.getPrinters,enabled:y}),[te,D]=(0,Y.useState)();(0,Y.useEffect)(()=>{E&&D(new Date(E))},[E]);let O=()=>{d(null),p(5e3)},k=t=>{t===`access_denied`?g(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&g(e(`profiles.orcaCloud.errors.expired`)),O()},A=s({mutationFn:r.orcaCloudDeviceStart,onSuccess:e=>{g(null),p(Math.max(1,e.interval)*1e3),d(e)},onError:t=>{g(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),j=s({mutationFn:r.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:M,error:P}=o({queryKey:[`orcaCloudDevicePoll`,u?.user_code??`none`],queryFn:r.orcaCloudDevicePoll,enabled:u!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:u===null?!1:f}),F=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{if(!u||!M)return;let r=M.status;if(r===`slow_down`){p(e=>e+5e3);return}r!==`authorization_pending`&&F.current!==r&&(F.current=r,r===`complete`?(O(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.connectedShort`))):k(r))},[M,u]),(0,Y.useEffect)(()=>{u&&P&&(g(e(`profiles.orcaCloud.errors.pollFailed`)),O())},[P,u]),(0,Y.useEffect)(()=>{u&&(F.current=null)},[u]),v?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,Z.jsxs)(`div`,{children:[y&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,Z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:_?.email?(0,Z.jsxs)(Z.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,Z.jsx)(`span`,{className:`text-white`,children:_.email})]}):(0,Z.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,Z.jsxs)(N,{variant:`secondary`,size:`sm`,onClick:()=>j.mutate(),disabled:j.isPending||!l,title:l?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,Z.jsx)(W,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),y?x?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):T?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:T.message}),(0,Z.jsx)(N,{onClick:()=>S(),children:e(`profiles.orcaCloud.retry`)})]}):b?(0,Z.jsx)(Pe,{settings:b,lastSyncTime:te,onRefresh:()=>S(),isRefreshing:C,printers:ee,t:e}):null:(0,Z.jsx)(ze,{pairing:u,connectError:m,onConnect:()=>A.mutate(),onCancel:O,isStarting:A.isPending,canManage:l,t:e})]})}function ze({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,Z.jsx)(z,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,Z.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.device.title`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:o(`profiles.orcaCloud.device.instruction`)}),(0,Z.jsx)(`p`,{className:`text-xs uppercase tracking-wide text-bambu-gray mb-2`,children:o(`profiles.orcaCloud.device.codeLabel`)}),(0,Z.jsx)(`div`,{className:`mb-6 py-3 px-4 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:(0,Z.jsx)(`span`,{className:`text-2xl font-mono font-bold tracking-[0.3em] text-white select-all`,children:e.user_code})}),(0,Z.jsx)(`a`,{href:e.verification_uri_complete,target:`_blank`,rel:`noopener noreferrer`,children:(0,Z.jsxs)(N,{className:`w-full mb-3`,children:[(0,Z.jsx)(R,{className:`w-4 h-4`}),o(`profiles.orcaCloud.device.openButton`)]})}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray break-all mb-6`,children:o(`profiles.orcaCloud.device.manualHint`,{url:e.verification_uri})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-bambu-gray mb-4`,children:[(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin text-bambu-green`}),o(`profiles.orcaCloud.device.waiting`)]}),(0,Z.jsx)(`button`,{type:`button`,onClick:r,className:`text-bambu-gray hover:text-white text-sm`,children:o(`profiles.orcaCloud.device.cancel`)})]})}):(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`p-8 text-center`,children:[(0,Z.jsx)(z,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,Z.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.connect.title`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:o(`profiles.orcaCloud.connect.description`)}),(0,Z.jsxs)(`div`,{className:`max-w-sm mx-auto`,children:[(0,Z.jsxs)(N,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(d,{className:`w-4 h-4`}),o(`profiles.orcaCloud.connectButton`)]}),t&&(0,Z.jsxs)(`p`,{className:`mt-3 text-sm text-red-700 dark:text-red-400 flex items-center justify-center gap-2`,children:[(0,Z.jsx)(m,{className:`w-4 h-4 flex-shrink-0`}),t]})]})]})})}function Be(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function Ve(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function He({onSuccess:e,t}){let{showToast:n}=h(),[i,a]=(0,Y.useState)(`email`),[o,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(`global`),[v,y]=(0,Y.useState)(null),[b,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(!1),E=s({mutationFn:()=>r.cloudLogin(o,l,g),onSuccess:r=>{if(C(r.reason===`captcha`),r.success)n(t(`profiles.login.toast.loggedIn`)),e();else if(r.reason===`captcha`)return;else r.needs_verification?(y(r.verification_type||`email`),x(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),a(`code`)):n(r.message,`error`)},onError:e=>{C(!1),n(e.message,`error`)}}),ee=s({mutationFn:()=>r.cloudVerify(o,d,b||void 0,g),onSuccess:r=>{C(r.reason===`captcha`),r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.reason!==`captcha`&&n(r.message,`error`)},onError:e=>{C(!1),n(e.message,`error`)}}),te=s({mutationFn:()=>r.cloudSetToken(p,g),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),D=e=>{e.preventDefault(),i===`email`?E.mutate():i===`code`?ee.mutate():i===`token`&&te.mutate()},O=E.isPending||ee.isPending||te.isPending;return(0,Z.jsx)(M,{className:`max-w-md mx-auto`,children:(0,Z.jsxs)(j,{children:[(0,Z.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,Z.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,Z.jsx)(z,{className:`w-6 h-6 text-bambu-green`})}),(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),S&&i!==`token`&&(0,Z.jsx)(`div`,{role:`alert`,className:`mb-4 p-3 rounded-lg border border-amber-500/40 bg-amber-500/10`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(L,{className:`w-4 h-4 text-amber-400 shrink-0 mt-0.5`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-amber-300`,children:t(`profiles.login.captchaTitle`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`profiles.login.captchaBody`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{C(!1),a(`token`)},className:`mt-2 text-xs text-bambu-green hover:underline flex items-center gap-1`,children:[(0,Z.jsx)(G,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,Z.jsxs)(`form`,{onSubmit:D,className:`space-y-4`,children:[i===`email`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,Z.jsx)(`input`,{type:`email`,value:o,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,Z.jsx)(`input`,{type:`password`,value:l,onChange:e=>u(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,Z.jsxs)(`select`,{value:g,onChange:e=>_(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,Z.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,Z.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),i===`code`&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(v===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:v===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:o})}),(0,Z.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),i===`token`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,Z.jsx)(`textarea`,{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 text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,Z.jsxs)(`select`,{value:g,onChange:e=>_(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,Z.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,Z.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[i===`code`&&(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:()=>a(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,Z.jsxs)(N,{type:`submit`,disabled:O,className:`flex-1`,children:[O?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(T,{className:`w-4 h-4`}),t(i===`email`?`profiles.login.loginButton`:i===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),i===`email`&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,Z.jsx)(G,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),i===`token`&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,Z.jsx)(T,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function Ue({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,Y.useState)(!1),o=n.find(e=>e.value===t);return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,Z.jsx)(`span`,{children:o?.label||`All`}),(0,Z.jsx)(f,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,Z.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,Z.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,Z.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function We(){let[e,t]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,Z.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-24 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,Z.jsx)(u,{className:`w-5 h-5`})}):null}function Ge({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=Be(e.name),l=Ve(e.setting_id);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,Z.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,Z.jsx)(g,{className:`w-4 h-4`})})]})}function Ke(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(`
`)){let t=e.replace(/\\n/g,`
`).replace(/\\"/g,`"`).replace(/\\t/g,` `).split(`
`);if(t.length>1)return`"""
diff --git a/static/assets/ProjectDetailPage-BpwdspD8.js b/static/assets/ProjectDetailPage-Dxt4vo_Y.js
similarity index 99%
rename from static/assets/ProjectDetailPage-BpwdspD8.js
rename to static/assets/ProjectDetailPage-Dxt4vo_Y.js
index 5461cb039..cb829c81c 100644
--- a/static/assets/ProjectDetailPage-BpwdspD8.js
+++ b/static/assets/ProjectDetailPage-Dxt4vo_Y.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as ee}from"./arrow-left-MSgMxOFV.js";import{t as te}from"./RichTextEditor-DoPGmmPm.js";import{t as ne}from"./calendar-DiVEdzUw.js";import{n as re}from"./info-DcT0QU8O.js";import{n as ie,r as c}from"./ToastContext-VFOrCCoA.js";import{t as ae}from"./copy-3N5VKzXz.js";import{t as oe}from"./file-box-BjB1o93N.js";import{t as se}from"./history-BBZbf3sJ.js";import{t as l}from"./loader-circle-CB4leTZa.js";import{t as u}from"./package-D9xR0eOt.js";import{t as ce}from"./pen-line-DYnjxVtS.js";import{t as d}from"./triangle-alert-gIik0G2C.js";import{t as le}from"./x-Dctff5l9.js";import{n as f,t as p}from"./Card-OUAj0Ayh.js";import{t as m}from"./Button-pwVKPiYn.js";import{a as ue,i as de,s as fe,v as h}from"./date-G9KUauqz.js";import{$t as pe,At as me,Cn as he,Jt as g,Mn as ge,N as _e,On as ve,Pt as ye,Rn as _,Un as be,Ut as xe,Vn as Se,Zt as Ce,_t as we,at as Te,b as Ee,cn as De,vn as Oe,wn as ke,xn as Ae,yt as je,zt as Me}from"./index-Bw-_P2Fg.js";import{t as Ne}from"./purify.es-F_7NWVtX.js";import{n as Pe}from"./libraryFiles-B0B1SFfn.js";import{ProjectModal as Fe,n as v,t as Ie}from"./ProjectsPage-BvSVSfNa.js";var y=e(n(),1),b=t();function x(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function Le({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,b.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function Re({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,b.jsx)(e,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,b.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function ze({archives:e,t}){return e.length===0?(0,b.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,b.jsx)(u,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,b.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,b.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,b.jsxs)(_,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,b.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,b.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,b.jsx)(u,{className:`w-8 h-8`})}),e.status===`failed`&&(0,b.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,b.jsx)(re,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,b.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,b.jsx)(c,{className:`w-4 h-4 text-bambu-green`})}),(0,b.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,b.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function Be({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,b.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,b.jsx)(d,{className:`w-3 h-3`}),i]})}function S(e,t){if(!e)return null;let n=h(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-700 dark:text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-700 dark:text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-700 dark:text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function C(){let{id:e}=be(),t=Se(),{t:n}=i(),d=a(),{showToast:h}=ie(),{hasPermission:C}=je(),[Ve,w]=(0,y.useState)(!1),[He,T]=(0,y.useState)(!1),[Ue,E]=(0,y.useState)(``),[D,O]=(0,y.useState)(null),k=parseInt(e||`0`,10),{data:A,isLoading:We,error:j}=o({queryKey:[`project`,k],queryFn:()=>r.getProject(k),enabled:k>0}),{data:Ge,isLoading:Ke}=o({queryKey:[`project-archives`,k],queryFn:()=>r.getProjectArchives(k),enabled:k>0}),{data:M,isLoading:qe}=o({queryKey:[`project-bom`,k],queryFn:()=>r.getProjectBOM(k),enabled:k>0}),{data:N,isLoading:Je}=o({queryKey:[`project-timeline`,k],queryFn:()=>r.getProjectTimeline(k,20),enabled:k>0}),{data:Ye}=o({queryKey:[`settings`],queryFn:r.getSettings}),{data:P}=o({queryKey:[`project-folders`,k],queryFn:()=>r.getLibraryFoldersByProject(k),enabled:k>0}),{data:F,isLoading:Xe}=o({queryKey:[`project-files`,k],queryFn:()=>r.getLibraryFiles(null,!1,k),enabled:k>0}),Ze=(0,y.useMemo)(()=>{let e=new Map;for(let t of F??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[F]),{data:Qe}=o({queryKey:[`project-file-progress`,k],queryFn:()=>r.getProjectFileProgress(k),enabled:k>0}),I=(0,y.useMemo)(()=>{let e=new Map;for(let t of Qe??[])e.set(t.file_id,t.completed_count);return e},[Qe]),L=(0,y.useMemo)(()=>{let e=A?.target_sets;if(!e||!F)return null;let t=F.filter(e=>Pe(e));return t.length===0?null:Math.min(...t.map(t=>Math.min(I.get(t.id)??0,e)))},[A?.target_sets,F,I]),R=Te(Ye?.currency||`USD`),$e=Ye?.time_format||`system`,z=s({mutationFn:e=>r.updateProject(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project`,k]}),d.invalidateQueries({queryKey:[`projects`]}),w(!1),T(!1),h(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{h(e.message,`error`)}}),et=()=>{E(A?.notes||``),T(!0)},tt=()=>{z.mutate({notes:Ue})},nt=()=>{T(!1),E(``)},[B,rt]=(0,y.useState)(``),[it,at]=(0,y.useState)(1),[V,ot]=(0,y.useState)(``),[st,ct]=(0,y.useState)(``),[lt,ut]=(0,y.useState)(``),[dt,H]=(0,y.useState)(!1),[U,ft]=(0,y.useState)(!1),[W,G]=(0,y.useState)(null),[K,pt]=(0,y.useState)(``),[mt,ht]=(0,y.useState)(1),[q,gt]=(0,y.useState)(``),[_t,vt]=(0,y.useState)(``),[yt,bt]=(0,y.useState)(``),[J,Y]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),X=s({mutationFn:e=>r.createBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),rt(``),at(1),ot(``),ct(``),ut(``),H(!1),h(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>h(e.message,`error`)}),Z=s({mutationFn:({itemId:e,data:t})=>r.updateBOMItem(k,e,t),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),G(null)},onError:e=>h(e.message,`error`)}),xt=s({mutationFn:e=>r.deleteBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),h(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>h(e.message,`error`)}),St=e=>{e.preventDefault(),B.trim()&&X.mutate({name:B.trim(),quantity_needed:it,unit_price:V?parseFloat(V):void 0,sourcing_url:st.trim()||void 0,remarks:lt.trim()||void 0})},Ct=e=>{let t=e.is_complete?0:e.quantity_needed;Z.mutate({itemId:e.id,data:{quantity_acquired:t}})},wt=(e,t)=>{Y({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{Y(e=>({...e,isOpen:!1})),xt.mutate(e)}})},Tt=e=>{G(e),pt(e.name),ht(e.quantity_needed),gt(e.unit_price?.toString()||``),vt(e.sourcing_url||``),bt(e.remarks||``)},Et=e=>{e.preventDefault(),!(!W||!K.trim())&&Z.mutate({itemId:W.id,data:{name:K.trim(),quantity_needed:mt,unit_price:q?parseFloat(q):void 0,sourcing_url:_t.trim()||void 0,remarks:yt.trim()||void 0}})},Dt=()=>{G(null)},Ot=async()=>{try{let{blob:e,filename:t}=await r.exportProjectZip(Number(k)),i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=t||`${A?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(i),h(n(`projectDetail.toast.projectExported`),`success`)}catch(e){h(e.message,`error`)}},kt=s({mutationFn:()=>r.createTemplateFromProject(k),onSuccess:()=>{d.invalidateQueries({queryKey:[`projects`]}),h(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>h(e.message,`error`)}),At=e=>ue(e,$e,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(We)return(0,b.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,b.jsx)(l,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(j||!A)return(0,b.jsxs)(`div`,{className:`text-center py-24`,children:[(0,b.jsx)(`p`,{className:`text-bambu-gray`,children:j?`${n(`common.error`)}: ${j.message}`:n(`projectDetail.notFound`)}),(0,b.jsx)(m,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Q=A.stats,jt=Q?.progress_percent??0,$=Q?.parts_progress_percent??0;return(0,b.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,b.jsx)(_,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,b.jsx)(ge,{className:`w-4 h-4`}),(0,b.jsx)(`span`,{className:`text-white`,children:A.name})]}),(0,b.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,b.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,b.jsx)(ee,{className:`w-5 h-5 text-bambu-gray`})}),(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:A.color||`#6b7280`}}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:A.name}),A.description&&(0,b.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:A.description})]})]}),(0,b.jsx)(Le,{status:A.status,t:n})]}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,onClick:Ot,disabled:!C(`projects:read`),title:C(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,b.jsx)(ke,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,b.jsxs)(m,{onClick:()=>w(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(A.target_count||A.target_parts_count||A.target_sets)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4 space-y-4`,children:[A.target_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.total_archives||0,` / `,A.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(jt,100)}%`,backgroundColor:jt>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:jt.toFixed(0)})}),Q?.remaining_prints!=null&&Q.remaining_prints>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_prints})})]})]}),A.target_parts_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.completed_prints||0,` / `,A.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min($,100)}%`,backgroundColor:$>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:$.toFixed(0)})}),Q?.remaining_parts!=null&&Q.remaining_parts>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_parts})})]})]}),A.target_sets?(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.setsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[L??0,` / `,A.target_sets,` `,n(`projectDetail.progress.sets`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min((L??0)/A.target_sets*100,100)}%`,backgroundColor:(L??0)>=A.target_sets?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`projectDetail.progress.setsHint`)})]}):null]})}),Q&&(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,b.jsx)(u,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Q.total_archives,` `,(0,b.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Q.failed_prints>0&&(0,b.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Q.failed_prints})}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Q.completed_prints})})]})]})})}),(0,b.jsx)(Re,{icon:ve,label:n(`projectDetail.stats.printTime`),value:fe(Q.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,b.jsx)(Re,{icon:g,label:n(`projectDetail.stats.filamentUsed`),value:x(Q.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),A.rollup_stats&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.rollup.title`,{count:A.descendant_count})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:A.rollup_stats.total_archives}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:A.rollup_stats.completed_prints})})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printTime`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:fe(A.rollup_stats.total_print_time_hours)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.filamentUsed`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:x(A.rollup_stats.total_filament_grams)})]}),(()=>{let e=A.rollup_stats.estimated_cost+A.rollup_stats.total_energy_cost+(A.rollup_stats.total_wear_cost??0)+A.rollup_stats.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]})]})})()]}),A.rollup_stats.progress_percent!==null&&(0,b.jsxs)(`div`,{className:`mt-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.rollup.progress`)}),(0,b.jsx)(`span`,{className:`text-sm font-medium text-white`,children:n(`projectDetail.rollup.percentComplete`,{percent:A.rollup_stats.progress_percent.toFixed(0)})})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(A.rollup_stats.progress_percent,100)}%`,backgroundColor:A.rollup_stats.progress_percent>=100?`#22c55e`:A.color||`#6b7280`}})})]})]})}),Q&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return Q.estimated_cost>0||e>0||A.budget!==null})()&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.estimated_cost.toFixed(2)]})]}),Q.total_energy_kwh>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Q.total_energy_kwh.toFixed(3),` kWh`,Q.total_energy_cost>0&&(0,b.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,R,Q.total_energy_cost.toFixed(2),`)`]})]})]}),(Q.total_wear_cost??0)>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.wear`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.total_wear_cost.toFixed(2)]})]}),(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]}),Q.bom_cost>0&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),A.budget!==null&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost,t=A.budget-e;return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,b.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,b.jsxs)(`span`,{className:`text-white font-semibold`,children:[R,A.budget.toFixed(2)]})]}),(0,b.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,b.jsxs)(`span`,{className:`font-semibold`,children:[R,t.toFixed(2)]})]})]})})()]})]})}),A.children&&A.children.length>0&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:A.children.length})]}),(0,b.jsx)(`div`,{className:`space-y-2`,children:A.children.map(e=>(0,b.jsxs)(_,{to:`/projects/${e.id}`,className:`flex items-center justify-between gap-4 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#6b7280`}}),(0,b.jsx)(`span`,{className:`text-white truncate`,children:e.name}),(0,b.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded flex-shrink-0 ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}`,children:e.status}),e.descendant_count>0&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 inline-flex items-center gap-1`,children:[(0,b.jsx)(v,{className:`w-3 h-3`}),e.descendant_count]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray flex-shrink-0`,children:[e.total_archives>0&&(0,b.jsx)(`span`,{className:`hidden sm:inline`,children:n(`projectDetail.subProjects.jobs`,{count:e.total_archives})}),e.total_filament_grams>0&&(0,b.jsx)(`span`,{className:`hidden md:inline`,children:x(e.total_filament_grams)}),e.total_cost>0&&(0,b.jsxs)(`span`,{className:`hidden md:inline`,children:[R,e.total_cost.toFixed(2)]}),e.progress_percent!==null&&(0,b.jsxs)(`span`,{children:[e.progress_percent.toFixed(0),`%`]})]})]},e.id))})]})}),A.parent_id&&A.parent_name&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,b.jsx)(De,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,b.jsx)(_,{to:`/projects/${A.parent_id}`,className:`text-bambu-green hover:underline`,children:A.parent_name})]}),(A.tags||A.due_date||A.priority!==`normal`)&&(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[A.priority&&A.priority!==`normal`&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,b.jsx)(Be,{priority:A.priority,t:n})]}),A.due_date&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ne,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-sm text-white`,children:de(A.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),S(A.due_date,n)&&(0,b.jsxs)(`span`,{className:`text-xs ${S(A.due_date,n).color}`,children:[`(`,S(A.due_date,n).label,`)`]})]}),A.tags&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ye,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:A.tags.split(`,`).map((e,t)=>(0,b.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ae,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),He?(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:nt,disabled:z.isPending,children:[(0,b.jsx)(le,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,b.jsxs)(m,{size:`sm`,onClick:tt,disabled:z.isPending,children:[z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-1`}):(0,b.jsx)(xe,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:et,disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),He?(0,b.jsx)(te,{content:Ue,onChange:E,placeholder:n(`projectDetail.notes.placeholder`)}):A.notes?(0,b.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:Ne.sanitize(A.notes)}}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,b.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,b.jsx)(_,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),P&&P.length>0?(0,b.jsx)(`div`,{className:`space-y-4`,children:P.map(e=>{let t=Ze.get(e.id)??[],i=Xe;return(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(_,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,b.jsx)(ge,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),i?(0,b.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,b.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,b.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=Pe(e);return(0,b.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,b.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,b.jsx)(oe,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,b.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(()=>{let t=I.get(e.id)??0,r=A.target_sets;if(!r)return t>0?(0,b.jsxs)(`span`,{className:`shrink-0 text-xs px-1.5 py-0.5 rounded-full bg-bambu-dark text-bambu-gray`,title:n(`projectDetail.files.printedCount`,{count:t}),children:[t,`×`]}):null;let i=Math.min(t/r*100,100),a=t>=r?`text-status-ok`:t>0?`text-status-warning`:`text-bambu-gray`,o=t>=r?`bg-status-ok`:t>0?`bg-status-warning`:`bg-bambu-gray`;return(0,b.jsxs)(`div`,{className:`shrink-0 w-20`,title:n(`projectDetail.files.progressTooltip`,{done:t,target:r}),children:[(0,b.jsxs)(`p`,{className:`text-xs font-medium text-right ${a}`,children:[t,` / `,r]}),(0,b.jsx)(`div`,{className:`h-1 bg-bambu-dark rounded-full overflow-hidden mt-1`,children:(0,b.jsx)(`div`,{className:`h-full ${o}`,style:{width:`${i}%`}})})]})})(),t&&(0,b.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,b.jsx)(`button`,{onClick:()=>O(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,b.jsx)(g,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Me,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Q&&Q.bom_total_items>0&&(0,b.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Q.bom_completed_items,total:Q.bom_total_items}),`)`]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[M&&M.some(e=>e.is_complete)&&(0,b.jsx)(`button`,{onClick:()=>ft(!U),className:`text-xs px-2 py-1 rounded transition-colors ${U?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(U?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!dt&&(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,b.jsx)(Ce,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),dt&&(0,b.jsxs)(`form`,{onSubmit:St,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:B,onChange:e=>rt(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:it,onChange:at,fallback:1,className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:1,placeholder:n(`projectDetail.bom.qty`)}),(0,b.jsx)(`input`,{type:`number`,step:`0.01`,value:V,onChange:e=>ot(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:st,onChange:e=>ct(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,b.jsx)(`input`,{type:`text`,value:lt,onChange:e=>ut(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!B.trim()||X.isPending,children:X.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),qe?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):M&&M.length>0?(0,b.jsxs)(`div`,{className:`space-y-2`,children:[M.filter(e=>!U||!e.is_complete).map(e=>(0,b.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:W?.id===e.id?(0,b.jsxs)(`form`,{onSubmit:Et,className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:K,onChange:e=>pt(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:mt,onChange:ht,fallback:1,className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:1,placeholder:n(`projectDetail.bom.qty`)}),(0,b.jsx)(`input`,{type:`number`,step:`0.01`,value:q,onChange:e=>gt(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:_t,onChange:e=>vt(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,b.jsx)(`input`,{type:`text`,value:yt,onChange:e=>bt(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:Dt,children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!K.trim()||Z.isPending,children:Z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,b.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Ct(e),disabled:Z.isPending||!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:C(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,b.jsx)(c,{className:`w-3 h-3`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,b.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,b.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[R,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Tt(e),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,b.jsx)(pe,{className:`w-4 h-4`})}),(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&wt(e.id,e.name),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,b.jsx)(me,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,b.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-700 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,b.jsx)(he,{className:`w-3 h-3 shrink-0`}),(0,b.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,b.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Q&&Q.bom_cost>0&&(0,b.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,b.jsxs)(`span`,{className:`text-white font-medium`,children:[R,Q.bom_cost.toFixed(2)]})]})]}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(se,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),Je?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):N&&N.length>0?(0,b.jsx)(`div`,{className:`space-y-3`,children:N.slice(0,10).map((e,t)=>(0,b.jsxs)(`div`,{className:`flex gap-3`,children:[(0,b.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,b.jsx)(c,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,b.jsx)(re,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,b.jsx)(g,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,b.jsx)(Ie,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,b.jsx)(Ce,{className:`w-4 h-4`})]}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:At(e.timestamp)})]})]},t))}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!A.is_template&&(0,b.jsx)(`div`,{className:`flex justify-end`,children:(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>kt.mutate(),disabled:kt.isPending||!C(`projects:create`),title:C(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[kt.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-2`}):(0,b.jsx)(ae,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Q&&(Q.queued_prints>0||Q.in_progress_prints>0)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ie,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,b.jsx)(_,{to:`/queue?project=${k}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Q.in_progress_prints>0&&(0,b.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Q.in_progress_prints})}),Q.queued_prints>0&&(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Q.queued_prints})})]})]})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(u,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:Ge?.length||0})]})}),Ke?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,b.jsx)(ze,{archives:Ge||[],t:n})]}),Ve&&(0,b.jsx)(Fe,{t:n,currencySymbol:R,project:{...A,archive_count:Q?.total_archives||0,total_items:Q?.total_items||0,completed_count:Q?.completed_prints||0,failed_count:Q?.failed_prints||0,queue_count:Q?.queued_prints||0,progress_percent:Q?.progress_percent||null,child_count:A.children?.length??0,archives:[]},onClose:()=>w(!1),onSave:e=>z.mutate(e),isLoading:z.isPending}),J.isOpen&&(0,b.jsx)(we,{title:J.title,message:J.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:J.onConfirm,onCancel:()=>Y(e=>({...e,isOpen:!1}))}),D&&(0,b.jsx)(Ee,{mode:`create`,libraryFileId:D.id,archiveName:D.print_name||D.filename,projectId:k,onClose:()=>O(null),onSuccess:()=>{O(null),d.invalidateQueries({queryKey:[`archives`]}),d.invalidateQueries({queryKey:[`queue`]})}})]})}export{C as ProjectDetailPage};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as ee}from"./arrow-left-MSgMxOFV.js";import{t as te}from"./RichTextEditor-CvxzYgcv.js";import{t as ne}from"./calendar-DiVEdzUw.js";import{n as re}from"./info-DcT0QU8O.js";import{n as ie,r as c}from"./ToastContext-VFOrCCoA.js";import{t as ae}from"./copy-3N5VKzXz.js";import{t as oe}from"./file-box-BjB1o93N.js";import{t as se}from"./history-BBZbf3sJ.js";import{t as l}from"./loader-circle-CB4leTZa.js";import{t as u}from"./package-D9xR0eOt.js";import{t as ce}from"./pen-line-DYnjxVtS.js";import{t as d}from"./triangle-alert-gIik0G2C.js";import{t as le}from"./x-Dctff5l9.js";import{n as f,t as p}from"./Card-OUAj0Ayh.js";import{t as m}from"./Button-pwVKPiYn.js";import{a as ue,i as de,s as fe,v as h}from"./date-G9KUauqz.js";import{$t as pe,At as me,Cn as he,Jt as g,Mn as ge,N as _e,On as ve,Pt as ye,Rn as _,Un as be,Ut as xe,Vn as Se,Zt as Ce,_t as we,at as Te,b as Ee,cn as De,vn as Oe,wn as ke,xn as Ae,yt as je,zt as Me}from"./index-ggB_TpPo.js";import{t as Ne}from"./purify.es-F_7NWVtX.js";import{n as Pe}from"./libraryFiles-B0B1SFfn.js";import{ProjectModal as Fe,n as v,t as Ie}from"./ProjectsPage-BH4lIFv4.js";var y=e(n(),1),b=t();function x(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function Le({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,b.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function Re({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,b.jsx)(e,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,b.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function ze({archives:e,t}){return e.length===0?(0,b.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,b.jsx)(u,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,b.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,b.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,b.jsxs)(_,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,b.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,b.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,b.jsx)(u,{className:`w-8 h-8`})}),e.status===`failed`&&(0,b.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,b.jsx)(re,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,b.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,b.jsx)(c,{className:`w-4 h-4 text-bambu-green`})}),(0,b.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,b.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function Be({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,b.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,b.jsx)(d,{className:`w-3 h-3`}),i]})}function S(e,t){if(!e)return null;let n=h(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-700 dark:text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-700 dark:text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-700 dark:text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function C(){let{id:e}=be(),t=Se(),{t:n}=i(),d=a(),{showToast:h}=ie(),{hasPermission:C}=je(),[Ve,w]=(0,y.useState)(!1),[He,T]=(0,y.useState)(!1),[Ue,E]=(0,y.useState)(``),[D,O]=(0,y.useState)(null),k=parseInt(e||`0`,10),{data:A,isLoading:We,error:j}=o({queryKey:[`project`,k],queryFn:()=>r.getProject(k),enabled:k>0}),{data:Ge,isLoading:Ke}=o({queryKey:[`project-archives`,k],queryFn:()=>r.getProjectArchives(k),enabled:k>0}),{data:M,isLoading:qe}=o({queryKey:[`project-bom`,k],queryFn:()=>r.getProjectBOM(k),enabled:k>0}),{data:N,isLoading:Je}=o({queryKey:[`project-timeline`,k],queryFn:()=>r.getProjectTimeline(k,20),enabled:k>0}),{data:Ye}=o({queryKey:[`settings`],queryFn:r.getSettings}),{data:P}=o({queryKey:[`project-folders`,k],queryFn:()=>r.getLibraryFoldersByProject(k),enabled:k>0}),{data:F,isLoading:Xe}=o({queryKey:[`project-files`,k],queryFn:()=>r.getLibraryFiles(null,!1,k),enabled:k>0}),Ze=(0,y.useMemo)(()=>{let e=new Map;for(let t of F??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[F]),{data:Qe}=o({queryKey:[`project-file-progress`,k],queryFn:()=>r.getProjectFileProgress(k),enabled:k>0}),I=(0,y.useMemo)(()=>{let e=new Map;for(let t of Qe??[])e.set(t.file_id,t.completed_count);return e},[Qe]),L=(0,y.useMemo)(()=>{let e=A?.target_sets;if(!e||!F)return null;let t=F.filter(e=>Pe(e));return t.length===0?null:Math.min(...t.map(t=>Math.min(I.get(t.id)??0,e)))},[A?.target_sets,F,I]),R=Te(Ye?.currency||`USD`),$e=Ye?.time_format||`system`,z=s({mutationFn:e=>r.updateProject(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project`,k]}),d.invalidateQueries({queryKey:[`projects`]}),w(!1),T(!1),h(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{h(e.message,`error`)}}),et=()=>{E(A?.notes||``),T(!0)},tt=()=>{z.mutate({notes:Ue})},nt=()=>{T(!1),E(``)},[B,rt]=(0,y.useState)(``),[it,at]=(0,y.useState)(1),[V,ot]=(0,y.useState)(``),[st,ct]=(0,y.useState)(``),[lt,ut]=(0,y.useState)(``),[dt,H]=(0,y.useState)(!1),[U,ft]=(0,y.useState)(!1),[W,G]=(0,y.useState)(null),[K,pt]=(0,y.useState)(``),[mt,ht]=(0,y.useState)(1),[q,gt]=(0,y.useState)(``),[_t,vt]=(0,y.useState)(``),[yt,bt]=(0,y.useState)(``),[J,Y]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),X=s({mutationFn:e=>r.createBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),rt(``),at(1),ot(``),ct(``),ut(``),H(!1),h(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>h(e.message,`error`)}),Z=s({mutationFn:({itemId:e,data:t})=>r.updateBOMItem(k,e,t),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),G(null)},onError:e=>h(e.message,`error`)}),xt=s({mutationFn:e=>r.deleteBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),h(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>h(e.message,`error`)}),St=e=>{e.preventDefault(),B.trim()&&X.mutate({name:B.trim(),quantity_needed:it,unit_price:V?parseFloat(V):void 0,sourcing_url:st.trim()||void 0,remarks:lt.trim()||void 0})},Ct=e=>{let t=e.is_complete?0:e.quantity_needed;Z.mutate({itemId:e.id,data:{quantity_acquired:t}})},wt=(e,t)=>{Y({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{Y(e=>({...e,isOpen:!1})),xt.mutate(e)}})},Tt=e=>{G(e),pt(e.name),ht(e.quantity_needed),gt(e.unit_price?.toString()||``),vt(e.sourcing_url||``),bt(e.remarks||``)},Et=e=>{e.preventDefault(),!(!W||!K.trim())&&Z.mutate({itemId:W.id,data:{name:K.trim(),quantity_needed:mt,unit_price:q?parseFloat(q):void 0,sourcing_url:_t.trim()||void 0,remarks:yt.trim()||void 0}})},Dt=()=>{G(null)},Ot=async()=>{try{let{blob:e,filename:t}=await r.exportProjectZip(Number(k)),i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=t||`${A?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(i),h(n(`projectDetail.toast.projectExported`),`success`)}catch(e){h(e.message,`error`)}},kt=s({mutationFn:()=>r.createTemplateFromProject(k),onSuccess:()=>{d.invalidateQueries({queryKey:[`projects`]}),h(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>h(e.message,`error`)}),At=e=>ue(e,$e,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(We)return(0,b.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,b.jsx)(l,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(j||!A)return(0,b.jsxs)(`div`,{className:`text-center py-24`,children:[(0,b.jsx)(`p`,{className:`text-bambu-gray`,children:j?`${n(`common.error`)}: ${j.message}`:n(`projectDetail.notFound`)}),(0,b.jsx)(m,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Q=A.stats,jt=Q?.progress_percent??0,$=Q?.parts_progress_percent??0;return(0,b.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,b.jsx)(_,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,b.jsx)(ge,{className:`w-4 h-4`}),(0,b.jsx)(`span`,{className:`text-white`,children:A.name})]}),(0,b.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,b.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,b.jsx)(ee,{className:`w-5 h-5 text-bambu-gray`})}),(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:A.color||`#6b7280`}}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:A.name}),A.description&&(0,b.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:A.description})]})]}),(0,b.jsx)(Le,{status:A.status,t:n})]}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,onClick:Ot,disabled:!C(`projects:read`),title:C(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,b.jsx)(ke,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,b.jsxs)(m,{onClick:()=>w(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(A.target_count||A.target_parts_count||A.target_sets)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4 space-y-4`,children:[A.target_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.total_archives||0,` / `,A.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(jt,100)}%`,backgroundColor:jt>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:jt.toFixed(0)})}),Q?.remaining_prints!=null&&Q.remaining_prints>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_prints})})]})]}),A.target_parts_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.completed_prints||0,` / `,A.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min($,100)}%`,backgroundColor:$>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:$.toFixed(0)})}),Q?.remaining_parts!=null&&Q.remaining_parts>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_parts})})]})]}),A.target_sets?(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.setsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[L??0,` / `,A.target_sets,` `,n(`projectDetail.progress.sets`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min((L??0)/A.target_sets*100,100)}%`,backgroundColor:(L??0)>=A.target_sets?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`projectDetail.progress.setsHint`)})]}):null]})}),Q&&(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,b.jsx)(u,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Q.total_archives,` `,(0,b.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Q.failed_prints>0&&(0,b.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Q.failed_prints})}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Q.completed_prints})})]})]})})}),(0,b.jsx)(Re,{icon:ve,label:n(`projectDetail.stats.printTime`),value:fe(Q.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,b.jsx)(Re,{icon:g,label:n(`projectDetail.stats.filamentUsed`),value:x(Q.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),A.rollup_stats&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.rollup.title`,{count:A.descendant_count})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:A.rollup_stats.total_archives}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:A.rollup_stats.completed_prints})})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printTime`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:fe(A.rollup_stats.total_print_time_hours)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.filamentUsed`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:x(A.rollup_stats.total_filament_grams)})]}),(()=>{let e=A.rollup_stats.estimated_cost+A.rollup_stats.total_energy_cost+(A.rollup_stats.total_wear_cost??0)+A.rollup_stats.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]})]})})()]}),A.rollup_stats.progress_percent!==null&&(0,b.jsxs)(`div`,{className:`mt-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.rollup.progress`)}),(0,b.jsx)(`span`,{className:`text-sm font-medium text-white`,children:n(`projectDetail.rollup.percentComplete`,{percent:A.rollup_stats.progress_percent.toFixed(0)})})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(A.rollup_stats.progress_percent,100)}%`,backgroundColor:A.rollup_stats.progress_percent>=100?`#22c55e`:A.color||`#6b7280`}})})]})]})}),Q&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return Q.estimated_cost>0||e>0||A.budget!==null})()&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.estimated_cost.toFixed(2)]})]}),Q.total_energy_kwh>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Q.total_energy_kwh.toFixed(3),` kWh`,Q.total_energy_cost>0&&(0,b.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,R,Q.total_energy_cost.toFixed(2),`)`]})]})]}),(Q.total_wear_cost??0)>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.wear`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.total_wear_cost.toFixed(2)]})]}),(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]}),Q.bom_cost>0&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),A.budget!==null&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost,t=A.budget-e;return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,b.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,b.jsxs)(`span`,{className:`text-white font-semibold`,children:[R,A.budget.toFixed(2)]})]}),(0,b.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,b.jsxs)(`span`,{className:`font-semibold`,children:[R,t.toFixed(2)]})]})]})})()]})]})}),A.children&&A.children.length>0&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:A.children.length})]}),(0,b.jsx)(`div`,{className:`space-y-2`,children:A.children.map(e=>(0,b.jsxs)(_,{to:`/projects/${e.id}`,className:`flex items-center justify-between gap-4 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#6b7280`}}),(0,b.jsx)(`span`,{className:`text-white truncate`,children:e.name}),(0,b.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded flex-shrink-0 ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}`,children:e.status}),e.descendant_count>0&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 inline-flex items-center gap-1`,children:[(0,b.jsx)(v,{className:`w-3 h-3`}),e.descendant_count]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray flex-shrink-0`,children:[e.total_archives>0&&(0,b.jsx)(`span`,{className:`hidden sm:inline`,children:n(`projectDetail.subProjects.jobs`,{count:e.total_archives})}),e.total_filament_grams>0&&(0,b.jsx)(`span`,{className:`hidden md:inline`,children:x(e.total_filament_grams)}),e.total_cost>0&&(0,b.jsxs)(`span`,{className:`hidden md:inline`,children:[R,e.total_cost.toFixed(2)]}),e.progress_percent!==null&&(0,b.jsxs)(`span`,{children:[e.progress_percent.toFixed(0),`%`]})]})]},e.id))})]})}),A.parent_id&&A.parent_name&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,b.jsx)(De,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,b.jsx)(_,{to:`/projects/${A.parent_id}`,className:`text-bambu-green hover:underline`,children:A.parent_name})]}),(A.tags||A.due_date||A.priority!==`normal`)&&(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[A.priority&&A.priority!==`normal`&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,b.jsx)(Be,{priority:A.priority,t:n})]}),A.due_date&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ne,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-sm text-white`,children:de(A.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),S(A.due_date,n)&&(0,b.jsxs)(`span`,{className:`text-xs ${S(A.due_date,n).color}`,children:[`(`,S(A.due_date,n).label,`)`]})]}),A.tags&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ye,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:A.tags.split(`,`).map((e,t)=>(0,b.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ae,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),He?(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:nt,disabled:z.isPending,children:[(0,b.jsx)(le,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,b.jsxs)(m,{size:`sm`,onClick:tt,disabled:z.isPending,children:[z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-1`}):(0,b.jsx)(xe,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:et,disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),He?(0,b.jsx)(te,{content:Ue,onChange:E,placeholder:n(`projectDetail.notes.placeholder`)}):A.notes?(0,b.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:Ne.sanitize(A.notes)}}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,b.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,b.jsx)(_,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),P&&P.length>0?(0,b.jsx)(`div`,{className:`space-y-4`,children:P.map(e=>{let t=Ze.get(e.id)??[],i=Xe;return(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(_,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,b.jsx)(ge,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),i?(0,b.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,b.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,b.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=Pe(e);return(0,b.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,b.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,b.jsx)(oe,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,b.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(()=>{let t=I.get(e.id)??0,r=A.target_sets;if(!r)return t>0?(0,b.jsxs)(`span`,{className:`shrink-0 text-xs px-1.5 py-0.5 rounded-full bg-bambu-dark text-bambu-gray`,title:n(`projectDetail.files.printedCount`,{count:t}),children:[t,`×`]}):null;let i=Math.min(t/r*100,100),a=t>=r?`text-status-ok`:t>0?`text-status-warning`:`text-bambu-gray`,o=t>=r?`bg-status-ok`:t>0?`bg-status-warning`:`bg-bambu-gray`;return(0,b.jsxs)(`div`,{className:`shrink-0 w-20`,title:n(`projectDetail.files.progressTooltip`,{done:t,target:r}),children:[(0,b.jsxs)(`p`,{className:`text-xs font-medium text-right ${a}`,children:[t,` / `,r]}),(0,b.jsx)(`div`,{className:`h-1 bg-bambu-dark rounded-full overflow-hidden mt-1`,children:(0,b.jsx)(`div`,{className:`h-full ${o}`,style:{width:`${i}%`}})})]})})(),t&&(0,b.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,b.jsx)(`button`,{onClick:()=>O(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,b.jsx)(g,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Me,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Q&&Q.bom_total_items>0&&(0,b.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Q.bom_completed_items,total:Q.bom_total_items}),`)`]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[M&&M.some(e=>e.is_complete)&&(0,b.jsx)(`button`,{onClick:()=>ft(!U),className:`text-xs px-2 py-1 rounded transition-colors ${U?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(U?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!dt&&(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,b.jsx)(Ce,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),dt&&(0,b.jsxs)(`form`,{onSubmit:St,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:B,onChange:e=>rt(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:it,onChange:at,fallback:1,className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:1,placeholder:n(`projectDetail.bom.qty`)}),(0,b.jsx)(`input`,{type:`number`,step:`0.01`,value:V,onChange:e=>ot(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:st,onChange:e=>ct(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,b.jsx)(`input`,{type:`text`,value:lt,onChange:e=>ut(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!B.trim()||X.isPending,children:X.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),qe?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):M&&M.length>0?(0,b.jsxs)(`div`,{className:`space-y-2`,children:[M.filter(e=>!U||!e.is_complete).map(e=>(0,b.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:W?.id===e.id?(0,b.jsxs)(`form`,{onSubmit:Et,className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:K,onChange:e=>pt(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:mt,onChange:ht,fallback:1,className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:1,placeholder:n(`projectDetail.bom.qty`)}),(0,b.jsx)(`input`,{type:`number`,step:`0.01`,value:q,onChange:e=>gt(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:_t,onChange:e=>vt(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,b.jsx)(`input`,{type:`text`,value:yt,onChange:e=>bt(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:Dt,children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!K.trim()||Z.isPending,children:Z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,b.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Ct(e),disabled:Z.isPending||!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:C(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,b.jsx)(c,{className:`w-3 h-3`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,b.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,b.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[R,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Tt(e),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,b.jsx)(pe,{className:`w-4 h-4`})}),(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&wt(e.id,e.name),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,b.jsx)(me,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,b.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-700 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,b.jsx)(he,{className:`w-3 h-3 shrink-0`}),(0,b.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,b.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Q&&Q.bom_cost>0&&(0,b.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,b.jsxs)(`span`,{className:`text-white font-medium`,children:[R,Q.bom_cost.toFixed(2)]})]})]}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(se,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),Je?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):N&&N.length>0?(0,b.jsx)(`div`,{className:`space-y-3`,children:N.slice(0,10).map((e,t)=>(0,b.jsxs)(`div`,{className:`flex gap-3`,children:[(0,b.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,b.jsx)(c,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,b.jsx)(re,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,b.jsx)(g,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,b.jsx)(Ie,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,b.jsx)(Ce,{className:`w-4 h-4`})]}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:At(e.timestamp)})]})]},t))}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!A.is_template&&(0,b.jsx)(`div`,{className:`flex justify-end`,children:(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>kt.mutate(),disabled:kt.isPending||!C(`projects:create`),title:C(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[kt.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-2`}):(0,b.jsx)(ae,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Q&&(Q.queued_prints>0||Q.in_progress_prints>0)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ie,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,b.jsx)(_,{to:`/queue?project=${k}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Q.in_progress_prints>0&&(0,b.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Q.in_progress_prints})}),Q.queued_prints>0&&(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Q.queued_prints})})]})]})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(u,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:Ge?.length||0})]})}),Ke?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,b.jsx)(ze,{archives:Ge||[],t:n})]}),Ve&&(0,b.jsx)(Fe,{t:n,currencySymbol:R,project:{...A,archive_count:Q?.total_archives||0,total_items:Q?.total_items||0,completed_count:Q?.completed_prints||0,failed_count:Q?.failed_prints||0,queue_count:Q?.queued_prints||0,progress_percent:Q?.progress_percent||null,child_count:A.children?.length??0,archives:[]},onClose:()=>w(!1),onSave:e=>z.mutate(e),isLoading:z.isPending}),J.isOpen&&(0,b.jsx)(we,{title:J.title,message:J.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:J.onConfirm,onCancel:()=>Y(e=>({...e,isOpen:!1}))}),D&&(0,b.jsx)(Ee,{mode:`create`,libraryFileId:D.id,archiveName:D.print_name||D.filename,projectId:k,onClose:()=>O(null),onSuccess:()=>{O(null),d.invalidateQueries({queryKey:[`archives`]}),d.invalidateQueries({queryKey:[`queue`]})}})]})}export{C as ProjectDetailPage};
\ No newline at end of file
diff --git a/static/assets/ProjectsPage-BvSVSfNa.js b/static/assets/ProjectsPage-BH4lIFv4.js
similarity index 99%
rename from static/assets/ProjectsPage-BvSVSfNa.js
rename to static/assets/ProjectsPage-BH4lIFv4.js
index 26c15f2f3..ccbf3c73f 100644
--- a/static/assets/ProjectsPage-BvSVSfNa.js
+++ b/static/assets/ProjectsPage-BH4lIFv4.js
@@ -1 +1 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./react-dom-xhkz5--P.js";import{n as o}from"./QueryClientProvider-Clbyr4Jg.js";import{t as s}from"./useQuery-CCy0EwsM.js";import{t as c}from"./useMutation-qh3Iyscy.js";import{t as l}from"./createLucideIcon-Yo2YoYjm.js";import{a as u}from"./info-DcT0QU8O.js";import{n as d}from"./ToastContext-VFOrCCoA.js";import{t as f}from"./ellipsis-vertical-So0E77JK.js";import{t as p}from"./loader-circle-CB4leTZa.js";import{t as m}from"./package-D9xR0eOt.js";import{t as h}from"./pen-line-DYnjxVtS.js";import{t as g}from"./triangle-alert-gIik0G2C.js";import{t as _}from"./x-Dctff5l9.js";import{t as v}from"./Button-pwVKPiYn.js";import{An as y,At as b,Cn as x,I as S,Ln as C,Mn as w,On as T,Vn as E,Zt as D,_t as O,at as k,cn as A,kt as j,un as ee,wn as M,yn as N,yt as P}from"./index-Bw-_P2Fg.js";var F=l(`folder-tree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),I=l(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),L=e(n(),1),R=e(a(),1),z=t(),B=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function V({project:e,onClose:t,onSave:n,isLoading:i,currencySymbol:a,t:c}){let[l,u]=(0,L.useState)(e?.name||``),[d,f]=(0,L.useState)(e?.description||``),[m,h]=(0,L.useState)(e?.color||B[0]),[g,y]=(0,L.useState)(e?.target_count?.toString()||``),[b,x]=(0,L.useState)(e?.target_parts_count?.toString()||``),[C,w]=(0,L.useState)(e?.target_sets?.toString()||``),[T,E]=(0,L.useState)(e?.status||`active`),[D,O]=(0,L.useState)(e?.tags||``),[k,A]=(0,L.useState)(e?.due_date?.split(`T`)[0]||``),[M,N]=(0,L.useState)(e?.priority||`normal`),[P,F]=(0,L.useState)(e?.budget?.toString()||``),[I,R]=(0,L.useState)(e?.url||``),[V,H]=(0,L.useState)(null),[U,W]=(0,L.useState)(e?.parent_id??null),G=o(),{data:te}=s({queryKey:[`projects`,void 0],queryFn:()=>r.getProjects()}),K=S(te||[],e?.id),[q,J]=(0,L.useState)(e?.cover_image_filename||null),Y=(0,L.useRef)(null),[X,Z]=(0,L.useState)(!1),[Q,$]=(0,L.useState)(0);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(e?`projects.editProject`:`projects.newProject`)})}),(0,z.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=I.trim();if(r&&!/^https?:\/\//i.test(r)){H(c(`projects.urlInvalid`));return}H(null),n({name:l.trim(),description:d.trim()||void 0,color:m,target_count:g?parseInt(g,10):void 0,target_parts_count:b?parseInt(b,10):void 0,target_sets:e?C?parseInt(C,10):null:C?parseInt(C,10):void 0,tags:e?D.trim()||null:D.trim()||void 0,due_date:e?k||null:k||void 0,priority:M,budget:P.trim()?parseFloat(P):null,url:e?r||null:r||void 0,parent_id:e?U??0:U??void 0,...e&&{status:T}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,z.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.name`)}),(0,z.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.namePlaceholder`),required:!0})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.description`)}),(0,z.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:c(`projects.descriptionPlaceholder`),rows:2})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.urlLabel`)}),(0,z.jsx)(`input`,{type:`url`,value:I,onChange:e=>{R(e.target.value),V&&H(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${V?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:c(`projects.urlPlaceholder`),maxLength:2048}),V&&(0,z.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:V})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.parentLabel`)}),(0,z.jsxs)(`select`,{value:U??``,onChange:e=>W(e.target.value?parseInt(e.target.value,10):null),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:``,children:c(`projects.parentNone`)}),K.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.parentHint`)})]}),e&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.coverImageLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:q?(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e.id,Q),alt:c(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,z.jsx)(ee,{className:`w-6 h-6 text-bambu-gray`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,z.jsx)(`input`,{ref:Y,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){Z(!0);try{J((await r.uploadProjectCoverImage(e.id,n)).filename),$(e=>e+1),G.invalidateQueries({queryKey:[`projects`]})}catch{}finally{Z(!1),Y.current&&(Y.current.value=``)}}},className:`hidden`}),(0,z.jsxs)(v,{type:`button`,variant:`secondary`,onClick:()=>Y.current?.click(),disabled:X,children:[X?(0,z.jsx)(p,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(j,{className:`w-4 h-4 mr-1`}),c(q?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),q&&(0,z.jsxs)(v,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){Z(!0);try{await r.deleteProjectCoverImage(e.id),J(null),$(e=>e+1),G.invalidateQueries({queryKey:[`projects`]})}finally{Z(!1)}}},disabled:X,children:[(0,z.jsx)(_,{className:`w-4 h-4 mr-1`}),c(`projects.coverImageRemove`)]})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.color`)}),(0,z.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:B.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>h(e),className:`w-8 h-8 rounded-full transition-transform ${m===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetPlates`)}),(0,z.jsx)(`input`,{type:`number`,value:g,onChange:e=>y(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.targetPlatesPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetPlatesHelp`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetParts`)}),(0,z.jsx)(`input`,{type:`number`,value:b,onChange:e=>x(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.targetPartsPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetPartsHelp`)})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetSets`)}),(0,z.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.targetSetsPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetSetsHelp`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.tagsLabel`)}),(0,z.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.tagsPlaceholder`)})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.dueDate`)}),(0,z.jsx)(`input`,{type:`date`,value:k,onChange:e=>A(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.priority`)}),(0,z.jsxs)(`select`,{value:M,onChange:e=>N(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`low`,children:c(`projects.priorityLow`)}),(0,z.jsx)(`option`,{value:`normal`,children:c(`projects.priorityNormal`)}),(0,z.jsx)(`option`,{value:`high`,children:c(`projects.priorityHigh`)}),(0,z.jsx)(`option`,{value:`urgent`,children:c(`projects.priorityUrgent`)})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projectDetail.cost.budget`)}),(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:a}),(0,z.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:P,onChange:e=>F(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.status`)}),(0,z.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`active`,children:c(`projects.statusActive`)}),(0,z.jsx)(`option`,{value:`completed`,children:c(`projects.statusCompleted`)}),(0,z.jsx)(`option`,{value:`archived`,children:c(`projects.statusArchived`)})]})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,z.jsx)(v,{type:`button`,variant:`secondary`,onClick:t,children:c(`common.cancel`)}),(0,z.jsx)(v,{type:`submit`,disabled:!l.trim()||i,children:i?(0,z.jsx)(p,{className:`w-4 h-4 animate-spin`}):c(e?`common.save`:`projects.create`)})]})]})]})})}function H({projectId:e,altText:t}){let n=(0,L.useRef)(null),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null);return(0,z.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,i=e.right+8;i+384>t-8&&(i=e.left-384-8);let o=e.top;o+384>r-8&&(o=r-384-8),o<8&&(o=8),s({left:i,top:o}),a(!0)},onMouseLeave:()=>a(!1),onClick:e=>e.stopPropagation(),children:[(0,z.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),i&&o&&(0,R.createPortal)((0,z.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:o.left,top:o.top},"aria-hidden":`true`,children:(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function U({project:e,parentName:t,onClick:n,onEdit:i,onDelete:a,hasPermission:o,t:s}){let c=e.target_count?Math.round(e.archive_count/e.target_count*100):0,l=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,u=e.status===`completed`,d=e.status===`archived`,[p,_]=(0,L.useState)(!1),v=u?{icon:y,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:d?{icon:C,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:T,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:N,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,z.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:n,children:[(0,z.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,z.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,z.jsx)(H,{projectId:e.id,altText:s(`projects.coverImageAlt`)}):(0,z.jsx)(`div`,{className:`p-2 rounded-lg ${v.bg} flex-shrink-0`,children:(0,z.jsx)(v.icon,{className:`w-5 h-5 ${v.color}`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,z.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,z.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":s(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,z.jsx)(x,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,s(`projects.parts`)]}):e.target_count?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${c>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,s(`projects.plates`)]}):e.completed_count>0?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,s(`projects.parts`)]}):null,u&&(0,z.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:s(`projects.done`)}),d&&(0,z.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:s(`projects.statusArchived`)}),e.child_count>0&&(0,z.jsxs)(`span`,{className:`text-xs bg-bambu-dark text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap inline-flex items-center gap-1`,title:s(`projects.subProjectCount`,{count:e.child_count}),children:[(0,z.jsx)(F,{className:`w-3 h-3`}),e.child_count]})]}),t&&(0,z.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-1`,children:[(0,z.jsx)(A,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:s(`projects.partOf`,{name:t})})]}),e.description&&(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,z.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,z.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,z.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,z.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,z.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100`,onClick:()=>_(!p),children:(0,z.jsx)(f,{className:`w-4 h-4`})}),p&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>_(!1)}),(0,z.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,z.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${o(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{o(`projects:update`)&&(i(),_(!1))},disabled:!o(`projects:update`),title:o(`projects:update`)?void 0:s(`projects.noEditPermission`),children:[(0,z.jsx)(h,{className:`w-4 h-4`}),s(`common.edit`)]}),(0,z.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${o(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{o(`projects:delete`)&&(a(),_(!1))},disabled:!o(`projects:delete`),title:o(`projects:delete`)?void 0:s(`projects.noDeletePermission`),children:[(0,z.jsx)(b,{className:`w-4 h-4`}),s(`common.delete`)]})]})]})]})]}),(0,z.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,z.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,z.jsx)(`span`,{className:`text-bambu-gray`,children:s(`projects.plates`)}),(0,z.jsxs)(`span`,{className:c>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,z.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,z.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(c,100)}%`,background:c>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${c>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,z.jsx)(`span`,{className:`text-bambu-gray`,children:s(`projects.parts`)}),(0,z.jsxs)(`span`,{className:l>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,z.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,z.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(l,100)}%`,background:l>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${l>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,s(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,z.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,z.jsx)(C,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.completed_count,` `,s(`projects.completed`)]})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.failed_count,` `,s(`projects.failed`)]})]}),e.queue_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,z.jsx)(T,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.queue_count,` `,s(`projects.inQueue`)]})]})]}):(0,z.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:s(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,z.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,z.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,z.jsx)(m,{className:`w-6 h-6`})}),e.status===`failed`&&(0,z.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,z.jsx)(g,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:s(`common.more`,{count:e.archive_count-4})})]}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:s(`projects.printJobs`),children:[(0,z.jsx)(A,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,z.jsxs)(`span`,{children:[e.archive_count,` `,s(`projects.plates`)]})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:s(`projects.partsPrinted`),children:[(0,z.jsx)(m,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,z.jsxs)(`span`,{children:[e.completed_count,` `,s(`projects.parts`)]})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:s(`projects.failedParts`),children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:s(`projects.inQueue`),children:[(0,z.jsx)(I,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.queue_count})]})]}),(0,z.jsx)(w,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function W(){let{t:e}=i(),t=E(),n=o(),{showToast:a}=d(),{hasPermission:l}=P(),[f,m]=(0,L.useState)(!1),[h,g]=(0,L.useState)(),[_,b]=(0,L.useState)(`active`),[x,S]=(0,L.useState)(null),[A,ee]=(0,L.useState)(()=>localStorage.getItem(`projects-collapse-subprojects`)===`true`),[I,R]=(0,L.useState)({}),B=()=>{let e=!A;ee(e),R({}),localStorage.setItem(`projects-collapse-subprojects`,String(e))},{data:H}=s({queryKey:[`settings`],queryFn:r.getSettings}),W=k(H?.currency||`USD`),{data:G,isLoading:te}=s({queryKey:[`projects`,_===`all`?void 0:_],queryFn:()=>r.getProjects(_===`all`?void 0:_)}),{data:K}=s({queryKey:[`projects`,void 0],queryFn:()=>r.getProjects()}),q=new Map((K||[]).map(e=>[e.id,e.name])),J=G||[],Y=new Set(J.map(e=>e.id)),X=new Map;for(let e of J)if(e.parent_id!==null&&Y.has(e.parent_id)){let t=X.get(e.parent_id)||[];t.push(e),X.set(e.parent_id,t)}let Z=new Set,Q=e=>{if(!Z.has(e)){Z.add(e);for(let t of X.get(e)||[])Q(t.id)}},$=[];for(let e of J)e.parent_id!==null&&Y.has(e.parent_id)||($.push(e),Q(e.id));for(let e of J)Z.has(e.id)||($.push(e),Q(e.id));let ne=(t,n,r)=>{let i=(0,z.jsx)(U,{project:t,parentName:n===0&&t.parent_id!==null?q.get(t.parent_id):void 0,onClick:()=>pe(t),onEdit:()=>fe(t),onDelete:()=>me(t.id),hasPermission:l,t:e}),a=new Set(r).add(t.id),o=(X.get(t.id)||[]).filter(e=>!a.has(e.id));if(o.length===0)return(0,z.jsx)(`div`,{children:i},t.id);let s=I[t.id]??!A;return(0,z.jsxs)(`div`,{className:s?`col-span-full space-y-4`:`space-y-4`,children:[i,(0,z.jsxs)(`div`,{className:`ml-4 md:ml-8 pl-4 md:pl-6 border-l-2 rounded-l space-y-4`,style:{borderColor:t.color||`#6b7280`},children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>R(e=>({...e,[t.id]:!s})),"aria-expanded":s,title:e(s?`projects.collapseSubProjects`:`projects.expandSubProjects`),className:`text-xs uppercase tracking-wide text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5 max-w-full min-w-0`,children:[s?(0,z.jsx)(u,{className:`w-3.5 h-3.5 flex-shrink-0`}):(0,z.jsx)(w,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,z.jsx)(F,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e(`projects.subProjectsOf`,{name:t.name})}),(0,z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark normal-case tracking-normal flex-shrink-0`,children:o.length})]}),s&&(0,z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-8`,children:o.map(e=>ne(e,n+1,a))})]})]},t.id)},re=c({mutationFn:e=>r.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),m(!1),a(e(`projects.toast.created`),`success`)},onError:e=>{a(e.message,`error`)}}),ie=c({mutationFn:({id:e,data:t})=>r.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),m(!1),g(void 0),a(e(`projects.toast.updated`),`success`)},onError:e=>{a(e.message,`error`)}}),ae=c({mutationFn:e=>r.deleteProject(e),onSuccess:()=>{S(null),a(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{S(null),a(e.message,`error`)}}),oe=c({mutationFn:e=>r.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),a(e(`projects.toast.imported`),`success`)},onError:e=>{a(e.message,`error`)}}),se=(0,L.useRef)(null),ce=async()=>{try{let t=await r.getProjects(),n=await Promise.all(t.map(async e=>await r.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,s.click(),URL.revokeObjectURL(o),a(e(`projects.toast.exported`),`success`)}catch(e){a(e.message,`error`)}},le=()=>{se.current?.click()},ue=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await r.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),a(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),r=Array.isArray(n)?n:[n];for(let e of r)await oe.mutateAsync(e);r.length>1&&a(e(`projects.toast.multipleImported`,{count:r.length}),`success`)}}catch(t){a(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},de=e=>{h?ie.mutate({id:h.id,data:e}):re.mutate(e)},fe=e=>{g(e),m(!0)},pe=e=>{t(`/projects/${e.id}`)},me=e=>{S(e)},he=()=>{x!==null&&ae.mutate(x)},ge=K?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,z.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,z.jsx)(`input`,{ref:se,type:`file`,accept:`.json,.zip`,onChange:ue,className:`hidden`}),(0,z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(v,{variant:`secondary`,onClick:le,disabled:!l(`projects:create`),title:l(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,z.jsx)(j,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,z.jsxs)(v,{variant:`secondary`,onClick:ce,disabled:!l(`projects:read`),title:l(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,z.jsx)(M,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,z.jsxs)(v,{onClick:()=>m(!0),className:`sm:w-auto w-full`,disabled:!l(`projects:create`),title:l(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,z.jsx)(D,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,z.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:T},{key:`completed`,label:e(`projects.statusCompleted`),icon:y},{key:`archived`,label:e(`projects.statusArchived`),icon:C},{key:`all`,label:e(`common.all`),icon:N}].map(({key:e,label:t,icon:n})=>(0,z.jsxs)(`button`,{onClick:()=>b(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${_===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(n,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{children:t}),ge[e]>0&&(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${_===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:ge[e]})]},e))}),X.size>0&&(0,z.jsxs)(`button`,{type:`button`,onClick:B,"aria-pressed":A,title:e(A?`projects.expandSubProjects`:`projects.collapseSubProjects`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-lg transition-colors ${A?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,children:[(0,z.jsx)(F,{className:`w-4 h-4`}),e(`common.collapse`)]})]}),te?(0,z.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,z.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,z.jsx)(p,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):G?.length===0?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(N,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:_===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:_})}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:_===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:_})}),_===`all`&&(0,z.jsxs)(v,{onClick:()=>m(!0),disabled:!l(`projects:create`),title:l(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,z.jsx)(D,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:$.map(e=>ne(e,0,new Set))}),x!==null&&(0,z.jsx)(O,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:he,onCancel:()=>S(null)}),f&&(0,z.jsx)(V,{project:h,onClose:()=>{m(!1),g(void 0)},onSave:de,isLoading:re.isPending||ie.isPending,currencySymbol:W,t:e})]})}export{V as ProjectModal,W as ProjectsPage,F as n,I as t};
\ No newline at end of file
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./react-dom-xhkz5--P.js";import{n as o}from"./QueryClientProvider-Clbyr4Jg.js";import{t as s}from"./useQuery-CCy0EwsM.js";import{t as c}from"./useMutation-qh3Iyscy.js";import{t as l}from"./createLucideIcon-Yo2YoYjm.js";import{a as u}from"./info-DcT0QU8O.js";import{n as d}from"./ToastContext-VFOrCCoA.js";import{t as f}from"./ellipsis-vertical-So0E77JK.js";import{t as p}from"./loader-circle-CB4leTZa.js";import{t as m}from"./package-D9xR0eOt.js";import{t as h}from"./pen-line-DYnjxVtS.js";import{t as g}from"./triangle-alert-gIik0G2C.js";import{t as _}from"./x-Dctff5l9.js";import{t as v}from"./Button-pwVKPiYn.js";import{An as y,At as b,Cn as x,I as S,Ln as C,Mn as w,On as T,Vn as E,Zt as D,_t as O,at as k,cn as A,kt as j,un as ee,wn as M,yn as N,yt as P}from"./index-ggB_TpPo.js";var F=l(`folder-tree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),I=l(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),L=e(n(),1),R=e(a(),1),z=t(),B=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function V({project:e,onClose:t,onSave:n,isLoading:i,currencySymbol:a,t:c}){let[l,u]=(0,L.useState)(e?.name||``),[d,f]=(0,L.useState)(e?.description||``),[m,h]=(0,L.useState)(e?.color||B[0]),[g,y]=(0,L.useState)(e?.target_count?.toString()||``),[b,x]=(0,L.useState)(e?.target_parts_count?.toString()||``),[C,w]=(0,L.useState)(e?.target_sets?.toString()||``),[T,E]=(0,L.useState)(e?.status||`active`),[D,O]=(0,L.useState)(e?.tags||``),[k,A]=(0,L.useState)(e?.due_date?.split(`T`)[0]||``),[M,N]=(0,L.useState)(e?.priority||`normal`),[P,F]=(0,L.useState)(e?.budget?.toString()||``),[I,R]=(0,L.useState)(e?.url||``),[V,H]=(0,L.useState)(null),[U,W]=(0,L.useState)(e?.parent_id??null),G=o(),{data:te}=s({queryKey:[`projects`,void 0],queryFn:()=>r.getProjects()}),K=S(te||[],e?.id),[q,J]=(0,L.useState)(e?.cover_image_filename||null),Y=(0,L.useRef)(null),[X,Z]=(0,L.useState)(!1),[Q,$]=(0,L.useState)(0);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(e?`projects.editProject`:`projects.newProject`)})}),(0,z.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=I.trim();if(r&&!/^https?:\/\//i.test(r)){H(c(`projects.urlInvalid`));return}H(null),n({name:l.trim(),description:d.trim()||void 0,color:m,target_count:g?parseInt(g,10):void 0,target_parts_count:b?parseInt(b,10):void 0,target_sets:e?C?parseInt(C,10):null:C?parseInt(C,10):void 0,tags:e?D.trim()||null:D.trim()||void 0,due_date:e?k||null:k||void 0,priority:M,budget:P.trim()?parseFloat(P):null,url:e?r||null:r||void 0,parent_id:e?U??0:U??void 0,...e&&{status:T}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,z.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.name`)}),(0,z.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.namePlaceholder`),required:!0})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.description`)}),(0,z.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:c(`projects.descriptionPlaceholder`),rows:2})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.urlLabel`)}),(0,z.jsx)(`input`,{type:`url`,value:I,onChange:e=>{R(e.target.value),V&&H(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${V?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:c(`projects.urlPlaceholder`),maxLength:2048}),V&&(0,z.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:V})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.parentLabel`)}),(0,z.jsxs)(`select`,{value:U??``,onChange:e=>W(e.target.value?parseInt(e.target.value,10):null),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:``,children:c(`projects.parentNone`)}),K.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.parentHint`)})]}),e&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.coverImageLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:q?(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e.id,Q),alt:c(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,z.jsx)(ee,{className:`w-6 h-6 text-bambu-gray`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,z.jsx)(`input`,{ref:Y,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){Z(!0);try{J((await r.uploadProjectCoverImage(e.id,n)).filename),$(e=>e+1),G.invalidateQueries({queryKey:[`projects`]})}catch{}finally{Z(!1),Y.current&&(Y.current.value=``)}}},className:`hidden`}),(0,z.jsxs)(v,{type:`button`,variant:`secondary`,onClick:()=>Y.current?.click(),disabled:X,children:[X?(0,z.jsx)(p,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(j,{className:`w-4 h-4 mr-1`}),c(q?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),q&&(0,z.jsxs)(v,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){Z(!0);try{await r.deleteProjectCoverImage(e.id),J(null),$(e=>e+1),G.invalidateQueries({queryKey:[`projects`]})}finally{Z(!1)}}},disabled:X,children:[(0,z.jsx)(_,{className:`w-4 h-4 mr-1`}),c(`projects.coverImageRemove`)]})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.color`)}),(0,z.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:B.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>h(e),className:`w-8 h-8 rounded-full transition-transform ${m===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetPlates`)}),(0,z.jsx)(`input`,{type:`number`,value:g,onChange:e=>y(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.targetPlatesPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetPlatesHelp`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetParts`)}),(0,z.jsx)(`input`,{type:`number`,value:b,onChange:e=>x(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.targetPartsPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetPartsHelp`)})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetSets`)}),(0,z.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.targetSetsPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetSetsHelp`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.tagsLabel`)}),(0,z.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.tagsPlaceholder`)})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.dueDate`)}),(0,z.jsx)(`input`,{type:`date`,value:k,onChange:e=>A(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.priority`)}),(0,z.jsxs)(`select`,{value:M,onChange:e=>N(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`low`,children:c(`projects.priorityLow`)}),(0,z.jsx)(`option`,{value:`normal`,children:c(`projects.priorityNormal`)}),(0,z.jsx)(`option`,{value:`high`,children:c(`projects.priorityHigh`)}),(0,z.jsx)(`option`,{value:`urgent`,children:c(`projects.priorityUrgent`)})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projectDetail.cost.budget`)}),(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:a}),(0,z.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:P,onChange:e=>F(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.status`)}),(0,z.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`active`,children:c(`projects.statusActive`)}),(0,z.jsx)(`option`,{value:`completed`,children:c(`projects.statusCompleted`)}),(0,z.jsx)(`option`,{value:`archived`,children:c(`projects.statusArchived`)})]})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,z.jsx)(v,{type:`button`,variant:`secondary`,onClick:t,children:c(`common.cancel`)}),(0,z.jsx)(v,{type:`submit`,disabled:!l.trim()||i,children:i?(0,z.jsx)(p,{className:`w-4 h-4 animate-spin`}):c(e?`common.save`:`projects.create`)})]})]})]})})}function H({projectId:e,altText:t}){let n=(0,L.useRef)(null),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null);return(0,z.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,i=e.right+8;i+384>t-8&&(i=e.left-384-8);let o=e.top;o+384>r-8&&(o=r-384-8),o<8&&(o=8),s({left:i,top:o}),a(!0)},onMouseLeave:()=>a(!1),onClick:e=>e.stopPropagation(),children:[(0,z.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),i&&o&&(0,R.createPortal)((0,z.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:o.left,top:o.top},"aria-hidden":`true`,children:(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function U({project:e,parentName:t,onClick:n,onEdit:i,onDelete:a,hasPermission:o,t:s}){let c=e.target_count?Math.round(e.archive_count/e.target_count*100):0,l=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,u=e.status===`completed`,d=e.status===`archived`,[p,_]=(0,L.useState)(!1),v=u?{icon:y,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:d?{icon:C,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:T,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:N,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,z.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:n,children:[(0,z.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,z.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,z.jsx)(H,{projectId:e.id,altText:s(`projects.coverImageAlt`)}):(0,z.jsx)(`div`,{className:`p-2 rounded-lg ${v.bg} flex-shrink-0`,children:(0,z.jsx)(v.icon,{className:`w-5 h-5 ${v.color}`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,z.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,z.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":s(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,z.jsx)(x,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,s(`projects.parts`)]}):e.target_count?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${c>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,s(`projects.plates`)]}):e.completed_count>0?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,s(`projects.parts`)]}):null,u&&(0,z.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:s(`projects.done`)}),d&&(0,z.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:s(`projects.statusArchived`)}),e.child_count>0&&(0,z.jsxs)(`span`,{className:`text-xs bg-bambu-dark text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap inline-flex items-center gap-1`,title:s(`projects.subProjectCount`,{count:e.child_count}),children:[(0,z.jsx)(F,{className:`w-3 h-3`}),e.child_count]})]}),t&&(0,z.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-1`,children:[(0,z.jsx)(A,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:s(`projects.partOf`,{name:t})})]}),e.description&&(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,z.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,z.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,z.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,z.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,z.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100`,onClick:()=>_(!p),children:(0,z.jsx)(f,{className:`w-4 h-4`})}),p&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>_(!1)}),(0,z.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,z.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${o(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{o(`projects:update`)&&(i(),_(!1))},disabled:!o(`projects:update`),title:o(`projects:update`)?void 0:s(`projects.noEditPermission`),children:[(0,z.jsx)(h,{className:`w-4 h-4`}),s(`common.edit`)]}),(0,z.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${o(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{o(`projects:delete`)&&(a(),_(!1))},disabled:!o(`projects:delete`),title:o(`projects:delete`)?void 0:s(`projects.noDeletePermission`),children:[(0,z.jsx)(b,{className:`w-4 h-4`}),s(`common.delete`)]})]})]})]})]}),(0,z.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,z.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,z.jsx)(`span`,{className:`text-bambu-gray`,children:s(`projects.plates`)}),(0,z.jsxs)(`span`,{className:c>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,z.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,z.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(c,100)}%`,background:c>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${c>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,z.jsx)(`span`,{className:`text-bambu-gray`,children:s(`projects.parts`)}),(0,z.jsxs)(`span`,{className:l>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,z.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,z.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(l,100)}%`,background:l>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${l>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,s(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,z.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,z.jsx)(C,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.completed_count,` `,s(`projects.completed`)]})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.failed_count,` `,s(`projects.failed`)]})]}),e.queue_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,z.jsx)(T,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.queue_count,` `,s(`projects.inQueue`)]})]})]}):(0,z.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:s(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,z.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,z.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,z.jsx)(m,{className:`w-6 h-6`})}),e.status===`failed`&&(0,z.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,z.jsx)(g,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:s(`common.more`,{count:e.archive_count-4})})]}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:s(`projects.printJobs`),children:[(0,z.jsx)(A,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,z.jsxs)(`span`,{children:[e.archive_count,` `,s(`projects.plates`)]})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:s(`projects.partsPrinted`),children:[(0,z.jsx)(m,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,z.jsxs)(`span`,{children:[e.completed_count,` `,s(`projects.parts`)]})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:s(`projects.failedParts`),children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:s(`projects.inQueue`),children:[(0,z.jsx)(I,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.queue_count})]})]}),(0,z.jsx)(w,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function W(){let{t:e}=i(),t=E(),n=o(),{showToast:a}=d(),{hasPermission:l}=P(),[f,m]=(0,L.useState)(!1),[h,g]=(0,L.useState)(),[_,b]=(0,L.useState)(`active`),[x,S]=(0,L.useState)(null),[A,ee]=(0,L.useState)(()=>localStorage.getItem(`projects-collapse-subprojects`)===`true`),[I,R]=(0,L.useState)({}),B=()=>{let e=!A;ee(e),R({}),localStorage.setItem(`projects-collapse-subprojects`,String(e))},{data:H}=s({queryKey:[`settings`],queryFn:r.getSettings}),W=k(H?.currency||`USD`),{data:G,isLoading:te}=s({queryKey:[`projects`,_===`all`?void 0:_],queryFn:()=>r.getProjects(_===`all`?void 0:_)}),{data:K}=s({queryKey:[`projects`,void 0],queryFn:()=>r.getProjects()}),q=new Map((K||[]).map(e=>[e.id,e.name])),J=G||[],Y=new Set(J.map(e=>e.id)),X=new Map;for(let e of J)if(e.parent_id!==null&&Y.has(e.parent_id)){let t=X.get(e.parent_id)||[];t.push(e),X.set(e.parent_id,t)}let Z=new Set,Q=e=>{if(!Z.has(e)){Z.add(e);for(let t of X.get(e)||[])Q(t.id)}},$=[];for(let e of J)e.parent_id!==null&&Y.has(e.parent_id)||($.push(e),Q(e.id));for(let e of J)Z.has(e.id)||($.push(e),Q(e.id));let ne=(t,n,r)=>{let i=(0,z.jsx)(U,{project:t,parentName:n===0&&t.parent_id!==null?q.get(t.parent_id):void 0,onClick:()=>pe(t),onEdit:()=>fe(t),onDelete:()=>me(t.id),hasPermission:l,t:e}),a=new Set(r).add(t.id),o=(X.get(t.id)||[]).filter(e=>!a.has(e.id));if(o.length===0)return(0,z.jsx)(`div`,{children:i},t.id);let s=I[t.id]??!A;return(0,z.jsxs)(`div`,{className:s?`col-span-full space-y-4`:`space-y-4`,children:[i,(0,z.jsxs)(`div`,{className:`ml-4 md:ml-8 pl-4 md:pl-6 border-l-2 rounded-l space-y-4`,style:{borderColor:t.color||`#6b7280`},children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>R(e=>({...e,[t.id]:!s})),"aria-expanded":s,title:e(s?`projects.collapseSubProjects`:`projects.expandSubProjects`),className:`text-xs uppercase tracking-wide text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5 max-w-full min-w-0`,children:[s?(0,z.jsx)(u,{className:`w-3.5 h-3.5 flex-shrink-0`}):(0,z.jsx)(w,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,z.jsx)(F,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e(`projects.subProjectsOf`,{name:t.name})}),(0,z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark normal-case tracking-normal flex-shrink-0`,children:o.length})]}),s&&(0,z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-8`,children:o.map(e=>ne(e,n+1,a))})]})]},t.id)},re=c({mutationFn:e=>r.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),m(!1),a(e(`projects.toast.created`),`success`)},onError:e=>{a(e.message,`error`)}}),ie=c({mutationFn:({id:e,data:t})=>r.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),m(!1),g(void 0),a(e(`projects.toast.updated`),`success`)},onError:e=>{a(e.message,`error`)}}),ae=c({mutationFn:e=>r.deleteProject(e),onSuccess:()=>{S(null),a(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{S(null),a(e.message,`error`)}}),oe=c({mutationFn:e=>r.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),a(e(`projects.toast.imported`),`success`)},onError:e=>{a(e.message,`error`)}}),se=(0,L.useRef)(null),ce=async()=>{try{let t=await r.getProjects(),n=await Promise.all(t.map(async e=>await r.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,s.click(),URL.revokeObjectURL(o),a(e(`projects.toast.exported`),`success`)}catch(e){a(e.message,`error`)}},le=()=>{se.current?.click()},ue=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await r.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),a(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),r=Array.isArray(n)?n:[n];for(let e of r)await oe.mutateAsync(e);r.length>1&&a(e(`projects.toast.multipleImported`,{count:r.length}),`success`)}}catch(t){a(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},de=e=>{h?ie.mutate({id:h.id,data:e}):re.mutate(e)},fe=e=>{g(e),m(!0)},pe=e=>{t(`/projects/${e.id}`)},me=e=>{S(e)},he=()=>{x!==null&&ae.mutate(x)},ge=K?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,z.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,z.jsx)(`input`,{ref:se,type:`file`,accept:`.json,.zip`,onChange:ue,className:`hidden`}),(0,z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(v,{variant:`secondary`,onClick:le,disabled:!l(`projects:create`),title:l(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,z.jsx)(j,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,z.jsxs)(v,{variant:`secondary`,onClick:ce,disabled:!l(`projects:read`),title:l(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,z.jsx)(M,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,z.jsxs)(v,{onClick:()=>m(!0),className:`sm:w-auto w-full`,disabled:!l(`projects:create`),title:l(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,z.jsx)(D,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,z.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:T},{key:`completed`,label:e(`projects.statusCompleted`),icon:y},{key:`archived`,label:e(`projects.statusArchived`),icon:C},{key:`all`,label:e(`common.all`),icon:N}].map(({key:e,label:t,icon:n})=>(0,z.jsxs)(`button`,{onClick:()=>b(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${_===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(n,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{children:t}),ge[e]>0&&(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${_===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:ge[e]})]},e))}),X.size>0&&(0,z.jsxs)(`button`,{type:`button`,onClick:B,"aria-pressed":A,title:e(A?`projects.expandSubProjects`:`projects.collapseSubProjects`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-lg transition-colors ${A?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,children:[(0,z.jsx)(F,{className:`w-4 h-4`}),e(`common.collapse`)]})]}),te?(0,z.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,z.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,z.jsx)(p,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):G?.length===0?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(N,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:_===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:_})}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:_===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:_})}),_===`all`&&(0,z.jsxs)(v,{onClick:()=>m(!0),disabled:!l(`projects:create`),title:l(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,z.jsx)(D,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:$.map(e=>ne(e,0,new Set))}),x!==null&&(0,z.jsx)(O,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:he,onCancel:()=>S(null)}),f&&(0,z.jsx)(V,{project:h,onClose:()=>{m(!1),g(void 0)},onSave:de,isLoading:re.isPending||ie.isPending,currencySymbol:W,t:e})]})}export{V as ProjectModal,W as ProjectsPage,F as n,I as t};
\ No newline at end of file
diff --git a/static/assets/QueuePage-DVAUmwSb.js b/static/assets/QueuePage-bp2WcaGg.js
similarity index 99%
rename from static/assets/QueuePage-DVAUmwSb.js
rename to static/assets/QueuePage-bp2WcaGg.js
index 76d69b0c6..b2cdaa848 100644
--- a/static/assets/QueuePage-DVAUmwSb.js
+++ b/static/assets/QueuePage-bp2WcaGg.js
@@ -1,4 +1,4 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-BdOyoZJz.js";import{n as o}from"./QueryClientProvider-Clbyr4Jg.js";import{t as s}from"./useQuery-CCy0EwsM.js";import{t as c}from"./useMutation-qh3Iyscy.js";import{t as l}from"./useQueries-C87lFrjE.js";import{t as u}from"./createLucideIcon-Yo2YoYjm.js";import{t as d}from"./arrow-down-C4OBNDqJ.js";import{t as f}from"./arrow-up-Dam8cLfE.js";import{a as p,c as m,d as h,f as g,h as _,i as v,l as y,m as b,o as x,p as S,s as ee,t as C,u as te}from"./sortable.esm-uF6WmP46.js";import{t as w}from"./calendar-DiVEdzUw.js";import{t as ne}from"./check-D1Pn8T1J.js";import{a as T,i as re,n as E,r as D}from"./info-DcT0QU8O.js";import{n as O,r as k}from"./ToastContext-VFOrCCoA.js";import{t as A}from"./coins-6tqy9spE.js";import{t as j}from"./funnel-BtI48m95.js";import{t as M}from"./grip-vertical-D4urhrwn.js";import{t as ie}from"./list-CBXEiN6g.js";import{t as ae}from"./loader-circle-CB4leTZa.js";import{t as N}from"./package-D9xR0eOt.js";import{t as P}from"./pause-CPKrVlsD.js";import{t as oe}from"./play-DROvjtg7.js";import{t as F}from"./skip-forward-BE5zCMec.js";import{t as I}from"./timer-BYBW_ysJ.js";import{t as L}from"./triangle-alert-gIik0G2C.js";import{t as se}from"./workflow-DxBrfirU.js";import{t as ce}from"./x-Dctff5l9.js";import{t as le}from"./Card-OUAj0Ayh.js";import{t as R}from"./Button-pwVKPiYn.js";import{c as ue,o as de,u as fe,v as z}from"./date-G9KUauqz.js";import{$t as pe,A as me,At as he,Cn as ge,En as _e,Gt as B,H as ve,Jt as ye,Kt as V,Lt as be,Mn as xe,On as H,Ot as Se,Rn as Ce,Rt as we,T as U,W,Yt as Te,_t as Ee,at as De,b as Oe,cn as ke,ct as G,jn as Ae,jt as je,mn as Me,on as Ne,w as K,wt as Pe,xn as Fe,yt as Ie}from"./index-Bw-_P2Fg.js";import{t as Le}from"./queueItemName-UFY7kpjG.js";var Re=u(`chart-no-axes-gantt`,[[`path`,{d:`M6 5h12`,key:`fvfigv`}],[`path`,{d:`M4 12h10`,key:`oujl3d`}],[`path`,{d:`M12 19h8`,key:`baeox8`}]]),ze=u(`circle-play`,[[`path`,{d:`M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z`,key:`kmsa83`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Be=u(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),Ve=u(`package-open`,[[`path`,{d:`M12 22v-9`,key:`x3hkom`}],[`path`,{d:`M15.17 2.21a1.67 1.67 0 0 1 1.63 0L21 4.57a1.93 1.93 0 0 1 0 3.36L8.82 14.79a1.655 1.655 0 0 1-1.64 0L3 12.43a1.93 1.93 0 0 1 0-3.36z`,key:`2ntwy6`}],[`path`,{d:`M20 13v3.87a2.06 2.06 0 0 1-1.11 1.83l-6 3.08a1.93 1.93 0 0 1-1.78 0l-6-3.08A2.06 2.06 0 0 1 4 16.87V13`,key:`1pmm1c`}],[`path`,{d:`M21 12.43a1.93 1.93 0 0 0 0-3.36L8.83 2.2a1.64 1.64 0 0 0-1.63 0L3 4.57a1.93 1.93 0 0 0 0 3.36l12.18 6.86a1.636 1.636 0 0 0 1.63 0z`,key:`12ttoo`}]]),He=u(`snail`,[[`path`,{d:`M2 13a6 6 0 1 0 12 0 4 4 0 1 0-8 0 2 2 0 0 0 4 0`,key:`hneq2s`}],[`circle`,{cx:`10`,cy:`13`,r:`8`,key:`194lz3`}],[`path`,{d:`M2 21h12c4.4 0 8-3.6 8-8V7a2 2 0 1 0-4 0v6`,key:`ixqyt7`}],[`path`,{d:`M18 3 19.1 5.2`,key:`9tjm43`}],[`path`,{d:`M22 3 20.9 5.2`,key:`j3odrs`}]]),Ue=u(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]),q=e(n(),1),J=t(),We=[``,`queued`,`slicing`,`dispatching`,`in_progress`,`completed`,`partial_failure`,`failed`,`cancelled`],Y=25;function Ge(){let{t:e}=a(),t=o(),{showToast:n}=O(),[i,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(0),[g,_]=(0,q.useState)(new Set),[v,y]=(0,q.useState)(!1),{data:b}=s({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:x}=s({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),S=(x??[]).reduce((e,t)=>(e[t.id]=t,e),{}),ee=f.startsWith(`p:`)?parseInt(f.slice(2),10):void 0,C=f.startsWith(`c:`)?f.slice(2):void 0,{data:te,isLoading:w}=s({queryKey:[`pipeline-runs-all`,i,u,m,f],queryFn:()=>r.listAllPipelineRuns({limit:Y,offset:m,pipelineId:u??void 0,status:i||void 0,targetPrinterId:ee,targetModelClass:C}),refetchInterval:15e3}),ne=c({mutationFn:e=>r.cancelPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.cancelled`,`Run cancelled`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.cancelFailed`,`Cancel failed`),`error`)}),T=c({mutationFn:e=>r.retryFailedPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.retryStarted`,`Retry started`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.retryFailed`,`Retry failed`),`error`)}),re=c({mutationFn:()=>r.clearTerminalPipelineRuns(),onSuccess:r=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),y(!1),h(0),n(e(`pipelineRuns.toast.cleared`,`{{n}} runs cleared`,{n:r.deleted}),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.clearFailed`,`Clear failed`),`error`)}),E=te?.runs??[],D=te?.total??0,k=(b?.pipelines??[]).reduce((e,t)=>(e[t.id]=t,e),{}),A=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!(i||u!==null||f),ie=(()=>{let e=new Set,t=new Set;for(let n of b?.pipelines??[])n.target_kind===`printer_class`&&n.target_model_class?t.add(n.target_model_class):n.target_printer_id&&e.add(n.target_printer_id);return{printers:(x??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort()}})();return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),"aria-label":e(`common.refresh`,`Refresh`),title:e(`common.refresh`,`Refresh`),className:`p-1.5 text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(qe,{icon:(0,J.jsx)(se,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.pipeline`,`Pipeline`),value:u===null?``:String(u),onChange:e=>{h(0),d(e?parseInt(e,10):null)},options:[{value:``,label:e(`pipelineRuns.filter.allPipelines`,`All pipelines`)},...(b?.pipelines??[]).map(e=>({value:String(e.id),label:e.name}))]}),(0,J.jsx)(qe,{icon:(0,J.jsx)(j,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.status`,`Status`),value:i,onChange:e=>{h(0),l(e)},options:We.map(t=>({value:t,label:t===``?e(`pipelineRuns.filter.allStatus`,`All statuses`):e(`settings.pipelines.runs.status.${t}`,t)}))}),(ie.printers.length>0||ie.classes.length>0)&&(0,J.jsx)(qe,{icon:(0,J.jsx)(ye,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.target`,`Target`),value:f,onChange:e=>{h(0),p(e)},options:[{value:``,label:e(`pipelineRuns.filter.allTargets`,`All targets`)},...ie.printers.map(t=>({value:`p:${t.id}`,label:t.name,group:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)})),...ie.classes.map(t=>({value:`c:${t}`,label:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t}),group:e(`settings.pipelines.field.targetKindClass`,`Printer class`)}))]}),M&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>{l(``),d(null),p(``),h(0)},className:`text-xs text-bambu-gray hover:text-white`,children:e(`pipelineRuns.filter.clear`,`Clear filters`)}),(0,J.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 text-xs text-bambu-gray`,children:[!w&&D>0&&(0,J.jsx)(`span`,{children:e(`pipelineRuns.totalCount`,`{{n}} run`,{n:D,count:D})}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>y(!0),disabled:D===0,className:`flex items-center gap-1 px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,J.jsx)(he,{className:`w-3 h-3`}),e(`pipelineRuns.clearLog`,`Clear log`)]})]})]}),v&&(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:()=>y(!1),role:`dialog`,"aria-modal":`true`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md p-4`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,J.jsx)(he,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),e(`pipelineRuns.clearConfirmTitle`,`Clear log?`)]}),(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`pipelineRuns.clearConfirmBody`,`Delete every completed, failed, cancelled, and partial-failure pipeline run? In-flight runs are kept. This cannot be undone.`)}),(0,J.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-4`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>y(!1),disabled:re.isPending,className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white`,children:e(`common.cancel`,`Cancel`)}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>re.mutate(),disabled:re.isPending,className:`px-3 py-1.5 text-sm bg-red-500 hover:bg-red-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[re.isPending?(0,J.jsx)(ae,{className:`w-3.5 h-3.5 animate-spin`}):(0,J.jsx)(he,{className:`w-3.5 h-3.5`}),e(`pipelineRuns.clearConfirmAction`,`Clear`)]})]})]})}),w&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,J.jsx)(ae,{className:`w-4 h-4 animate-spin`}),e(`pipelineRuns.loading`,`Loading…`)]}),!w&&E.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:M?e(`pipelineRuns.filter.noMatches`,`No runs match the current filters.`):e(`pipelineRuns.empty`,`No pipeline runs yet.`)}),!w&&E.length>0&&(0,J.jsx)(`div`,{className:`space-y-1.5`,children:E.map(e=>(0,J.jsx)(Ke,{run:e,pipeline:e.pipeline_id?k[e.pipeline_id]:void 0,printersById:S,expanded:g.has(e.id),onToggle:()=>A(e.id),onCancel:()=>ne.mutate(e.id),onRetry:()=>T.mutate(e.id),cancelling:ne.isPending,retrying:T.isPending},e.id))}),!w&&D>Y&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between mt-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(Math.max(0,m-Y)),disabled:m===0,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.previous`,`Previous`)}),(0,J.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e(`pipelineRuns.pagination`,`{{start}}–{{end}} of {{total}}`,{start:m+1,end:Math.min(m+Y,D),total:D})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(m+Y),disabled:m+Y>=D,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.next`,`Next`)})]})]})}function Ke({run:e,pipeline:t,printersById:n,expanded:r,onToggle:i,onCancel:o,onRetry:s,cancelling:c,retrying:l}){let{t:u}=a(),d=[`queued`,`slicing`,`dispatching`,`in_progress`].includes(e.status),f=e.status===`partial_failure`||e.status===`failed`,p=e.status===`cancelled`&&e.error_message===`Cancelled by user`,m=e.target_kind===`printer_class`&&e.target_model_class?u(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):e.target_printer_id&&n[e.target_printer_id]?n[e.target_printer_id].name:null;return(0,J.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:i,"aria-label":r?u(`common.collapse`,`Collapse`):u(`common.expand`,`Expand`),"aria-expanded":r,className:`text-bambu-gray hover:text-white flex-shrink-0`,children:r?(0,J.jsx)(T,{className:`w-4 h-4`}):(0,J.jsx)(xe,{className:`w-4 h-4`})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm`,children:[(0,J.jsxs)(`span`,{className:`font-medium text-white`,children:[`#`,e.id]}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:t?.name??e.pipeline_name??`—`}),(0,J.jsx)(X,{status:e.status}),m&&(0,J.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray flex items-center gap-1`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),m]}),e.parent_run_id&&(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray/70 italic`,children:u(`pipelineRuns.retryOf`,`retry of #{{n}}`,{n:e.parent_run_id})})]}),e.source_filename&&(0,J.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-xs text-bambu-gray min-w-0`,children:[(0,J.jsx)(Fe,{className:`w-3 h-3 flex-shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,title:e.source_filename,children:e.source_filename})]}),(0,J.jsxs)(`div`,{className:`mt-0.5 text-xs text-bambu-gray/70 flex flex-wrap items-center gap-x-2`,children:[(0,J.jsx)(`span`,{children:new Date(e.created_at).toLocaleString()}),e.copies>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{children:u(`pipelineRuns.copies`,`{{n}} copies`,{n:e.copies})})]}),(e.copies_completed>0||e.copies_failed>0||e.copies_cancelled>0)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`span`,{className:`text-bambu-green`,children:e.copies_completed}),`/`,e.copies]}),e.copies_failed>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:u(`pipelineRuns.failedCount`,`{{n}} failed`,{n:e.copies_failed})})]})]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[d&&(0,J.jsxs)(`button`,{type:`button`,onClick:o,disabled:c,"aria-label":u(`common.cancel`,`Cancel`),className:`text-xs px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(ce,{className:`w-3 h-3`}),u(`common.cancel`,`Cancel`)]}),f&&(0,J.jsxs)(`button`,{type:`button`,onClick:s,disabled:l,"aria-label":u(`pipelineRuns.retryFailed`,`Retry failed`),className:`text-xs px-2 py-1 text-bambu-green hover:bg-bambu-green/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(B,{className:`w-3 h-3`}),u(`pipelineRuns.retryFailed`,`Retry failed`)]})]})]}),r&&(0,J.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary px-3 py-2 bg-bambu-dark/30`,children:[(0,J.jsx)(`div`,{className:`space-y-1.5`,children:e.jobs.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/60 w-14 flex-shrink-0`,children:u(`pipelineRuns.copyN`,`Copy {{n}}`,{n:e.copy_index+1})}),(0,J.jsx)(Je,{status:e.status}),e.assigned_printer_name&&(0,J.jsxs)(`span`,{className:`text-bambu-gray flex items-center gap-1 truncate`,children:[(0,J.jsx)(ye,{className:`w-3 h-3 text-bambu-gray/60`}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:e.assigned_printer_name})]}),e.error_message&&(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400 truncate`,title:e.error_message,children:e.error_message})]},e.id))}),e.error_message&&!p&&(0,J.jsx)(`div`,{className:`text-xs text-red-700 dark:text-red-400 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:e.error_message}),p&&(0,J.jsx)(`div`,{className:`text-xs text-bambu-gray/70 mt-2 pt-2 border-t border-bambu-dark-tertiary italic`,children:u(`pipelineRuns.cancelledByUser`,`Cancelled by user`)})]})]})}function X({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide whitespace-nowrap ${{queued:`bg-slate-700 text-slate-200`,slicing:`bg-sky-700 text-sky-100`,dispatching:`bg-sky-700 text-sky-100`,in_progress:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,partial_failure:`bg-amber-700 text-amber-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`settings.pipelines.runs.status.${e}`,e)})}function qe({value:e,onChange:t,options:n,icon:r,ariaLabel:i}){let[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=n.find(t=>t.value===e),l=[];for(let e of n){let t=l[l.length-1];t&&t.group===e.group?t.options.push(e):l.push({group:e.group,options:[e]})}return(0,J.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":i,"aria-haspopup":`listbox`,"aria-expanded":a,className:`flex items-center gap-1.5 px-2 py-1 border border-bambu-dark-tertiary rounded bg-bambu-dark/40 text-xs text-white hover:border-bambu-gray/60 focus:outline-none focus:ring-1 focus:ring-bambu-green/40`,children:[r,(0,J.jsx)(`span`,{className:`truncate max-w-[14rem]`,children:c?.label??``}),(0,J.jsx)(T,{className:`w-3 h-3 text-bambu-gray transition-transform ${a?`rotate-180`:``}`})]}),a&&(0,J.jsx)(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-full max-h-72 overflow-auto rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-xl py-1`,children:l.map((n,r)=>(0,J.jsxs)(`div`,{children:[n.group&&(0,J.jsx)(`div`,{className:`px-2 pt-1.5 pb-0.5 text-[10px] uppercase tracking-wider text-bambu-gray/60`,children:n.group}),n.options.map(n=>{let r=n.value===e;return(0,J.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":r,onClick:()=>{t(n.value),o(!1)},className:`flex w-full items-center gap-1.5 text-left px-2 py-1 text-xs whitespace-nowrap ${r?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary/60 hover:text-white`}`,children:[(0,J.jsx)(ne,{className:`w-3 h-3 flex-shrink-0 ${r?`opacity-100`:`opacity-0`}`}),(0,J.jsx)(`span`,{className:`truncate`,children:n.label})]},n.value)})]},r))})]})}function Je({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide ${{pending:`bg-slate-700 text-slate-200`,awaiting_printer:`bg-sky-700 text-sky-100`,queued:`bg-sky-700 text-sky-100`,printing:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`pipelineRuns.jobStatus.${e}`,e)})}function Ye(e){return e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function Xe({activeCount:e,pendingCount:t,totalTime:n,totalWeight:r,historyCount:i,t:a}){return(0,J.jsx)(`div`,{className:`flex items-center gap-3 sm:gap-5 flex-wrap px-4 py-3 bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary mb-6`,children:[{icon:oe,value:e,label:a(`queue.summary.printing`),color:`text-blue-600 dark:text-blue-400`},{icon:H,value:t,label:a(`queue.summary.queued`),color:`text-yellow-600 dark:text-yellow-400`},{icon:I,value:de(n),label:a(`queue.summary.totalTime`),color:`text-bambu-green`},{icon:Pe,value:Ye(r),label:a(`queue.summary.totalWeight`),color:`text-purple-600 dark:text-purple-400`},{icon:k,value:i,label:a(`queue.summary.history`),color:`text-bambu-gray`}].map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t>0&&(0,J.jsx)(`span`,{className:`hidden sm:block text-bambu-dark-tertiary`,children:`|`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(e.icon,{className:`w-4 h-4 ${e.color}`}),(0,J.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:e.value}),(0,J.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e.label})]})]},t))})}var Z={completed:{icon:k,color:`text-emerald-600 dark:text-emerald-400`,border:`border-l-emerald-500`},failed:{icon:E,color:`text-red-600 dark:text-red-400`,border:`border-l-red-500`},skipped:{icon:F,color:`text-orange-600 dark:text-orange-400`,border:`border-l-gray-500`},cancelled:{icon:_,color:`text-gray-400`,border:`border-l-gray-500`}};function Ze(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;return/^0{6,8}$/.test(t)||!/^[0-9a-fA-F]{6,8}$/.test(t)?null:`#${t.slice(0,6)}`}function Qe({item:e,onRequeue:t,onRemove:n,timeFormat:i=`system`,hasPermission:a,canModify:o,t:s}){let c=Z[e.status]||Z.cancelled,l=c.icon,u=Le(e),d=e.archive_thumbnail?r.getArchiveThumbnail(e.archive_id):e.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.library_file_id):null,f=e.completed_at||e.created_at,p=Ze(e.filament_color),m=e.filament_used_grams?Math.round(e.filament_used_grams):null,h=!!e.error_message&&(e.status===`failed`||e.status===`skipped`);return(0,J.jsxs)(`div`,{className:`px-3 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] ${c.border}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,J.jsx)(l,{className:`w-4 h-4 shrink-0 ${c.color}`}),(0,J.jsxs)(`div`,{className:`relative shrink-0 history-thumb-hover`,children:[(0,J.jsx)(`div`,{className:`w-8 h-8 bg-bambu-dark rounded overflow-hidden`,children:d?(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover`}):(0,J.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,J.jsx)(ke,{className:`w-4 h-4`})})}),d&&(0,J.jsx)(`div`,{className:`history-thumb-preview absolute z-[60] left-full top-0 ml-2 w-48 h-48 pointer-events-none opacity-0 transition-opacity`,children:(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover rounded-lg shadow-2xl border-2 border-bambu-dark-tertiary bg-bambu-dark`})})]}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:u}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,title:f??void 0,children:fe(f,i,s)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:t,disabled:!a(`queue:create`),title:a(`queue:create`)?s(`queue.actions.requeue`):s(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:n,disabled:!o(`queue`,`delete`,e.created_by_id),title:o(`queue`,`delete`,e.created_by_id)?s(`common.remove`):s(`queue.permissions.noRemove`),className:`p-1.5`,children:(0,J.jsx)(he,{className:`w-3.5 h-3.5`})})]})]}),(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[e.printer_name&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[100px] sm:max-w-[140px]`,children:e.printer_name})]}),(p||m)&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[p?(0,J.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-full border border-white/15`,style:{backgroundColor:p},"aria-hidden":!0}):(0,J.jsx)(Pe,{className:`w-3 h-3`}),(0,J.jsxs)(`span`,{className:`truncate`,children:[m?`${m}g`:null,m&&e.filament_type?` ${e.filament_type}`:null,!m&&e.filament_type?e.filament_type:null]})]}),e.print_time_seconds&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(I,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.created_by_username&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,title:s(`queue.addedBy`,{name:e.created_by_username}),children:[(0,J.jsx)(Se,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.created_by_username})]})]}),h&&(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex items-start gap-1 text-xs text-red-700 dark:text-red-400`,children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,J.jsx)(`span`,{className:`break-words`,children:e.error_message})]})]})}function $e(e){return e.printer_id==null?e.target_model?`model:${e.target_model}`:`unassigned`:`printer:${e.printer_id}`}function et(e,t,n){if(n){let n=+!!e.been_jumped,r=+!!t.been_jumped;if(n!==r)return r-n;let i=e.print_time_seconds??1/0,a=t.print_time_seconds??1/0;if(i!==a)return i-a}return e.position===t.position?(e.id??0)-(t.id??0):e.position-t.position}function tt(e){return e?e.split(` | `).map(e=>e.trim()).every(e=>e.startsWith(`Busy:`)):!1}var nt=3600*1e3,rt=24,it=rt*nt,at=32,ot=40;function st(e){return e.toLocaleTimeString(void 0,{hour:`numeric`})}function ct(e){return e.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function lt({queueItems:e,printers:t,printerStatuses:n,sjfEnabled:i,onItemClick:a,t:o}){let[s,c]=(0,q.useState)(()=>new Date);(0,q.useEffect)(()=>{let e=setInterval(()=>c(new Date),6e4);return()=>clearInterval(e)},[]);let[l,u]=(0,q.useState)(0),d=(0,q.useMemo)(()=>{let e=s.getTime()+l;return Math.floor(e/nt)*nt},[s,l]),f=d+it,p=s.getTime(),m=(0,q.useMemo)(()=>{let t=[],r=new Map,a=new Set,o=new Map;for(let i of e)if(i.status===`printing`){let e=i.printer_id==null?void 0:n[i.printer_id],r=z(i.started_at)||new Date,s;if(e?.remaining_time!=null&&e.remaining_time>0)s=new Date(p+e.remaining_time*60*1e3);else if(i.print_time_seconds){let t=e?.progress||0,n=Math.max(0,1-t/100);s=new Date(p+i.print_time_seconds*n*1e3)}else s=new Date(p+nt);t.push({item:i,estimatedStart:r,estimatedEnd:s,progress:e?.progress??void 0,type:`printing`});let c=$e(i);a.add(c),o.set(c,Math.max(o.get(c)??p,s.getTime()))}else if(i.status===`pending`){if(i.manual_start||i.waiting_reason&&!tt(i.waiting_reason))continue;let e=$e(i);r.has(e)||r.set(e,[]),r.get(e).push(i)}let s=Date.now()+4320*nt;for(let[e,n]of r){n.sort((e,t)=>et(e,t,i));let r=a.has(e),c=n[0]?z(n[0].scheduled_time):null,l=c&&c.getTime()<=s;if(!r&&!l)continue;let u=o.get(e)??p;for(let e of n){let n=z(e.scheduled_time);n&&n.getTime()<=s&&(u=Math.max(u,n.getTime()));let r=(e.print_time_seconds||3600)*1e3;t.push({item:e,estimatedStart:new Date(u),estimatedEnd:new Date(u+r),type:`queued`}),u+=r}}return t},[e,n,p,i]),h=(0,q.useMemo)(()=>{let e=[];for(let n of t)e.push({key:`printer:${n.id}`,label:n.name,printerId:n.id,targetModel:null});let n=new Set,r=!1;for(let t of m)if(t.item.printer_id==null)if(t.item.target_model){let r=`model:${t.item.target_model}`;n.has(r)||(n.add(r),e.push({key:r,label:`${o(`queue.filter.any`)} ${t.item.target_model}`,printerId:null,targetModel:t.item.target_model}))}else r=!0;return r&&e.push({key:`unassigned`,label:o(`queue.filter.unassigned`),printerId:null,targetModel:null}),e},[t,m,o]),g=(0,q.useMemo)(()=>{let e=new Map;for(let t of m){let n;n=t.item.printer_id==null?t.item.target_model?`model:${t.item.target_model}`:`unassigned`:`printer:${t.item.printer_id}`,e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[m]),_=(0,q.useMemo)(()=>{let e=[];for(let t=0;t<=rt;t+=2){let n=d+t*nt;e.push({ms:n,pct:t/rt*100,label:st(new Date(n))})}return e},[d]),v=(p-d)/it*100,y=v>=0&&v<=100,b=(0,q.useMemo)(()=>{let e=0;for(let t of m)e=Math.max(e,t.estimatedEnd.getTime());return e>0?new Date(e):null},[m]),x=(0,q.useRef)(null);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e-12*nt),className:`p-1.5`,title:o(`queue.timeline.window.back12h`),children:(0,J.jsx)(Ae,{className:`w-4 h-4`})}),(0,J.jsxs)(`span`,{className:`text-sm font-medium text-white min-w-[180px] text-center`,children:[new Date(d).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),` → `,new Date(f).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e+12*nt),className:`p-1.5`,title:o(`queue.timeline.window.forward12h`),children:(0,J.jsx)(xe,{className:`w-4 h-4`})}),l!==0&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(0),className:`text-xs text-bambu-green`,children:o(`queue.timeline.window.now`)})]}),b&&(0,J.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1.5`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),o(`queue.timeline.allDoneBy`,{time:b.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})})]})]}),h.length>0&&m.length===0&&(0,J.jsx)(`div`,{className:`mb-4 p-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 text-xs text-bambu-gray`,children:o(`queue.timeline.nothingCommitted`)}),h.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,J.jsx)(ke,{className:`w-12 h-12 mb-3 opacity-30`}),(0,J.jsx)(`p`,{className:`text-sm`,children:o(`queue.timeline.noData`)})]}):(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-2 text-xs font-medium text-bambu-gray border-r border-bambu-dark-tertiary`,children:o(`queue.timeline.printerColumnHeader`)}),(0,J.jsx)(`div`,{className:`relative flex-1 h-9`,children:_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/40 text-[10px] sm:text-xs text-bambu-gray pl-1 flex items-center`,style:{left:`${e.pct}%`},children:e.label},e.ms))})]}),(0,J.jsxs)(`div`,{ref:x,className:`relative`,children:[h.map(e=>{let t=g.get(e.key)??[];return(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary/40 last:border-b-0`,children:[(0,J.jsxs)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-3 border-r border-bambu-dark-tertiary flex items-center gap-2`,children:[(0,J.jsx)(ye,{className:`w-3.5 h-3.5 shrink-0 ${e.printerId==null&&e.targetModel==null?`text-orange-600 dark:text-orange-400`:e.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,J.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.label})]}),(0,J.jsxs)(`div`,{className:`relative flex-1`,style:{height:56},children:[_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/30`,style:{left:`${e.pct}%`}},e.ms)),(0,J.jsx)(`div`,{className:`absolute inset-0 opacity-30`,style:{backgroundImage:`repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,0.04) 6px, rgba(255,255,255,0.04) 12px)`},"aria-hidden":!0}),t.map(e=>{let t=Math.max(d,e.estimatedStart.getTime()),n=Math.min(f,e.estimatedEnd.getTime());if(n<=d||t>=f)return null;let i=(t-d)/it*100,o=(n-t)/it*100,s=e.item.archive_name||e.item.library_file_name||`#${e.item.id}`,c=e.item.archive_thumbnail?r.getArchiveThumbnail(e.item.archive_id):e.item.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.item.library_file_id):null,l=e.type===`printing`,u=e.item.batch_id!=null;return(0,J.jsxs)(`button`,{onClick:()=>a(e.item),title:[s,`${ct(e.estimatedStart)} → ${ct(e.estimatedEnd)}`,e.item.print_time_seconds?de(e.item.print_time_seconds):null,l&&e.progress!=null?`${Math.round(e.progress)}%`:null,e.item.batch_name?`batch: ${e.item.batch_name}`:null].filter(Boolean).join(` · `),className:`absolute rounded-md transition-all hover:brightness-110 hover:z-10 overflow-hidden flex items-center gap-1.5 px-1.5 text-left ${l?`bg-blue-500/30 border border-blue-400/60`:u?`bg-cyan-500/20 border border-cyan-400/50`:`bg-bambu-green/20 border border-bambu-green/40`}`,style:{left:`${i}%`,width:`max(${at}px, ${o}%)`,top:8,height:ot},children:[c&&(0,J.jsx)(`img`,{src:c,alt:``,className:`w-7 h-7 rounded object-cover shrink-0 bg-bambu-dark`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-xs text-white font-medium truncate leading-tight`,children:s}),(0,J.jsxs)(`div`,{className:`text-[10px] text-bambu-gray truncate leading-tight`,children:[e.item.print_time_seconds?de(e.item.print_time_seconds):``,l&&e.progress!=null?` · ${Math.round(e.progress)}%`:``]})]}),l&&e.progress!=null&&(0,J.jsx)(`div`,{className:`absolute bottom-0 left-0 h-0.5 bg-blue-300`,style:{width:`${e.progress}%`},"aria-hidden":!0})]},e.item.id)})]})]},e.key)}),y&&(0,J.jsxs)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none z-20 flex inset-x-0`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0`}),(0,J.jsx)(`div`,{className:`relative flex-1`,children:(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.6)]`,style:{left:`${v}%`},children:(0,J.jsx)(`div`,{className:`absolute -top-1 -left-1 w-2.5 h-2.5 bg-red-400 rounded-full`})})})]})]})]})]})}function ut({hasPermission:e,t,focusBatchId:n=null}){let i=o(),{showToast:a}=O(),[l,u]=(0,q.useState)(n?`all`:`active`),[d,f]=(0,q.useState)(null),{data:p}=s({queryKey:[`settings`],queryFn:r.getSettings}),m=De(p?.currency||`USD`),{data:h,isLoading:g}=s({queryKey:[`batches`,l],queryFn:()=>r.getBatches(l===`all`?void 0:l)}),_=n!=null&&!!h?.some(e=>e.id===n);(0,q.useEffect)(()=>{_&&document.getElementById(`batch-${n}`)?.scrollIntoView({block:`center`})},[_,n]);let v=()=>{i.invalidateQueries({queryKey:[`batches`]}),i.invalidateQueries({queryKey:[`queue`]})},y=c({mutationFn:({id:e,plateId:t})=>r.dispatchBatch(e,t===void 0?{}:{plate_id:t,only_plate:!0}),onSuccess:e=>{v(),a(t(`queue.batchOrders.dispatched`,{name:e.name}),`success`)},onError:e=>a(e.message,`error`)}),b=c({mutationFn:e=>r.cancelBatch(e),onSuccess:()=>{v(),f(null),a(t(`queue.batchCancelled`),`success`)},onError:e=>a(e.message,`error`)}),x=e(`queue:create`),S=e(`queue:delete_all`);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4`,children:[(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`h2`,{className:`text-base sm:text-lg font-semibold text-white`,children:t(`queue.batchOrders.title`)}),(0,J.jsx)(`div`,{className:`flex gap-1 ml-auto`,children:[`active`,`completed`,`cancelled`,`all`].map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-xs px-2.5 py-1 rounded-full border transition-colors ${l===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:t(`queue.batchOrders.filter.${e}`)},e))})]}),g?(0,J.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:t(`common.loading`)}):h?.length?(0,J.jsx)(`div`,{className:`space-y-4`,children:h.map(e=>(0,J.jsx)(ft,{batch:e,currency:m,canDispatch:x,canCancel:S,isDispatching:y.isPending&&y.variables?.id===e.id,highlighted:e.id===n,onDispatch:t=>y.mutate({id:e.id,plateId:t}),onCancel:()=>f(e),t},e.id))}):(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(N,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:t(`queue.batchOrders.emptyTitle`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:t(`queue.batchOrders.emptyDescription`)})]}),d&&(0,J.jsx)(Ee,{title:t(`queue.cancelBatchConfirmTitle`),message:t(`queue.cancelBatchConfirmMessage`),confirmText:t(`queue.cancelBatch`),variant:`warning`,onConfirm:()=>b.mutate(d.id),onCancel:()=>f(null)})]})}var dt={active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`,completed:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`,cancelled:`bg-bambu-dark-tertiary text-bambu-gray`};function ft({batch:e,currency:t,canDispatch:n,canCancel:r,isDispatching:i,onDispatch:a,onCancel:o,t:s,highlighted:c=!1}){let l=e.has_targets?e.target_count:e.completed_count+e.pending_count+e.printing_count+e.failed_count,u=l>0?Math.round(e.completed_count/l*100):0,d=e.has_targets?e.remaining_count-e.dispatchable_count:0,f=e.due_date?z(e.due_date):null,p=f!=null&&e.status===`active`&&f.getTime()0&&e.status!==`cancelled`&&n&&(0,J.jsxs)(R,{variant:`primary`,size:`sm`,onClick:()=>a(),disabled:i,children:[(0,J.jsx)(ze,{className:`w-4 h-4 mr-1`}),s(`queue.batchOrders.dispatchRemaining`,{count:e.dispatchable_count})]}),e.status===`active`&&r&&(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:o,children:[(0,J.jsx)(E,{className:`w-4 h-4 mr-1`}),s(`queue.cancelBatch`)]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,J.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,J.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.status===`completed`?`bg-bambu-green`:`bg-blue-500`}`,style:{width:`${Math.min(100,u)}%`}})}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap tabular-nums`,children:s(`queue.batchProgress`,{completed:e.completed_count,total:l})})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-bambu-gray mb-1`,children:[e.printing_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.printing`,{count:e.printing_count})}),e.pending_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batch.pendingCount`,{count:e.pending_count})}),e.failed_count>0&&(0,J.jsxs)(`span`,{className:`text-orange-600 dark:text-orange-400 flex items-center gap-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3`}),s(`queue.batchOrders.failed`,{count:e.failed_count})]}),e.has_targets&&e.remaining_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.remaining`,{count:e.remaining_count})}),e.print_time_seconds>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(H,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.actual_cost!=null&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(A,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costSoFar`,{amount:`${t} ${e.actual_cost.toFixed(2)}`})}),e.estimated_remaining_cost!=null&&e.estimated_remaining_cost>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costRemaining`,{amount:`${t} ${e.estimated_remaining_cost.toFixed(2)}`})})]})]}),d>0&&e.status!==`cancelled`&&(0,J.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-orange-600 dark:text-orange-400 mb-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.strandedNotice`,{runs:d,owed:e.remaining_count})})]}),e.has_targets&&e.plates.length>0&&(0,J.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3 space-y-1.5`,children:e.plates.map(r=>(0,J.jsx)(pt,{plate:r,batchStatus:e.status,currency:t,canDispatch:n,isDispatching:i,onDispatch:()=>a(r.plate_id),t:s},`${r.plate_id??`file`}`))})]})}function pt({plate:e,batchStatus:t,currency:n,canDispatch:r,isDispatching:i,onDispatch:a,t:o}){let s=e.plate_name||(e.plate_id==null?o(`queue.batchOrders.wholeFile`):o(`queue.plateNumber`,{index:e.plate_id}));return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs`,children:[(0,J.jsx)(ke,{className:`w-3.5 h-3.5 text-bambu-gray flex-shrink-0`}),(0,J.jsx)(`span`,{className:`text-white min-w-0 truncate`,children:s}),(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:o(`queue.batchOrders.plateProgress`,{completed:e.completed_count,target:e.quantity_target})}),e.failed_count>0&&(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.failed`,{count:e.failed_count})}),e.actual_cost!=null&&(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:`${n} ${e.actual_cost.toFixed(2)}`}),e.remaining>0&&t!==`cancelled`&&(0,J.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray`,children:o(`queue.batchOrders.remaining`,{count:e.remaining})}),e.can_dispatch?r&&(0,J.jsx)(`button`,{type:`button`,onClick:a,disabled:i,className:`text-bambu-green hover:underline disabled:opacity-50`,children:o(`queue.batchOrders.dispatchPlate`)}):(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.strandedPlate`)})]})]})}function mt(e,t){if(!e?.connected||t>=254)return;let n=t>=128,r=n?t:Math.floor(t/4),i=n?0:t%4,a=e.ams?.find(e=>e.id===r);if(W(n?a?.tray[0]:a?.tray.find(e=>e.id===i))===`physical`)return ve(r,i,n,!1)}function ht(e){return e.slotLabel?[e.slotLabel,e.spoolName||e.type,e.colorName].filter(Boolean).join(` · `):e.colorName}function gt(e,t,n=[],r,i=`Empty`){let a=t=>{let a=t.slotId,o=a>0?e.ams_mapping?.[a-1]:void 0;if(o==null||o<0)return t;let s=n.find(e=>e.globalTrayId===o);if(s)return{slotId:a,type:s.type,color:s.color,colorName:s.colorName,slotLabel:s.label,spoolName:s.spoolName,extraColors:s.extraColors,effectType:s.effectType,subtype:s.spoolSubtype};let c=mt(r,o);return c?{...t,slotLabel:c,spoolName:i,emptySlot:!0}:t},o=e.plate_id==null?t[0]:t.find(t=>t.index===e.plate_id);if(o){let t=new Map((e.filament_overrides??[]).map(e=>[e.slot_id,e]));return o.filaments.filter(e=>e.used_in_plate!==!1&&e.used_grams>0).map(e=>{let n=t.get(e.slot_id),r=n?.color??e.color,i=n?.type??e.type;return a({slotId:e.slot_id,type:i,color:r,colorName:n?.color_name?.trim()||G(r,i)})})}return e.filament_overrides?.length?e.filament_overrides.map(e=>a({slotId:e.slot_id,type:e.type,color:e.color,colorName:e.color_name?.trim()||G(e.color,e.type)})):e.filament_color?[a({slotId:1,type:e.filament_type??``,color:e.filament_color,colorName:G(e.filament_color,e.filament_type)})]:[]}function _t(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function vt({status:e,waitingReason:t,printerState:n,t:r}){if(e===`pending`&&t)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-purple-700 dark:text-purple-400 bg-purple-50 dark:bg-purple-400/10 border-purple-200 dark:border-purple-400/20`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),r(`queue.status.waiting`)]});if(e===`printing`&&n===`PAUSE`)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-400/10 border-yellow-200 dark:border-yellow-400/20`,children:[(0,J.jsx)(P,{className:`w-3.5 h-3.5`}),r(`queue.status.paused`)]});let{icon:i,color:a,label:o}={pending:{icon:H,color:`text-status-warning bg-status-warning/10 border-status-warning/20`,label:r(`queue.status.pending`)},printing:{icon:oe,color:`text-blue-700 dark:text-blue-400 bg-blue-50 dark:bg-blue-400/10 border-blue-200 dark:border-blue-400/20`,label:r(`queue.status.printing`)},completed:{icon:k,color:`text-status-ok bg-status-ok/10 border-status-ok/20`,label:r(`queue.status.completed`)},failed:{icon:E,color:`text-status-error bg-status-error/10 border-status-error/20`,label:r(`queue.status.failed`)},skipped:{icon:F,color:`text-orange-700 dark:text-orange-400 bg-orange-50 dark:bg-orange-400/10 border-orange-200 dark:border-orange-400/20`,label:r(`queue.status.skipped`)},cancelled:{icon:ce,color:`text-gray-400 bg-gray-400/10 border-gray-400/20`,label:r(`queue.status.cancelled`)}}[e];return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a}`,children:[(0,J.jsx)(i,{className:`w-3.5 h-3.5`}),o]})}function yt({selectedCount:e,printers:t,onSave:n,onClose:r,isSaving:i,canControlPrinter:a,hasGcodeSnippets:o,t:s}){let[c,l]=(0,q.useState)(`unchanged`),[u,d]=(0,q.useState)(`unchanged`),[f,p]=(0,q.useState)(`unchanged`),[m,h]=(0,q.useState)(`unchanged`),[g,_]=(0,q.useState)(`unchanged`),[v,y]=(0,q.useState)(`unchanged`),[b,x]=(0,q.useState)(`unchanged`),[S,ee]=(0,q.useState)(`unchanged`),[C,te]=(0,q.useState)(`unchanged`),[w,ne]=(0,q.useState)(`unchanged`),[T,re]=(0,q.useState)(`unchanged`),[E,D]=(0,q.useState)(`unchanged`),[O,k]=(0,q.useState)(`unchanged`),A=t.some(e=>e.nozzle_count===2),j=()=>{let e={};c!==`unchanged`&&(e.printer_id=c),u!==`unchanged`&&(e.manual_start=u),f!==`unchanged`&&(e.auto_off_after=f),m!==`unchanged`&&(e.require_previous_success=m),g!==`unchanged`&&(e.gcode_injection=g),v!==`unchanged`&&(e.bed_levelling=v),b!==`unchanged`&&(e.flow_cali=b),S!==`unchanged`&&(e.vibration_cali=S),C!==`unchanged`&&(e.layer_inspect=C),w!==`unchanged`&&(e.timelapse=w),T!==`unchanged`&&(e.use_ams=T),E!==`unchanged`&&(e.confirm_outcome=E),O!==`unchanged`&&(e.nozzle_offset_cali=O),n(e)},M=c!==`unchanged`||u!==`unchanged`||f!==`unchanged`||m!==`unchanged`||v!==`unchanged`||b!==`unchanged`||S!==`unchanged`||C!==`unchanged`||w!==`unchanged`||T!==`unchanged`||E!==`unchanged`||O!==`unchanged`||g!==`unchanged`;return(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm`,children:(0,J.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`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:s(`queue.bulkEdit.title`,{count:e})}),(0,J.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,J.jsx)(ce,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,J.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:s(`queue.bulkEdit.description`)}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printer`)}),(0,J.jsxs)(`select`,{value:c===null?`null`:c===`unchanged`?`unchanged`:String(c),onChange:e=>{let t=e.target.value;l(t===`unchanged`?`unchanged`:t===`null`?null:Number(t))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,J.jsx)(`option`,{value:`unchanged`,children:s(`queue.bulkEdit.noChange`)}),(0,J.jsx)(`option`,{value:`null`,children:s(`queue.filter.unassigned`)}),t.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.queueOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(Q,{label:s(`queue.bulkEdit.staged`),value:u,onChange:d,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.autoPowerOff`),value:f,onChange:p,disabled:!a,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.requirePrevious`),value:m,onChange:h,t:s}),o&&(0,J.jsx)(Q,{label:s(`queue.bulkEdit.gcodeInjection`),value:g,onChange:_,t:s})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(bt,{label:s(`queue.bulkEdit.bedLevelling`),value:v,onChange:y,t:s}),(0,J.jsx)(bt,{label:s(`queue.bulkEdit.flowCalibration`),value:b,onChange:x,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.vibrationCalibration`),value:S,onChange:ee,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.layerInspection`),value:C,onChange:te,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.timelapse`),value:w,onChange:ne,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.useAms`),value:T,onChange:re,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.confirmOutcome`),value:E,onChange:D,t:s}),A&&(0,J.jsx)(bt,{label:s(`queue.bulkEdit.nozzleOffsetCali`),value:O,onChange:k,t:s})]})]})]}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,J.jsx)(R,{variant:`secondary`,onClick:r,children:s(`common.cancel`)}),(0,J.jsx)(R,{onClick:j,disabled:!M||i,children:s(i?`common.saving`:`queue.bulkEdit.applyChanges`)})]})]})})}function Q({label:e,value:t,onChange:n,disabled:r,t:i}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1 ${r?`opacity-50`:``}`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:[(0,J.jsx)(`button`,{onClick:()=>n(`unchanged`),disabled:r,className:`px-2 py-1 text-xs rounded ${t===`unchanged`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:`—`}),(0,J.jsx)(`button`,{onClick:()=>n(!1),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!1?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.off`)}),(0,J.jsx)(`button`,{onClick:()=>n(!0),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!0?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.on`)})]})]})}function bt({label:e,value:t,onChange:n,t:r}){let i=[{key:`unchanged`,label:`—`,active:`bg-bambu-dark-tertiary text-white`},{key:`off`,label:r(`settings.calibrationMode_off`),active:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`},{key:`auto`,label:r(`settings.calibrationMode_auto`),active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},{key:`on`,label:r(`settings.calibrationMode_on`),active:`bg-bambu-green/20 text-bambu-green`}];return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:i.map(({key:e,label:r,active:i})=>(0,J.jsx)(`button`,{onClick:()=>n(e),className:`px-2 py-1 text-xs rounded ${t===e?i:`text-bambu-gray hover:text-white`}`,children:r},e))})]})}function xt({item:e,position:t,onEdit:n,onCancel:i,onRemove:a,onStop:o,onRequeue:c,onStart:l,onMoveUp:u,onMoveDown:d,timeFormat:f=`system`,isSelected:m=!1,onToggleSelect:h,hasPermission:g,canModify:_,printerState:v,showEta:y=!1,etaNow:x,t:S}){let{hasAnyPermission:ee}=Ie(),C=!ee(`queue:update_all`,`queue:start_unreviewed`),te=e.printer_id!=null&&(e.ams_mapping?.some(e=>e>=0)??!1),{data:w}=s({queryKey:[`printerStatus`,e.printer_id],queryFn:()=>r.getPrinterStatus(e.printer_id),refetchInterval:v===`printing`?3e4:!1,enabled:e.printer_id!=null&&(v===`printing`||te)}),{data:E}=s({queryKey:[`printer-inventory-remain`,e.printer_id],queryFn:()=>r.getInventoryRemain(e.printer_id),enabled:te,staleTime:30*1e3}),O=(0,q.useMemo)(()=>{let e=E?.slot_materials;if(!e?.length)return;let t=new Map;return e.forEach(e=>{e.spool&&t.set(e.global_tray_id,e.spool)}),t.size>0?t:void 0},[E]),k=(0,q.useMemo)(()=>me(w,O),[w,O]),A=!!e.library_file_id&&!e.archive_id,{data:j}=s({queryKey:[`archive-plates`,e.archive_id],queryFn:()=>r.getArchivePlates(e.archive_id),enabled:!!e.archive_id&&!A&&!e.archive_deleted}),{data:ie}=s({queryKey:[`library-file-plates`,e.library_file_id],queryFn:()=>r.getLibraryFilePlates(e.library_file_id),enabled:A&&!!e.library_file_id}),ae=A?ie:j,N=ae?.plates??[],P=gt(e,N,k,w,S(`ams.empty`)),F=g(`queue:reorder`),{attributes:L,listeners:se,setNodeRef:le,transform:B,transition:ve,isDragging:be}=p({id:e.id,disabled:e.status!==`pending`||!F}),xe={transform:b.Transform.toString(B),transition:ve},we=e.status===`printing`,W=e.status===`pending`,Ee=[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status),De=W&&y&&e.print_time_seconds!=null&&e.print_time_seconds>0?ue(e.print_time_seconds/60,f,S,x):null,Oe=W&&h;return(0,J.jsxs)(`div`,{ref:le,style:xe,className:`
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-BdOyoZJz.js";import{n as o}from"./QueryClientProvider-Clbyr4Jg.js";import{t as s}from"./useQuery-CCy0EwsM.js";import{t as c}from"./useMutation-qh3Iyscy.js";import{t as l}from"./useQueries-C87lFrjE.js";import{t as u}from"./createLucideIcon-Yo2YoYjm.js";import{t as d}from"./arrow-down-C4OBNDqJ.js";import{t as f}from"./arrow-up-Dam8cLfE.js";import{a as p,c as m,d as h,f as g,h as _,i as v,l as y,m as b,o as x,p as S,s as ee,t as C,u as te}from"./sortable.esm-uF6WmP46.js";import{t as w}from"./calendar-DiVEdzUw.js";import{t as ne}from"./check-D1Pn8T1J.js";import{a as T,i as re,n as E,r as D}from"./info-DcT0QU8O.js";import{n as O,r as k}from"./ToastContext-VFOrCCoA.js";import{t as A}from"./coins-6tqy9spE.js";import{t as j}from"./funnel-BtI48m95.js";import{t as M}from"./grip-vertical-D4urhrwn.js";import{t as ie}from"./list-CBXEiN6g.js";import{t as ae}from"./loader-circle-CB4leTZa.js";import{t as N}from"./package-D9xR0eOt.js";import{t as P}from"./pause-CPKrVlsD.js";import{t as oe}from"./play-DROvjtg7.js";import{t as F}from"./skip-forward-BE5zCMec.js";import{t as I}from"./timer-BYBW_ysJ.js";import{t as L}from"./triangle-alert-gIik0G2C.js";import{t as se}from"./workflow-DxBrfirU.js";import{t as ce}from"./x-Dctff5l9.js";import{t as le}from"./Card-OUAj0Ayh.js";import{t as R}from"./Button-pwVKPiYn.js";import{c as ue,o as de,u as fe,v as z}from"./date-G9KUauqz.js";import{$t as pe,A as me,At as he,Cn as ge,En as _e,Gt as B,H as ve,Jt as ye,Kt as V,Lt as be,Mn as xe,On as H,Ot as Se,Rn as Ce,Rt as we,T as U,W,Yt as Te,_t as Ee,at as De,b as Oe,cn as ke,ct as G,jn as Ae,jt as je,mn as Me,on as Ne,w as K,wt as Pe,xn as Fe,yt as Ie}from"./index-ggB_TpPo.js";import{t as Le}from"./queueItemName-UFY7kpjG.js";var Re=u(`chart-no-axes-gantt`,[[`path`,{d:`M6 5h12`,key:`fvfigv`}],[`path`,{d:`M4 12h10`,key:`oujl3d`}],[`path`,{d:`M12 19h8`,key:`baeox8`}]]),ze=u(`circle-play`,[[`path`,{d:`M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z`,key:`kmsa83`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Be=u(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),Ve=u(`package-open`,[[`path`,{d:`M12 22v-9`,key:`x3hkom`}],[`path`,{d:`M15.17 2.21a1.67 1.67 0 0 1 1.63 0L21 4.57a1.93 1.93 0 0 1 0 3.36L8.82 14.79a1.655 1.655 0 0 1-1.64 0L3 12.43a1.93 1.93 0 0 1 0-3.36z`,key:`2ntwy6`}],[`path`,{d:`M20 13v3.87a2.06 2.06 0 0 1-1.11 1.83l-6 3.08a1.93 1.93 0 0 1-1.78 0l-6-3.08A2.06 2.06 0 0 1 4 16.87V13`,key:`1pmm1c`}],[`path`,{d:`M21 12.43a1.93 1.93 0 0 0 0-3.36L8.83 2.2a1.64 1.64 0 0 0-1.63 0L3 4.57a1.93 1.93 0 0 0 0 3.36l12.18 6.86a1.636 1.636 0 0 0 1.63 0z`,key:`12ttoo`}]]),He=u(`snail`,[[`path`,{d:`M2 13a6 6 0 1 0 12 0 4 4 0 1 0-8 0 2 2 0 0 0 4 0`,key:`hneq2s`}],[`circle`,{cx:`10`,cy:`13`,r:`8`,key:`194lz3`}],[`path`,{d:`M2 21h12c4.4 0 8-3.6 8-8V7a2 2 0 1 0-4 0v6`,key:`ixqyt7`}],[`path`,{d:`M18 3 19.1 5.2`,key:`9tjm43`}],[`path`,{d:`M22 3 20.9 5.2`,key:`j3odrs`}]]),Ue=u(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]),q=e(n(),1),J=t(),We=[``,`queued`,`slicing`,`dispatching`,`in_progress`,`completed`,`partial_failure`,`failed`,`cancelled`],Y=25;function Ge(){let{t:e}=a(),t=o(),{showToast:n}=O(),[i,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(0),[g,_]=(0,q.useState)(new Set),[v,y]=(0,q.useState)(!1),{data:b}=s({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:x}=s({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),S=(x??[]).reduce((e,t)=>(e[t.id]=t,e),{}),ee=f.startsWith(`p:`)?parseInt(f.slice(2),10):void 0,C=f.startsWith(`c:`)?f.slice(2):void 0,{data:te,isLoading:w}=s({queryKey:[`pipeline-runs-all`,i,u,m,f],queryFn:()=>r.listAllPipelineRuns({limit:Y,offset:m,pipelineId:u??void 0,status:i||void 0,targetPrinterId:ee,targetModelClass:C}),refetchInterval:15e3}),ne=c({mutationFn:e=>r.cancelPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.cancelled`,`Run cancelled`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.cancelFailed`,`Cancel failed`),`error`)}),T=c({mutationFn:e=>r.retryFailedPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.retryStarted`,`Retry started`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.retryFailed`,`Retry failed`),`error`)}),re=c({mutationFn:()=>r.clearTerminalPipelineRuns(),onSuccess:r=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),y(!1),h(0),n(e(`pipelineRuns.toast.cleared`,`{{n}} runs cleared`,{n:r.deleted}),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.clearFailed`,`Clear failed`),`error`)}),E=te?.runs??[],D=te?.total??0,k=(b?.pipelines??[]).reduce((e,t)=>(e[t.id]=t,e),{}),A=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!(i||u!==null||f),ie=(()=>{let e=new Set,t=new Set;for(let n of b?.pipelines??[])n.target_kind===`printer_class`&&n.target_model_class?t.add(n.target_model_class):n.target_printer_id&&e.add(n.target_printer_id);return{printers:(x??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort()}})();return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),"aria-label":e(`common.refresh`,`Refresh`),title:e(`common.refresh`,`Refresh`),className:`p-1.5 text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(qe,{icon:(0,J.jsx)(se,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.pipeline`,`Pipeline`),value:u===null?``:String(u),onChange:e=>{h(0),d(e?parseInt(e,10):null)},options:[{value:``,label:e(`pipelineRuns.filter.allPipelines`,`All pipelines`)},...(b?.pipelines??[]).map(e=>({value:String(e.id),label:e.name}))]}),(0,J.jsx)(qe,{icon:(0,J.jsx)(j,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.status`,`Status`),value:i,onChange:e=>{h(0),l(e)},options:We.map(t=>({value:t,label:t===``?e(`pipelineRuns.filter.allStatus`,`All statuses`):e(`settings.pipelines.runs.status.${t}`,t)}))}),(ie.printers.length>0||ie.classes.length>0)&&(0,J.jsx)(qe,{icon:(0,J.jsx)(ye,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.target`,`Target`),value:f,onChange:e=>{h(0),p(e)},options:[{value:``,label:e(`pipelineRuns.filter.allTargets`,`All targets`)},...ie.printers.map(t=>({value:`p:${t.id}`,label:t.name,group:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)})),...ie.classes.map(t=>({value:`c:${t}`,label:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t}),group:e(`settings.pipelines.field.targetKindClass`,`Printer class`)}))]}),M&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>{l(``),d(null),p(``),h(0)},className:`text-xs text-bambu-gray hover:text-white`,children:e(`pipelineRuns.filter.clear`,`Clear filters`)}),(0,J.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 text-xs text-bambu-gray`,children:[!w&&D>0&&(0,J.jsx)(`span`,{children:e(`pipelineRuns.totalCount`,`{{n}} run`,{n:D,count:D})}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>y(!0),disabled:D===0,className:`flex items-center gap-1 px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,J.jsx)(he,{className:`w-3 h-3`}),e(`pipelineRuns.clearLog`,`Clear log`)]})]})]}),v&&(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:()=>y(!1),role:`dialog`,"aria-modal":`true`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md p-4`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,J.jsx)(he,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),e(`pipelineRuns.clearConfirmTitle`,`Clear log?`)]}),(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`pipelineRuns.clearConfirmBody`,`Delete every completed, failed, cancelled, and partial-failure pipeline run? In-flight runs are kept. This cannot be undone.`)}),(0,J.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-4`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>y(!1),disabled:re.isPending,className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white`,children:e(`common.cancel`,`Cancel`)}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>re.mutate(),disabled:re.isPending,className:`px-3 py-1.5 text-sm bg-red-500 hover:bg-red-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[re.isPending?(0,J.jsx)(ae,{className:`w-3.5 h-3.5 animate-spin`}):(0,J.jsx)(he,{className:`w-3.5 h-3.5`}),e(`pipelineRuns.clearConfirmAction`,`Clear`)]})]})]})}),w&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,J.jsx)(ae,{className:`w-4 h-4 animate-spin`}),e(`pipelineRuns.loading`,`Loading…`)]}),!w&&E.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:M?e(`pipelineRuns.filter.noMatches`,`No runs match the current filters.`):e(`pipelineRuns.empty`,`No pipeline runs yet.`)}),!w&&E.length>0&&(0,J.jsx)(`div`,{className:`space-y-1.5`,children:E.map(e=>(0,J.jsx)(Ke,{run:e,pipeline:e.pipeline_id?k[e.pipeline_id]:void 0,printersById:S,expanded:g.has(e.id),onToggle:()=>A(e.id),onCancel:()=>ne.mutate(e.id),onRetry:()=>T.mutate(e.id),cancelling:ne.isPending,retrying:T.isPending},e.id))}),!w&&D>Y&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between mt-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(Math.max(0,m-Y)),disabled:m===0,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.previous`,`Previous`)}),(0,J.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e(`pipelineRuns.pagination`,`{{start}}–{{end}} of {{total}}`,{start:m+1,end:Math.min(m+Y,D),total:D})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(m+Y),disabled:m+Y>=D,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.next`,`Next`)})]})]})}function Ke({run:e,pipeline:t,printersById:n,expanded:r,onToggle:i,onCancel:o,onRetry:s,cancelling:c,retrying:l}){let{t:u}=a(),d=[`queued`,`slicing`,`dispatching`,`in_progress`].includes(e.status),f=e.status===`partial_failure`||e.status===`failed`,p=e.status===`cancelled`&&e.error_message===`Cancelled by user`,m=e.target_kind===`printer_class`&&e.target_model_class?u(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):e.target_printer_id&&n[e.target_printer_id]?n[e.target_printer_id].name:null;return(0,J.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:i,"aria-label":r?u(`common.collapse`,`Collapse`):u(`common.expand`,`Expand`),"aria-expanded":r,className:`text-bambu-gray hover:text-white flex-shrink-0`,children:r?(0,J.jsx)(T,{className:`w-4 h-4`}):(0,J.jsx)(xe,{className:`w-4 h-4`})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm`,children:[(0,J.jsxs)(`span`,{className:`font-medium text-white`,children:[`#`,e.id]}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:t?.name??e.pipeline_name??`—`}),(0,J.jsx)(X,{status:e.status}),m&&(0,J.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray flex items-center gap-1`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),m]}),e.parent_run_id&&(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray/70 italic`,children:u(`pipelineRuns.retryOf`,`retry of #{{n}}`,{n:e.parent_run_id})})]}),e.source_filename&&(0,J.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-xs text-bambu-gray min-w-0`,children:[(0,J.jsx)(Fe,{className:`w-3 h-3 flex-shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,title:e.source_filename,children:e.source_filename})]}),(0,J.jsxs)(`div`,{className:`mt-0.5 text-xs text-bambu-gray/70 flex flex-wrap items-center gap-x-2`,children:[(0,J.jsx)(`span`,{children:new Date(e.created_at).toLocaleString()}),e.copies>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{children:u(`pipelineRuns.copies`,`{{n}} copies`,{n:e.copies})})]}),(e.copies_completed>0||e.copies_failed>0||e.copies_cancelled>0)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`span`,{className:`text-bambu-green`,children:e.copies_completed}),`/`,e.copies]}),e.copies_failed>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:u(`pipelineRuns.failedCount`,`{{n}} failed`,{n:e.copies_failed})})]})]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[d&&(0,J.jsxs)(`button`,{type:`button`,onClick:o,disabled:c,"aria-label":u(`common.cancel`,`Cancel`),className:`text-xs px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(ce,{className:`w-3 h-3`}),u(`common.cancel`,`Cancel`)]}),f&&(0,J.jsxs)(`button`,{type:`button`,onClick:s,disabled:l,"aria-label":u(`pipelineRuns.retryFailed`,`Retry failed`),className:`text-xs px-2 py-1 text-bambu-green hover:bg-bambu-green/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(B,{className:`w-3 h-3`}),u(`pipelineRuns.retryFailed`,`Retry failed`)]})]})]}),r&&(0,J.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary px-3 py-2 bg-bambu-dark/30`,children:[(0,J.jsx)(`div`,{className:`space-y-1.5`,children:e.jobs.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/60 w-14 flex-shrink-0`,children:u(`pipelineRuns.copyN`,`Copy {{n}}`,{n:e.copy_index+1})}),(0,J.jsx)(Je,{status:e.status}),e.assigned_printer_name&&(0,J.jsxs)(`span`,{className:`text-bambu-gray flex items-center gap-1 truncate`,children:[(0,J.jsx)(ye,{className:`w-3 h-3 text-bambu-gray/60`}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:e.assigned_printer_name})]}),e.error_message&&(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400 truncate`,title:e.error_message,children:e.error_message})]},e.id))}),e.error_message&&!p&&(0,J.jsx)(`div`,{className:`text-xs text-red-700 dark:text-red-400 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:e.error_message}),p&&(0,J.jsx)(`div`,{className:`text-xs text-bambu-gray/70 mt-2 pt-2 border-t border-bambu-dark-tertiary italic`,children:u(`pipelineRuns.cancelledByUser`,`Cancelled by user`)})]})]})}function X({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide whitespace-nowrap ${{queued:`bg-slate-700 text-slate-200`,slicing:`bg-sky-700 text-sky-100`,dispatching:`bg-sky-700 text-sky-100`,in_progress:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,partial_failure:`bg-amber-700 text-amber-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`settings.pipelines.runs.status.${e}`,e)})}function qe({value:e,onChange:t,options:n,icon:r,ariaLabel:i}){let[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=n.find(t=>t.value===e),l=[];for(let e of n){let t=l[l.length-1];t&&t.group===e.group?t.options.push(e):l.push({group:e.group,options:[e]})}return(0,J.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":i,"aria-haspopup":`listbox`,"aria-expanded":a,className:`flex items-center gap-1.5 px-2 py-1 border border-bambu-dark-tertiary rounded bg-bambu-dark/40 text-xs text-white hover:border-bambu-gray/60 focus:outline-none focus:ring-1 focus:ring-bambu-green/40`,children:[r,(0,J.jsx)(`span`,{className:`truncate max-w-[14rem]`,children:c?.label??``}),(0,J.jsx)(T,{className:`w-3 h-3 text-bambu-gray transition-transform ${a?`rotate-180`:``}`})]}),a&&(0,J.jsx)(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-full max-h-72 overflow-auto rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-xl py-1`,children:l.map((n,r)=>(0,J.jsxs)(`div`,{children:[n.group&&(0,J.jsx)(`div`,{className:`px-2 pt-1.5 pb-0.5 text-[10px] uppercase tracking-wider text-bambu-gray/60`,children:n.group}),n.options.map(n=>{let r=n.value===e;return(0,J.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":r,onClick:()=>{t(n.value),o(!1)},className:`flex w-full items-center gap-1.5 text-left px-2 py-1 text-xs whitespace-nowrap ${r?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary/60 hover:text-white`}`,children:[(0,J.jsx)(ne,{className:`w-3 h-3 flex-shrink-0 ${r?`opacity-100`:`opacity-0`}`}),(0,J.jsx)(`span`,{className:`truncate`,children:n.label})]},n.value)})]},r))})]})}function Je({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide ${{pending:`bg-slate-700 text-slate-200`,awaiting_printer:`bg-sky-700 text-sky-100`,queued:`bg-sky-700 text-sky-100`,printing:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`pipelineRuns.jobStatus.${e}`,e)})}function Ye(e){return e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function Xe({activeCount:e,pendingCount:t,totalTime:n,totalWeight:r,historyCount:i,t:a}){return(0,J.jsx)(`div`,{className:`flex items-center gap-3 sm:gap-5 flex-wrap px-4 py-3 bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary mb-6`,children:[{icon:oe,value:e,label:a(`queue.summary.printing`),color:`text-blue-600 dark:text-blue-400`},{icon:H,value:t,label:a(`queue.summary.queued`),color:`text-yellow-600 dark:text-yellow-400`},{icon:I,value:de(n),label:a(`queue.summary.totalTime`),color:`text-bambu-green`},{icon:Pe,value:Ye(r),label:a(`queue.summary.totalWeight`),color:`text-purple-600 dark:text-purple-400`},{icon:k,value:i,label:a(`queue.summary.history`),color:`text-bambu-gray`}].map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t>0&&(0,J.jsx)(`span`,{className:`hidden sm:block text-bambu-dark-tertiary`,children:`|`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(e.icon,{className:`w-4 h-4 ${e.color}`}),(0,J.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:e.value}),(0,J.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e.label})]})]},t))})}var Z={completed:{icon:k,color:`text-emerald-600 dark:text-emerald-400`,border:`border-l-emerald-500`},failed:{icon:E,color:`text-red-600 dark:text-red-400`,border:`border-l-red-500`},skipped:{icon:F,color:`text-orange-600 dark:text-orange-400`,border:`border-l-gray-500`},cancelled:{icon:_,color:`text-gray-400`,border:`border-l-gray-500`}};function Ze(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;return/^0{6,8}$/.test(t)||!/^[0-9a-fA-F]{6,8}$/.test(t)?null:`#${t.slice(0,6)}`}function Qe({item:e,onRequeue:t,onRemove:n,timeFormat:i=`system`,hasPermission:a,canModify:o,t:s}){let c=Z[e.status]||Z.cancelled,l=c.icon,u=Le(e),d=e.archive_thumbnail?r.getArchiveThumbnail(e.archive_id):e.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.library_file_id):null,f=e.completed_at||e.created_at,p=Ze(e.filament_color),m=e.filament_used_grams?Math.round(e.filament_used_grams):null,h=!!e.error_message&&(e.status===`failed`||e.status===`skipped`);return(0,J.jsxs)(`div`,{className:`px-3 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] ${c.border}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,J.jsx)(l,{className:`w-4 h-4 shrink-0 ${c.color}`}),(0,J.jsxs)(`div`,{className:`relative shrink-0 history-thumb-hover`,children:[(0,J.jsx)(`div`,{className:`w-8 h-8 bg-bambu-dark rounded overflow-hidden`,children:d?(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover`}):(0,J.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,J.jsx)(ke,{className:`w-4 h-4`})})}),d&&(0,J.jsx)(`div`,{className:`history-thumb-preview absolute z-[60] left-full top-0 ml-2 w-48 h-48 pointer-events-none opacity-0 transition-opacity`,children:(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover rounded-lg shadow-2xl border-2 border-bambu-dark-tertiary bg-bambu-dark`})})]}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:u}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,title:f??void 0,children:fe(f,i,s)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:t,disabled:!a(`queue:create`),title:a(`queue:create`)?s(`queue.actions.requeue`):s(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:n,disabled:!o(`queue`,`delete`,e.created_by_id),title:o(`queue`,`delete`,e.created_by_id)?s(`common.remove`):s(`queue.permissions.noRemove`),className:`p-1.5`,children:(0,J.jsx)(he,{className:`w-3.5 h-3.5`})})]})]}),(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[e.printer_name&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[100px] sm:max-w-[140px]`,children:e.printer_name})]}),(p||m)&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[p?(0,J.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-full border border-white/15`,style:{backgroundColor:p},"aria-hidden":!0}):(0,J.jsx)(Pe,{className:`w-3 h-3`}),(0,J.jsxs)(`span`,{className:`truncate`,children:[m?`${m}g`:null,m&&e.filament_type?` ${e.filament_type}`:null,!m&&e.filament_type?e.filament_type:null]})]}),e.print_time_seconds&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(I,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.created_by_username&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,title:s(`queue.addedBy`,{name:e.created_by_username}),children:[(0,J.jsx)(Se,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.created_by_username})]})]}),h&&(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex items-start gap-1 text-xs text-red-700 dark:text-red-400`,children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,J.jsx)(`span`,{className:`break-words`,children:e.error_message})]})]})}function $e(e){return e.printer_id==null?e.target_model?`model:${e.target_model}`:`unassigned`:`printer:${e.printer_id}`}function et(e,t,n){if(n){let n=+!!e.been_jumped,r=+!!t.been_jumped;if(n!==r)return r-n;let i=e.print_time_seconds??1/0,a=t.print_time_seconds??1/0;if(i!==a)return i-a}return e.position===t.position?(e.id??0)-(t.id??0):e.position-t.position}function tt(e){return e?e.split(` | `).map(e=>e.trim()).every(e=>e.startsWith(`Busy:`)):!1}var nt=3600*1e3,rt=24,it=rt*nt,at=32,ot=40;function st(e){return e.toLocaleTimeString(void 0,{hour:`numeric`})}function ct(e){return e.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function lt({queueItems:e,printers:t,printerStatuses:n,sjfEnabled:i,onItemClick:a,t:o}){let[s,c]=(0,q.useState)(()=>new Date);(0,q.useEffect)(()=>{let e=setInterval(()=>c(new Date),6e4);return()=>clearInterval(e)},[]);let[l,u]=(0,q.useState)(0),d=(0,q.useMemo)(()=>{let e=s.getTime()+l;return Math.floor(e/nt)*nt},[s,l]),f=d+it,p=s.getTime(),m=(0,q.useMemo)(()=>{let t=[],r=new Map,a=new Set,o=new Map;for(let i of e)if(i.status===`printing`){let e=i.printer_id==null?void 0:n[i.printer_id],r=z(i.started_at)||new Date,s;if(e?.remaining_time!=null&&e.remaining_time>0)s=new Date(p+e.remaining_time*60*1e3);else if(i.print_time_seconds){let t=e?.progress||0,n=Math.max(0,1-t/100);s=new Date(p+i.print_time_seconds*n*1e3)}else s=new Date(p+nt);t.push({item:i,estimatedStart:r,estimatedEnd:s,progress:e?.progress??void 0,type:`printing`});let c=$e(i);a.add(c),o.set(c,Math.max(o.get(c)??p,s.getTime()))}else if(i.status===`pending`){if(i.manual_start||i.waiting_reason&&!tt(i.waiting_reason))continue;let e=$e(i);r.has(e)||r.set(e,[]),r.get(e).push(i)}let s=Date.now()+4320*nt;for(let[e,n]of r){n.sort((e,t)=>et(e,t,i));let r=a.has(e),c=n[0]?z(n[0].scheduled_time):null,l=c&&c.getTime()<=s;if(!r&&!l)continue;let u=o.get(e)??p;for(let e of n){let n=z(e.scheduled_time);n&&n.getTime()<=s&&(u=Math.max(u,n.getTime()));let r=(e.print_time_seconds||3600)*1e3;t.push({item:e,estimatedStart:new Date(u),estimatedEnd:new Date(u+r),type:`queued`}),u+=r}}return t},[e,n,p,i]),h=(0,q.useMemo)(()=>{let e=[];for(let n of t)e.push({key:`printer:${n.id}`,label:n.name,printerId:n.id,targetModel:null});let n=new Set,r=!1;for(let t of m)if(t.item.printer_id==null)if(t.item.target_model){let r=`model:${t.item.target_model}`;n.has(r)||(n.add(r),e.push({key:r,label:`${o(`queue.filter.any`)} ${t.item.target_model}`,printerId:null,targetModel:t.item.target_model}))}else r=!0;return r&&e.push({key:`unassigned`,label:o(`queue.filter.unassigned`),printerId:null,targetModel:null}),e},[t,m,o]),g=(0,q.useMemo)(()=>{let e=new Map;for(let t of m){let n;n=t.item.printer_id==null?t.item.target_model?`model:${t.item.target_model}`:`unassigned`:`printer:${t.item.printer_id}`,e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[m]),_=(0,q.useMemo)(()=>{let e=[];for(let t=0;t<=rt;t+=2){let n=d+t*nt;e.push({ms:n,pct:t/rt*100,label:st(new Date(n))})}return e},[d]),v=(p-d)/it*100,y=v>=0&&v<=100,b=(0,q.useMemo)(()=>{let e=0;for(let t of m)e=Math.max(e,t.estimatedEnd.getTime());return e>0?new Date(e):null},[m]),x=(0,q.useRef)(null);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e-12*nt),className:`p-1.5`,title:o(`queue.timeline.window.back12h`),children:(0,J.jsx)(Ae,{className:`w-4 h-4`})}),(0,J.jsxs)(`span`,{className:`text-sm font-medium text-white min-w-[180px] text-center`,children:[new Date(d).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),` → `,new Date(f).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e+12*nt),className:`p-1.5`,title:o(`queue.timeline.window.forward12h`),children:(0,J.jsx)(xe,{className:`w-4 h-4`})}),l!==0&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(0),className:`text-xs text-bambu-green`,children:o(`queue.timeline.window.now`)})]}),b&&(0,J.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1.5`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),o(`queue.timeline.allDoneBy`,{time:b.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})})]})]}),h.length>0&&m.length===0&&(0,J.jsx)(`div`,{className:`mb-4 p-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 text-xs text-bambu-gray`,children:o(`queue.timeline.nothingCommitted`)}),h.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,J.jsx)(ke,{className:`w-12 h-12 mb-3 opacity-30`}),(0,J.jsx)(`p`,{className:`text-sm`,children:o(`queue.timeline.noData`)})]}):(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-2 text-xs font-medium text-bambu-gray border-r border-bambu-dark-tertiary`,children:o(`queue.timeline.printerColumnHeader`)}),(0,J.jsx)(`div`,{className:`relative flex-1 h-9`,children:_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/40 text-[10px] sm:text-xs text-bambu-gray pl-1 flex items-center`,style:{left:`${e.pct}%`},children:e.label},e.ms))})]}),(0,J.jsxs)(`div`,{ref:x,className:`relative`,children:[h.map(e=>{let t=g.get(e.key)??[];return(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary/40 last:border-b-0`,children:[(0,J.jsxs)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-3 border-r border-bambu-dark-tertiary flex items-center gap-2`,children:[(0,J.jsx)(ye,{className:`w-3.5 h-3.5 shrink-0 ${e.printerId==null&&e.targetModel==null?`text-orange-600 dark:text-orange-400`:e.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,J.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.label})]}),(0,J.jsxs)(`div`,{className:`relative flex-1`,style:{height:56},children:[_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/30`,style:{left:`${e.pct}%`}},e.ms)),(0,J.jsx)(`div`,{className:`absolute inset-0 opacity-30`,style:{backgroundImage:`repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,0.04) 6px, rgba(255,255,255,0.04) 12px)`},"aria-hidden":!0}),t.map(e=>{let t=Math.max(d,e.estimatedStart.getTime()),n=Math.min(f,e.estimatedEnd.getTime());if(n<=d||t>=f)return null;let i=(t-d)/it*100,o=(n-t)/it*100,s=e.item.archive_name||e.item.library_file_name||`#${e.item.id}`,c=e.item.archive_thumbnail?r.getArchiveThumbnail(e.item.archive_id):e.item.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.item.library_file_id):null,l=e.type===`printing`,u=e.item.batch_id!=null;return(0,J.jsxs)(`button`,{onClick:()=>a(e.item),title:[s,`${ct(e.estimatedStart)} → ${ct(e.estimatedEnd)}`,e.item.print_time_seconds?de(e.item.print_time_seconds):null,l&&e.progress!=null?`${Math.round(e.progress)}%`:null,e.item.batch_name?`batch: ${e.item.batch_name}`:null].filter(Boolean).join(` · `),className:`absolute rounded-md transition-all hover:brightness-110 hover:z-10 overflow-hidden flex items-center gap-1.5 px-1.5 text-left ${l?`bg-blue-500/30 border border-blue-400/60`:u?`bg-cyan-500/20 border border-cyan-400/50`:`bg-bambu-green/20 border border-bambu-green/40`}`,style:{left:`${i}%`,width:`max(${at}px, ${o}%)`,top:8,height:ot},children:[c&&(0,J.jsx)(`img`,{src:c,alt:``,className:`w-7 h-7 rounded object-cover shrink-0 bg-bambu-dark`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-xs text-white font-medium truncate leading-tight`,children:s}),(0,J.jsxs)(`div`,{className:`text-[10px] text-bambu-gray truncate leading-tight`,children:[e.item.print_time_seconds?de(e.item.print_time_seconds):``,l&&e.progress!=null?` · ${Math.round(e.progress)}%`:``]})]}),l&&e.progress!=null&&(0,J.jsx)(`div`,{className:`absolute bottom-0 left-0 h-0.5 bg-blue-300`,style:{width:`${e.progress}%`},"aria-hidden":!0})]},e.item.id)})]})]},e.key)}),y&&(0,J.jsxs)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none z-20 flex inset-x-0`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0`}),(0,J.jsx)(`div`,{className:`relative flex-1`,children:(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.6)]`,style:{left:`${v}%`},children:(0,J.jsx)(`div`,{className:`absolute -top-1 -left-1 w-2.5 h-2.5 bg-red-400 rounded-full`})})})]})]})]})]})}function ut({hasPermission:e,t,focusBatchId:n=null}){let i=o(),{showToast:a}=O(),[l,u]=(0,q.useState)(n?`all`:`active`),[d,f]=(0,q.useState)(null),{data:p}=s({queryKey:[`settings`],queryFn:r.getSettings}),m=De(p?.currency||`USD`),{data:h,isLoading:g}=s({queryKey:[`batches`,l],queryFn:()=>r.getBatches(l===`all`?void 0:l)}),_=n!=null&&!!h?.some(e=>e.id===n);(0,q.useEffect)(()=>{_&&document.getElementById(`batch-${n}`)?.scrollIntoView({block:`center`})},[_,n]);let v=()=>{i.invalidateQueries({queryKey:[`batches`]}),i.invalidateQueries({queryKey:[`queue`]})},y=c({mutationFn:({id:e,plateId:t})=>r.dispatchBatch(e,t===void 0?{}:{plate_id:t,only_plate:!0}),onSuccess:e=>{v(),a(t(`queue.batchOrders.dispatched`,{name:e.name}),`success`)},onError:e=>a(e.message,`error`)}),b=c({mutationFn:e=>r.cancelBatch(e),onSuccess:()=>{v(),f(null),a(t(`queue.batchCancelled`),`success`)},onError:e=>a(e.message,`error`)}),x=e(`queue:create`),S=e(`queue:delete_all`);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4`,children:[(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`h2`,{className:`text-base sm:text-lg font-semibold text-white`,children:t(`queue.batchOrders.title`)}),(0,J.jsx)(`div`,{className:`flex gap-1 ml-auto`,children:[`active`,`completed`,`cancelled`,`all`].map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-xs px-2.5 py-1 rounded-full border transition-colors ${l===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:t(`queue.batchOrders.filter.${e}`)},e))})]}),g?(0,J.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:t(`common.loading`)}):h?.length?(0,J.jsx)(`div`,{className:`space-y-4`,children:h.map(e=>(0,J.jsx)(ft,{batch:e,currency:m,canDispatch:x,canCancel:S,isDispatching:y.isPending&&y.variables?.id===e.id,highlighted:e.id===n,onDispatch:t=>y.mutate({id:e.id,plateId:t}),onCancel:()=>f(e),t},e.id))}):(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(N,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:t(`queue.batchOrders.emptyTitle`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:t(`queue.batchOrders.emptyDescription`)})]}),d&&(0,J.jsx)(Ee,{title:t(`queue.cancelBatchConfirmTitle`),message:t(`queue.cancelBatchConfirmMessage`),confirmText:t(`queue.cancelBatch`),variant:`warning`,onConfirm:()=>b.mutate(d.id),onCancel:()=>f(null)})]})}var dt={active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`,completed:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`,cancelled:`bg-bambu-dark-tertiary text-bambu-gray`};function ft({batch:e,currency:t,canDispatch:n,canCancel:r,isDispatching:i,onDispatch:a,onCancel:o,t:s,highlighted:c=!1}){let l=e.has_targets?e.target_count:e.completed_count+e.pending_count+e.printing_count+e.failed_count,u=l>0?Math.round(e.completed_count/l*100):0,d=e.has_targets?e.remaining_count-e.dispatchable_count:0,f=e.due_date?z(e.due_date):null,p=f!=null&&e.status===`active`&&f.getTime()0&&e.status!==`cancelled`&&n&&(0,J.jsxs)(R,{variant:`primary`,size:`sm`,onClick:()=>a(),disabled:i,children:[(0,J.jsx)(ze,{className:`w-4 h-4 mr-1`}),s(`queue.batchOrders.dispatchRemaining`,{count:e.dispatchable_count})]}),e.status===`active`&&r&&(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:o,children:[(0,J.jsx)(E,{className:`w-4 h-4 mr-1`}),s(`queue.cancelBatch`)]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,J.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,J.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.status===`completed`?`bg-bambu-green`:`bg-blue-500`}`,style:{width:`${Math.min(100,u)}%`}})}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap tabular-nums`,children:s(`queue.batchProgress`,{completed:e.completed_count,total:l})})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-bambu-gray mb-1`,children:[e.printing_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.printing`,{count:e.printing_count})}),e.pending_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batch.pendingCount`,{count:e.pending_count})}),e.failed_count>0&&(0,J.jsxs)(`span`,{className:`text-orange-600 dark:text-orange-400 flex items-center gap-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3`}),s(`queue.batchOrders.failed`,{count:e.failed_count})]}),e.has_targets&&e.remaining_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.remaining`,{count:e.remaining_count})}),e.print_time_seconds>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(H,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.actual_cost!=null&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(A,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costSoFar`,{amount:`${t} ${e.actual_cost.toFixed(2)}`})}),e.estimated_remaining_cost!=null&&e.estimated_remaining_cost>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costRemaining`,{amount:`${t} ${e.estimated_remaining_cost.toFixed(2)}`})})]})]}),d>0&&e.status!==`cancelled`&&(0,J.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-orange-600 dark:text-orange-400 mb-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.strandedNotice`,{runs:d,owed:e.remaining_count})})]}),e.has_targets&&e.plates.length>0&&(0,J.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3 space-y-1.5`,children:e.plates.map(r=>(0,J.jsx)(pt,{plate:r,batchStatus:e.status,currency:t,canDispatch:n,isDispatching:i,onDispatch:()=>a(r.plate_id),t:s},`${r.plate_id??`file`}`))})]})}function pt({plate:e,batchStatus:t,currency:n,canDispatch:r,isDispatching:i,onDispatch:a,t:o}){let s=e.plate_name||(e.plate_id==null?o(`queue.batchOrders.wholeFile`):o(`queue.plateNumber`,{index:e.plate_id}));return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs`,children:[(0,J.jsx)(ke,{className:`w-3.5 h-3.5 text-bambu-gray flex-shrink-0`}),(0,J.jsx)(`span`,{className:`text-white min-w-0 truncate`,children:s}),(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:o(`queue.batchOrders.plateProgress`,{completed:e.completed_count,target:e.quantity_target})}),e.failed_count>0&&(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.failed`,{count:e.failed_count})}),e.actual_cost!=null&&(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:`${n} ${e.actual_cost.toFixed(2)}`}),e.remaining>0&&t!==`cancelled`&&(0,J.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray`,children:o(`queue.batchOrders.remaining`,{count:e.remaining})}),e.can_dispatch?r&&(0,J.jsx)(`button`,{type:`button`,onClick:a,disabled:i,className:`text-bambu-green hover:underline disabled:opacity-50`,children:o(`queue.batchOrders.dispatchPlate`)}):(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.strandedPlate`)})]})]})}function mt(e,t){if(!e?.connected||t>=254)return;let n=t>=128,r=n?t:Math.floor(t/4),i=n?0:t%4,a=e.ams?.find(e=>e.id===r);if(W(n?a?.tray[0]:a?.tray.find(e=>e.id===i))===`physical`)return ve(r,i,n,!1)}function ht(e){return e.slotLabel?[e.slotLabel,e.spoolName||e.type,e.colorName].filter(Boolean).join(` · `):e.colorName}function gt(e,t,n=[],r,i=`Empty`){let a=t=>{let a=t.slotId,o=a>0?e.ams_mapping?.[a-1]:void 0;if(o==null||o<0)return t;let s=n.find(e=>e.globalTrayId===o);if(s)return{slotId:a,type:s.type,color:s.color,colorName:s.colorName,slotLabel:s.label,spoolName:s.spoolName,extraColors:s.extraColors,effectType:s.effectType,subtype:s.spoolSubtype};let c=mt(r,o);return c?{...t,slotLabel:c,spoolName:i,emptySlot:!0}:t},o=e.plate_id==null?t[0]:t.find(t=>t.index===e.plate_id);if(o){let t=new Map((e.filament_overrides??[]).map(e=>[e.slot_id,e]));return o.filaments.filter(e=>e.used_in_plate!==!1&&e.used_grams>0).map(e=>{let n=t.get(e.slot_id),r=n?.color??e.color,i=n?.type??e.type;return a({slotId:e.slot_id,type:i,color:r,colorName:n?.color_name?.trim()||G(r,i)})})}return e.filament_overrides?.length?e.filament_overrides.map(e=>a({slotId:e.slot_id,type:e.type,color:e.color,colorName:e.color_name?.trim()||G(e.color,e.type)})):e.filament_color?[a({slotId:1,type:e.filament_type??``,color:e.filament_color,colorName:G(e.filament_color,e.filament_type)})]:[]}function _t(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function vt({status:e,waitingReason:t,printerState:n,t:r}){if(e===`pending`&&t)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-purple-700 dark:text-purple-400 bg-purple-50 dark:bg-purple-400/10 border-purple-200 dark:border-purple-400/20`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),r(`queue.status.waiting`)]});if(e===`printing`&&n===`PAUSE`)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-400/10 border-yellow-200 dark:border-yellow-400/20`,children:[(0,J.jsx)(P,{className:`w-3.5 h-3.5`}),r(`queue.status.paused`)]});let{icon:i,color:a,label:o}={pending:{icon:H,color:`text-status-warning bg-status-warning/10 border-status-warning/20`,label:r(`queue.status.pending`)},printing:{icon:oe,color:`text-blue-700 dark:text-blue-400 bg-blue-50 dark:bg-blue-400/10 border-blue-200 dark:border-blue-400/20`,label:r(`queue.status.printing`)},completed:{icon:k,color:`text-status-ok bg-status-ok/10 border-status-ok/20`,label:r(`queue.status.completed`)},failed:{icon:E,color:`text-status-error bg-status-error/10 border-status-error/20`,label:r(`queue.status.failed`)},skipped:{icon:F,color:`text-orange-700 dark:text-orange-400 bg-orange-50 dark:bg-orange-400/10 border-orange-200 dark:border-orange-400/20`,label:r(`queue.status.skipped`)},cancelled:{icon:ce,color:`text-gray-400 bg-gray-400/10 border-gray-400/20`,label:r(`queue.status.cancelled`)}}[e];return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a}`,children:[(0,J.jsx)(i,{className:`w-3.5 h-3.5`}),o]})}function yt({selectedCount:e,printers:t,onSave:n,onClose:r,isSaving:i,canControlPrinter:a,hasGcodeSnippets:o,t:s}){let[c,l]=(0,q.useState)(`unchanged`),[u,d]=(0,q.useState)(`unchanged`),[f,p]=(0,q.useState)(`unchanged`),[m,h]=(0,q.useState)(`unchanged`),[g,_]=(0,q.useState)(`unchanged`),[v,y]=(0,q.useState)(`unchanged`),[b,x]=(0,q.useState)(`unchanged`),[S,ee]=(0,q.useState)(`unchanged`),[C,te]=(0,q.useState)(`unchanged`),[w,ne]=(0,q.useState)(`unchanged`),[T,re]=(0,q.useState)(`unchanged`),[E,D]=(0,q.useState)(`unchanged`),[O,k]=(0,q.useState)(`unchanged`),A=t.some(e=>e.nozzle_count===2),j=()=>{let e={};c!==`unchanged`&&(e.printer_id=c),u!==`unchanged`&&(e.manual_start=u),f!==`unchanged`&&(e.auto_off_after=f),m!==`unchanged`&&(e.require_previous_success=m),g!==`unchanged`&&(e.gcode_injection=g),v!==`unchanged`&&(e.bed_levelling=v),b!==`unchanged`&&(e.flow_cali=b),S!==`unchanged`&&(e.vibration_cali=S),C!==`unchanged`&&(e.layer_inspect=C),w!==`unchanged`&&(e.timelapse=w),T!==`unchanged`&&(e.use_ams=T),E!==`unchanged`&&(e.confirm_outcome=E),O!==`unchanged`&&(e.nozzle_offset_cali=O),n(e)},M=c!==`unchanged`||u!==`unchanged`||f!==`unchanged`||m!==`unchanged`||v!==`unchanged`||b!==`unchanged`||S!==`unchanged`||C!==`unchanged`||w!==`unchanged`||T!==`unchanged`||E!==`unchanged`||O!==`unchanged`||g!==`unchanged`;return(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm`,children:(0,J.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`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:s(`queue.bulkEdit.title`,{count:e})}),(0,J.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,J.jsx)(ce,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,J.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:s(`queue.bulkEdit.description`)}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printer`)}),(0,J.jsxs)(`select`,{value:c===null?`null`:c===`unchanged`?`unchanged`:String(c),onChange:e=>{let t=e.target.value;l(t===`unchanged`?`unchanged`:t===`null`?null:Number(t))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,J.jsx)(`option`,{value:`unchanged`,children:s(`queue.bulkEdit.noChange`)}),(0,J.jsx)(`option`,{value:`null`,children:s(`queue.filter.unassigned`)}),t.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.queueOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(Q,{label:s(`queue.bulkEdit.staged`),value:u,onChange:d,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.autoPowerOff`),value:f,onChange:p,disabled:!a,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.requirePrevious`),value:m,onChange:h,t:s}),o&&(0,J.jsx)(Q,{label:s(`queue.bulkEdit.gcodeInjection`),value:g,onChange:_,t:s})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(bt,{label:s(`queue.bulkEdit.bedLevelling`),value:v,onChange:y,t:s}),(0,J.jsx)(bt,{label:s(`queue.bulkEdit.flowCalibration`),value:b,onChange:x,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.vibrationCalibration`),value:S,onChange:ee,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.layerInspection`),value:C,onChange:te,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.timelapse`),value:w,onChange:ne,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.useAms`),value:T,onChange:re,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.confirmOutcome`),value:E,onChange:D,t:s}),A&&(0,J.jsx)(bt,{label:s(`queue.bulkEdit.nozzleOffsetCali`),value:O,onChange:k,t:s})]})]})]}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,J.jsx)(R,{variant:`secondary`,onClick:r,children:s(`common.cancel`)}),(0,J.jsx)(R,{onClick:j,disabled:!M||i,children:s(i?`common.saving`:`queue.bulkEdit.applyChanges`)})]})]})})}function Q({label:e,value:t,onChange:n,disabled:r,t:i}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1 ${r?`opacity-50`:``}`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:[(0,J.jsx)(`button`,{onClick:()=>n(`unchanged`),disabled:r,className:`px-2 py-1 text-xs rounded ${t===`unchanged`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:`—`}),(0,J.jsx)(`button`,{onClick:()=>n(!1),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!1?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.off`)}),(0,J.jsx)(`button`,{onClick:()=>n(!0),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!0?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.on`)})]})]})}function bt({label:e,value:t,onChange:n,t:r}){let i=[{key:`unchanged`,label:`—`,active:`bg-bambu-dark-tertiary text-white`},{key:`off`,label:r(`settings.calibrationMode_off`),active:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`},{key:`auto`,label:r(`settings.calibrationMode_auto`),active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},{key:`on`,label:r(`settings.calibrationMode_on`),active:`bg-bambu-green/20 text-bambu-green`}];return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:i.map(({key:e,label:r,active:i})=>(0,J.jsx)(`button`,{onClick:()=>n(e),className:`px-2 py-1 text-xs rounded ${t===e?i:`text-bambu-gray hover:text-white`}`,children:r},e))})]})}function xt({item:e,position:t,onEdit:n,onCancel:i,onRemove:a,onStop:o,onRequeue:c,onStart:l,onMoveUp:u,onMoveDown:d,timeFormat:f=`system`,isSelected:m=!1,onToggleSelect:h,hasPermission:g,canModify:_,printerState:v,showEta:y=!1,etaNow:x,t:S}){let{hasAnyPermission:ee}=Ie(),C=!ee(`queue:update_all`,`queue:start_unreviewed`),te=e.printer_id!=null&&(e.ams_mapping?.some(e=>e>=0)??!1),{data:w}=s({queryKey:[`printerStatus`,e.printer_id],queryFn:()=>r.getPrinterStatus(e.printer_id),refetchInterval:v===`printing`?3e4:!1,enabled:e.printer_id!=null&&(v===`printing`||te)}),{data:E}=s({queryKey:[`printer-inventory-remain`,e.printer_id],queryFn:()=>r.getInventoryRemain(e.printer_id),enabled:te,staleTime:30*1e3}),O=(0,q.useMemo)(()=>{let e=E?.slot_materials;if(!e?.length)return;let t=new Map;return e.forEach(e=>{e.spool&&t.set(e.global_tray_id,e.spool)}),t.size>0?t:void 0},[E]),k=(0,q.useMemo)(()=>me(w,O),[w,O]),A=!!e.library_file_id&&!e.archive_id,{data:j}=s({queryKey:[`archive-plates`,e.archive_id],queryFn:()=>r.getArchivePlates(e.archive_id),enabled:!!e.archive_id&&!A&&!e.archive_deleted}),{data:ie}=s({queryKey:[`library-file-plates`,e.library_file_id],queryFn:()=>r.getLibraryFilePlates(e.library_file_id),enabled:A&&!!e.library_file_id}),ae=A?ie:j,N=ae?.plates??[],P=gt(e,N,k,w,S(`ams.empty`)),F=g(`queue:reorder`),{attributes:L,listeners:se,setNodeRef:le,transform:B,transition:ve,isDragging:be}=p({id:e.id,disabled:e.status!==`pending`||!F}),xe={transform:b.Transform.toString(B),transition:ve},we=e.status===`printing`,W=e.status===`pending`,Ee=[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status),De=W&&y&&e.print_time_seconds!=null&&e.print_time_seconds>0?ue(e.print_time_seconds/60,f,S,x):null,Oe=W&&h;return(0,J.jsxs)(`div`,{ref:le,style:xe,className:`
group relative bg-bambu-dark-secondary rounded-xl border transition-all duration-200
border-l-[3px] ${we?`border-l-blue-500`:W?`border-l-yellow-500`:e.status===`completed`?`border-l-emerald-500`:e.status===`failed`?`border-l-red-500`:`border-l-gray-500`}
${be?`opacity-50 scale-[1.02] shadow-xl z-50`:``}
diff --git a/static/assets/RichTextEditor-DoPGmmPm.js b/static/assets/RichTextEditor-CvxzYgcv.js
similarity index 99%
rename from static/assets/RichTextEditor-DoPGmmPm.js
rename to static/assets/RichTextEditor-CvxzYgcv.js
index 9b78b2340..2faa951a4 100644
--- a/static/assets/RichTextEditor-DoPGmmPm.js
+++ b/static/assets/RichTextEditor-CvxzYgcv.js
@@ -1,4 +1,4 @@
-import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,T as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./react-dom-xhkz5--P.js";import{t as o}from"./createLucideIcon-Yo2YoYjm.js";import{t as s}from"./list-CBXEiN6g.js";import{t as c}from"./unlink-DJBJ04VB.js";import{on as l,sn as u}from"./index-Bw-_P2Fg.js";import{t as d}from"./with-selector-C2KEMbwS.js";var f=o(`bold`,[[`path`,{d:`M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8`,key:`mg9rjx`}]]),p=o(`italic`,[[`line`,{x1:`19`,x2:`10`,y1:`4`,y2:`4`,key:`15jd3p`}],[`line`,{x1:`14`,x2:`5`,y1:`20`,y2:`20`,key:`bu0au3`}],[`line`,{x1:`15`,x2:`9`,y1:`4`,y2:`20`,key:`uljnxc`}]]),m=o(`text-align-center`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M17 12H7`,key:`16if0g`}],[`path`,{d:`M19 19H5`,key:`vjpgq2`}]]),h=o(`text-align-end`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M21 19H7`,key:`4cu937`}]]),g=o(`text-align-start`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]]),_=o(`underline`,[[`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`,key:`9kb039`}],[`line`,{x1:`4`,x2:`20`,y1:`20`,y2:`20`,key:`nun2al`}]]),v=e(n(),1),y=e(a(),1),b=r(),x=t(),ee=Object.defineProperty,te=(e,t)=>{let n={};for(var r in e)ee(n,r,{get:e[r],enumerable:!0});return t||ee(n,Symbol.toStringTag,{value:`Module`}),n};function S(e){this.content=e}S.prototype={constructor:S,find:function(e){for(var t=0;t>1}},S.from=function(e){if(e instanceof S)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new S(t)};function ne(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){let e=i.text,t=a.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r0&&a>0&&e[i-1]==t[a-1];)i--,a--,n--,r--;return i&&a&&i=56320&&e<57344}function ae(e){return e>=55296&&e<56320}var C=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;te&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);at)for(let e=0,a=0;at&&((an)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?se(t+1,i):se(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;ethis.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank),n}};w.none=[];var le=class extends Error{},T=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=de(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(ue(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(C.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};T.empty=new T(C.empty,0,0);function ue(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(ue(a.content,t-i-1,n-i-1)))}function de(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=de(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function fe(e,t,n){if(n.openStart>e.depth)throw new le(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new le(`Inconsistent open depths`);return pe(e,t,n,0)}function pe(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function _e(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(ge(e.nodeAfter,r),a++));for(let e=a;ei&&he(e,t,i+1),o=r.depth>i&&he(n,r,i+1),s=[];return _e(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(me(a,o),ge(ve(a,ye(e,t,n,r,i+1)),s)):(a&&ge(ve(a,be(e,t,i+1)),s),_e(t,n,i,s),o&&ge(ve(o,be(n,r,i+1)),s)),_e(r,null,i,s),new C(s)}function be(e,t,n){let r=[];return _e(null,e,n,r),e.depth>n&&ge(ve(he(e,t,n+1),be(e,t,n+1)),r),_e(t,null,n,r),new C(r)}function xe(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(C.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var Se=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new Ee(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=Te.get(t);if(r)for(let e=0;ee&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),Ae(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=C.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;ee.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=C.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};Oe.prototype.text=void 0;var ke=class e extends Oe{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Ae(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Ae(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var je=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Me(t,n);if(r.next==null)return e.empty;let i=Ne(r);r.next&&r.err(`Unexpected trailing text`);let a=Ue(Be(i));return We(a,r),a}matchType(e){for(let t=0;te.createAndFill()));for(let e=0;e=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n`+e.indexOf(t.next[n].next);return r}).join(`
+import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,T as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./react-dom-xhkz5--P.js";import{t as o}from"./createLucideIcon-Yo2YoYjm.js";import{t as s}from"./list-CBXEiN6g.js";import{t as c}from"./unlink-DJBJ04VB.js";import{on as l,sn as u}from"./index-ggB_TpPo.js";import{t as d}from"./with-selector-C2KEMbwS.js";var f=o(`bold`,[[`path`,{d:`M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8`,key:`mg9rjx`}]]),p=o(`italic`,[[`line`,{x1:`19`,x2:`10`,y1:`4`,y2:`4`,key:`15jd3p`}],[`line`,{x1:`14`,x2:`5`,y1:`20`,y2:`20`,key:`bu0au3`}],[`line`,{x1:`15`,x2:`9`,y1:`4`,y2:`20`,key:`uljnxc`}]]),m=o(`text-align-center`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M17 12H7`,key:`16if0g`}],[`path`,{d:`M19 19H5`,key:`vjpgq2`}]]),h=o(`text-align-end`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M21 19H7`,key:`4cu937`}]]),g=o(`text-align-start`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]]),_=o(`underline`,[[`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`,key:`9kb039`}],[`line`,{x1:`4`,x2:`20`,y1:`20`,y2:`20`,key:`nun2al`}]]),v=e(n(),1),y=e(a(),1),b=r(),x=t(),ee=Object.defineProperty,te=(e,t)=>{let n={};for(var r in e)ee(n,r,{get:e[r],enumerable:!0});return t||ee(n,Symbol.toStringTag,{value:`Module`}),n};function S(e){this.content=e}S.prototype={constructor:S,find:function(e){for(var t=0;t>1}},S.from=function(e){if(e instanceof S)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new S(t)};function ne(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){let e=i.text,t=a.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r0&&a>0&&e[i-1]==t[a-1];)i--,a--,n--,r--;return i&&a&&i=56320&&e<57344}function ae(e){return e>=55296&&e<56320}var C=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;te&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);at)for(let e=0,a=0;at&&((an)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?se(t+1,i):se(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;ethis.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank),n}};w.none=[];var le=class extends Error{},T=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=de(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(ue(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(C.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};T.empty=new T(C.empty,0,0);function ue(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(ue(a.content,t-i-1,n-i-1)))}function de(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=de(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function fe(e,t,n){if(n.openStart>e.depth)throw new le(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new le(`Inconsistent open depths`);return pe(e,t,n,0)}function pe(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function _e(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(ge(e.nodeAfter,r),a++));for(let e=a;ei&&he(e,t,i+1),o=r.depth>i&&he(n,r,i+1),s=[];return _e(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(me(a,o),ge(ve(a,ye(e,t,n,r,i+1)),s)):(a&&ge(ve(a,be(e,t,i+1)),s),_e(t,n,i,s),o&&ge(ve(o,be(n,r,i+1)),s)),_e(r,null,i,s),new C(s)}function be(e,t,n){let r=[];return _e(null,e,n,r),e.depth>n&&ge(ve(he(e,t,n+1),be(e,t,n+1)),r),_e(t,null,n,r),new C(r)}function xe(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(C.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var Se=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new Ee(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=Te.get(t);if(r)for(let e=0;ee&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),Ae(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=C.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;ee.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=C.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};Oe.prototype.text=void 0;var ke=class e extends Oe{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Ae(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Ae(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var je=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Me(t,n);if(r.next==null)return e.empty;let i=Ne(r);r.next&&r.err(`Unexpected trailing text`);let a=Ue(Be(i));return We(a,r),a}matchType(e){for(let t=0;te.createAndFill()));for(let e=0;e=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n`+e.indexOf(t.next[n].next);return r}).join(`
`)}};je.empty=new je(!0);var Me=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+` (in content expression '`+this.string+`')`)}};function Ne(e){let t=[];do t.push(Pe(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function Pe(e){let t=[];do t.push(Fe(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function Fe(e){let t=ze(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=Le(e,t);else break;return t}function Ie(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function Le(e,t){let n=Ie(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:Ie(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function Re(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function ze(e){if(e.eat(`(`)){let t=Ne(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=Re(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function Be(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new je(r.indexOf(e.length-1)>-1);for(let e=0;e-1}get whitespace(){return this.spec.whitespace||(this.spec.code?`pre`:`normal`)}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Ke(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new Oe(this,this.computeAttrs(e),C.from(t),w.setFrom(n))}createChecked(e=null,t,n){return t=C.from(t),this.checkContent(t),new Oe(this,this.computeAttrs(e),t,w.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=C.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(C.empty,!0);return i?new Oe(this,e,t.append(i),w.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function Xe(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var Ze=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?Xe(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},Qe=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=Je(e,r.attrs),this.excluded=null;let i=Ge(this.attrs);this.instance=i?new w(this,i):null}create(e=null){return!e&&this.instance?this.instance:new w(this,Ke(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}removeFromSet(e){for(var t=0;t-1}},$e=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=S.from(e.nodes),t.marks=S.from(e.marks||{}),this.nodes=Ye.compile(this.spec.nodes,this),this.marks=Qe.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=je.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?et(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:et(this,n.split(` `))}this.nodeFromJSON=e=>Oe.fromJSON(this,e),this.markFromJSON=e=>w.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof Ye))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new ke(n,n.defaultAttrs,e,w.setFrom(t))}mark(e,t){return typeof e==`string`&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type: `+e);return t}};function et(e,t){let n=[];for(let r=0;r-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function tt(e){return e.tag!=null}function nt(e){return e.style!=null}var rt=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(tt(e))this.tags.push(e);else if(nt(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new ft(this,t,!1);return n.addAll(e,w.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new ft(this,t,!0);return n.addAll(e,w.none,t.from,t.to),T.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;re.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r{n(e=ht(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=ht(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},it={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},at={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ot={ol:!0,ul:!0},st=1,ct=2,lt=4;function ut(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?st:0)|(t===`full`?ct:0)}var dt=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=w.none,this.match=i||(a<?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(C.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&st)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=C.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(C.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!it.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},ft=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=ut(null,t.preserveWhitespace,0)|(n?lt:0);i=r?new dt(r.type,r.attrs,w.none,!0,t.topMatch||r.type.contentMatch,a):n?new dt(null,null,w.none,!0,null,a):new dt(e.schema.topNodeType,null,w.none,!0,null,a),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=r.options&ct?`full`:this.localPreserveWS||(r.options&st)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,`
`);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node)if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e(a.type?a.type.allowsMarkType(t.type):gt(t.type,e))?(s=t.addToSet(s),!1):!0),this.nodes.push(new dt(e,t,s,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=st);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}else{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function pt(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&ot.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function mt(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function ht(e){let t={};for(let n in e)t[n]=e[n];return t}function gt(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n{if(i.length||e.marks.length){let n=0,a=0;for(;n=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&Ct(yt(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return typeof t==`string`?{dom:e.createTextNode(t)}:Ct(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=vt(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return vt(e.marks)}};function vt(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function yt(e){return e.document||window.document}var bt=new WeakMap;function xt(e){let t=bt.get(e);return t===void 0&&bt.set(e,t=St(e)),t}function St(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let o=i.indexOf(` `);o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;iu)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}else if(typeof a==`string`)c.appendChild(e.createTextNode(a));else{let{dom:t,contentDOM:i}=Ct(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var wt=65535,Tt=2**16;function Et(e,t){return e+t*Tt}function Dt(e){return e&wt}function Ot(e){return(e-(e&wt))/Tt}var kt=1,At=2,jt=4,Mt=8,Nt=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&Mt)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&jt)>0}},Pt=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=Dt(e);if(!this.inverted)for(let e=0;ee)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:Et(o/3,e-s),f=e==s?At:e==u?kt:jt;return(t<0?e!=s:e!=u)&&(f|=Mt),new Nt(a,f,d)}r+=l-c}return n?e+r:new Nt(e+r,0,null)}touches(e,t){let n=0,r=Dt(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;te)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;nn&&t