| 12345678910111213 |
- import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,O as n,T as r,a as i,w as a}from"./client-p9vNUtaN.js";import{n as o}from"./QueryClientProvider-B5zKGR0V.js";import{t as s}from"./useQuery-CDVFCu1z.js";import{t as c}from"./useMutation-BSJ5aGSN.js";import{t as l}from"./arrow-right-CLqCre6h.js";import{t as u}from"./arrow-up-C169xoJg.js";import{t as d}from"./check-dKiEVzKd.js";import{a as f,i as p,r as m}from"./info-Ddwe8b0j.js";import{n as h}from"./ToastContext-BMyWPryU.js";import{t as g}from"./copy-DzLcuv9M.js";import{t as _}from"./droplet-DuTViY9f.js";import{t as v}from"./eye-off-CLSafL7x.js";import{t as y}from"./funnel-Bha54I1I.js";import{t as b}from"./gauge-mynwuflO.js";import{t as x}from"./git-compare-GJZ_CJPj.js";import{t as S}from"./hard-drive-BNVWjQ_2.js";import{t as C}from"./list-zt387K9_.js";import{t as w}from"./loader-circle-mjS43L3L.js";import{t as T}from"./log-in-D3jOyFNw.js";import{t as E}from"./minus-Bl8qpn5p.js";import{t as D}from"./search-Cb5r-jZF.js";import{t as ee}from"./settings-2-DCW-ompJ.js";import{t as O}from"./sparkles-C7LYVlSs.js";import{t as k}from"./sticky-note-BA6JzxrM.js";import{t as A}from"./triangle-alert-US3vrQEH.js";import{t as j}from"./x-PZGhdu27.js";import{n as te}from"./AuthContext-BfmcZb9G.js";import{n as M,t as N}from"./Card-DgaxYs1A.js";import{t as P}from"./Button-B7HH19dk.js";import{u as F}from"./date-G9KUauqz.js";import{$t as I,Dn as ne,Ft as L,Gt as R,Ht as re,Jt as z,Mn as B,Nn as V,On as H,Ot as ie,Pt as U,Ut as ae,Zt as oe,in as W,jn as se,kn as ce,mn as le,nn as ue,pn as de,un as G}from"./index-DqEJjsTn.js";import{p as K,u as q}from"./utils-C1gbXcPr.js";import{t as fe}from"./useCancellableTimeout-Cvzy_uAL.js";var J=t(`equal`,[[`line`,{x1:`5`,x2:`19`,y1:`9`,y2:`9`,key:`1nwqeh`}],[`line`,{x1:`5`,x2:`19`,y1:`15`,y2:`15`,key:`g8yjpy`}]]),pe=t(`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``}}function ye(e){return e.confirmed===!1}function be(e,t){return ye(e)?{key:`kProfiles.toast.writeUnconfirmed`,type:`warning`}:{key:t,type:`success`}}var Z=a(),xe=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),Se=`HS00`,Q=`HH00`,$=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:Se},Ce=e=>$(e)===Q?`HF`:`S`,we=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 Te({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=Ce(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)(ae,{className:`w-4 h-4 text-bambu-green`}):(0,Z.jsx)(re,{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:xe(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)(k,{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 Ee({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:a=[],builtinFilaments:o=[],filamentPresets:s=[],isDualNozzle:l=!1,supportsFlowType:u=!0,initialNote:d=``,initialNoteKey:f=null,onClose:p,onSave:m,onSaveNote:g,hasPermission:_}){let{t:v}=r(),{showToast:y}=h(),[x,S]=(0,Y.useState)(e?.name||``),[C,T]=(0,Y.useState)(e?.k_value?xe(e.k_value):`0.020`),[E,ee]=(0,Y.useState)(e?.filament_id||``),[O,k]=(0,Y.useState)(e?$(e.nozzle_id):Se),[A,te]=(0,Y.useState)(e?.nozzle_diameter||n),[F,I]=(0,Y.useState)(e?[e.extruder_id]:l?[0,1]:[0]),[ne,R]=(0,Y.useState)(!1),[re,z]=(0,Y.useState)({current:0,total:0}),[B,V]=(0,Y.useState)(d),[H,ie]=(0,Y.useState)(``),{schedule:U}=fe(),ae=Y.useMemo(()=>e?.filament_id?o.find(t=>t.filament_id===e.filament_id)?.name||we(a.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,a,o]),oe=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=H.trim().toLowerCase(),n=t?s.filter(e=>e.name.toLowerCase().includes(t)):s;return e.map(([e,t])=>({source:e,label:t,items:n.filter(t=>t.source===e)})).filter(e=>e.items.length>0)},[s,H,v]),W=c({mutationFn:e=>(console.log(`[KProfile] Calling API...`),i.setKProfile(t,e)),onSuccess:(t,n)=>{console.log(`[KProfile] Save success:`,t);let r=be(t,`kProfiles.toast.profileSaved`);if(y(v(r.key),r.type),g&&B!==d){let t;t=B===``&&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,B)}R(!0),U(()=>{R(!1),m()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),y(e.message,`error`),R(!1)}}),se=c({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),i.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e);let t=be(e,`kProfiles.toast.profileDeleted`);y(v(t.key),t.type),R(!0),U(()=>{R(!1),p()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),y(e.message,`error`),R(!1)}}),[ce,le]=(0,Y.useState)(!1),ue=()=>{e&&se.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)(N,{className:`w-full max-w-md relative`,children:[ne&&(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:re.total>1?v(`kProfiles.modal.savingExtruder`,{current:re.current,total:re.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)(M,{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:ne,children:(0,Z.jsx)(j,{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 r=parseFloat(C).toFixed(6),a=`${O}-${A}`,o=e&&e.nozzle_id||a,c=e?e.nozzle_diameter:A,u=e?.filament_id||``;if(!e){let e=s.find(e=>e.id===E);if(!e){y(v(`kProfiles.toast.selectFilament`),`error`);return}if(u=await ve(e,i.getCloudSettingDetail),!u){y(v(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||F.length===1){let t={name:x,k_value:r,filament_id:u,nozzle_id:o,nozzle_diameter:c,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),W.mutate(t);return}R(!0),z({current:1,total:F.length});let d=F.map(e=>({name:x,k_value:r,filament_id:u,nozzle_id:a,nozzle_diameter:A,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${d.length} profiles in batch:`,d);try{let e=be(await i.setKProfilesBatch(t,d),`kProfiles.toast.profilesSaved`);y(v(e.key,{count:F.length}),e.type),g&&B&&g(`name_${x}_${u}`,B)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),y(v(`kProfiles.toast.failedToSaveBatch`),`error`),R(!1),z({current:0,total:0});return}z({current:F.length,total:F.length}),U(()=>{R(!1),z({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:ae||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)(D,{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:H,onChange:e=>ie(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:oe.length===0?(0,Z.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:s.length===0?v(`kProfiles.modal.noFilamentsHelp`):v(`kProfiles.modal.noFilamentMatches`)}):oe.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:()=>{ee(e.id),x||S(`${O===Q?`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:O,onChange:t=>{let n=t.target.value;if(k(n),!e&&E&&!x){let e=s.find(e=>e.id===E);e&&S(`${n===Q?`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:Q,children:v(`kProfiles.modal.highFlow`)}),(0,Z.jsx)(`option`,{value:Se,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:A,onChange:e=>te(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?I([...F,1]):I(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?I([...F,0]):I(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:B,onChange:e=>V(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)(P,{type:`button`,variant:`secondary`,onClick:()=>le(!0),disabled:se.isPending||ne||!_(`kprofiles:delete`),title:_(`kprofiles:delete`)?void 0:v(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:se.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(L,{className:`w-4 h-4`})}),(0,Z.jsx)(P,{type:`button`,variant:`secondary`,onClick:p,disabled:ne,className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(P,{type:`submit`,disabled:W.isPending||ne||!_(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:[W.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)(N,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(M,{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)(L,{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)(P,{variant:`secondary`,onClick:()=>le(!1),className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(P,{onClick:()=>{le(!1),ue()},disabled:se.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[se.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(L,{className:`w-4 h-4`}),v(`common.delete`)]})]})]})})})]})}var De={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function Oe(){let{t:e}=r(),{showToast:t}=h(),{hasPermission:n}=te(),[a,o]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(()=>localStorage.getItem(De.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,ee]=(0,Y.useState)(()=>localStorage.getItem(De.SORT_OPTION)||`name`),[O,k]=(0,Y.useState)(!1),[A,F]=(0,Y.useState)(new Set),[ne,R]=(0,Y.useState)(!1),[re,z]=(0,Y.useState)(!1),B=(0,Y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,Y.useEffect)(()=>{localStorage.setItem(De.NOZZLE_DIAMETER,c)},[c]),(0,Y.useEffect)(()=>{localStorage.setItem(De.SORT_OPTION,E)},[E]);let{data:V,isLoading:H}=s({queryKey:[`printers`],queryFn:i.getPrinters}),{data:W,isLoading:se,isFetching:le,error:de,refetch:G}=s({queryKey:[`kprofiles`,a,c],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,a,`nozzle`,c);let e=await i.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}=s({queryKey:[`builtinFilaments`],queryFn:()=>i.getBuiltinFilaments(),staleTime:3e5}),{data:q}=s({queryKey:[`filamentIdMap`],queryFn:()=>i.getFilamentIdMap(),staleTime:3e5}),{data:fe}=s({queryKey:[`localPresets`],queryFn:()=>i.getLocalPresets(),retry:!1}),{data:J}=s({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>i.orcaCloudListProfiles(),retry:!1}),{data:pe}=s({queryKey:[`cloudSettings`],queryFn:()=>i.getCloudSettings(),retry:!1}),{data:X,refetch:me}=s({queryKey:[`kprofile-notes`,a],queryFn:()=>i.getKProfileNotes(a),enabled:!!a,staleTime:3e4}),he=de?.message?.includes(`not connected`);(0,Y.useEffect)(()=>{if(!a&&V&&V.length>0){let e=V.find(e=>e.is_active);e&&o(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]),be=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]),Q=Y.useCallback(e=>ve.get(e.filament_id)||we(e.name),[ve]),$=Y.useMemo(()=>W?.profiles?W.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 Q(e).localeCompare(Q(t));default:return e.name.localeCompare(t.name)}}):[],[W?.profiles,v,x,C,E,Q]),Ce=V?.find(e=>e.id===a),Oe=Ce?.nozzle_count===2,ke=Ce?.supports_nozzle_flow_type??!0;(0,Y.useEffect)(()=>{ke||T(`all`)},[ke]),(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`&&O&&(e.preventDefault(),k(!1),F(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,f,g,O,G]);let Ae=(0,Y.useCallback)(()=>{if(!W?.profiles||W.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:Ce?.name||`Unknown`,nozzle_diameter:c,profiles:W.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_${Ce?.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:W.profiles.length}))},[W?.profiles,Ce,c,t,e]),je=(0,Y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let r=n.target.files?.[0];if(r)try{let n=await r.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0,l=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{let t=await i.setKProfile(a,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${Se}-${c}`,nozzle_diameter:e.nozzle_diameter||c,extruder_id:e.extruder_id??0,slot_id:0});s++,ye(t)&&l++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),l>0&&t(e(`kProfiles.toast.writesUnconfirmed`,{count:l}),`warning`),G()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[a,c,t,G,e]),Me=(0,Y.useCallback)(e=>{F(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Ne=(0,Y.useCallback)(()=>{F(new Set($.map(e=>B(e))))},[$,B]),Pe=(0,Y.useCallback)(()=>{A.size!==0&&R(!0)},[A.size]),Fe=(0,Y.useCallback)(async()=>{let n=$.filter(e=>A.has(B(e)));z(!0);let r=0,o=0;for(let e of n)try{let t=await i.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});r++,ye(t)&&o++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:r})),o>0&&t(e(`kProfiles.toast.writesUnconfirmed`,{count:o}),`warning`),z(!1),R(!1),k(!1),F(new Set),G()},[a,A,$,t,G,B,e]),Ie=(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},[]),Le=(0,Y.useCallback)(async(n,r)=>{if(a)try{await i.setKProfileNote(a,n,r),me()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[a,me,t,e]),Re=(0,Y.useCallback)(e=>{if(!X?.notes)return{note:``,key:null};let t=Ie(e);for(let e of t)if(X.notes[e])return{note:X.notes[e],key:e};return{note:``,key:null}},[X,Ie]),ze=(0,Y.useCallback)(e=>Re(e).note,[Re]);return H?(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)(N,{children:(0,Z.jsxs)(M,{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)(N,{children:(0,Z.jsxs)(M,{className:`py-12 text-center`,children:[(0,Z.jsx)(I,{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:[le&&!se&&(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=>o(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)(P,{variant:`secondary`,onClick:()=>G(),disabled:le||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,Z.jsx)(oe,{className:`w-4 h-4 ${le?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,Z.jsxs)(P,{onClick:()=>p(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,Z.jsx)(ue,{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)(D,{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`})]}),Oe&&(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`)})]})}),ke&&(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=>ee(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)(P,{variant:`secondary`,onClick:Ae,disabled:!W?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,Z.jsx)(ce,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,Z.jsxs)(P,{variant:`secondary`,onClick:je,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,Z.jsx)(U,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,Z.jsx)(`div`,{className:`flex-1`}),O?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(P,{variant:`secondary`,onClick:Ne,children:[(0,Z.jsx)(ae,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,Z.jsxs)(P,{variant:`secondary`,onClick:Pe,disabled:A.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)(L,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,A.size,`)`]}),(0,Z.jsxs)(P,{variant:`secondary`,onClick:()=>{k(!1),F(new Set)},children:[(0,Z.jsx)(j,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,Z.jsxs)(P,{variant:`secondary`,onClick:()=>k(!0),disabled:!$.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,Z.jsx)(ae,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),se?(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)(N,{children:(0,Z.jsxs)(M,{className:`py-12 text-center`,children:[(0,Z.jsx)(ie,{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)(P,{variant:`secondary`,onClick:()=>G(),children:[(0,Z.jsx)(oe,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):$.length>0?Oe?(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:$.filter(e=>e.extruder_id===1).map(e=>(0,Z.jsx)(Te,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:O,isSelected:A.has(B(e)),onToggleSelect:()=>Me(B(e)),note:ze(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:$.filter(e=>e.extruder_id===0).map(e=>(0,Z.jsx)(Te,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:O,isSelected:A.has(B(e)),onToggleSelect:()=>Me(B(e)),note:ze(e)},B(e)))})]})]}):(0,Z.jsx)(`div`,{className:`space-y-1`,children:$.map(e=>(0,Z.jsx)(Te,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:O,isSelected:A.has(B(e)),onToggleSelect:()=>Me(B(e)),note:ze(e)},B(e)))}):v||x!==`all`||C!==`all`?(0,Z.jsx)(N,{children:(0,Z.jsxs)(M,{className:`py-12 text-center`,children:[(0,Z.jsx)(D,{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)(N,{children:(0,Z.jsxs)(M,{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)(P,{onClick:()=>p(!0),children:[(0,Z.jsx)(ue,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),u&&a&&(()=>{let{note:e,key:t}=Re(u);return(0,Z.jsx)(Ee,{profile:u,printerId:a,nozzleDiameter:c,existingProfiles:W?.profiles,builtinFilaments:be,filamentPresets:xe,isDualNozzle:Oe,supportsFlowType:ke,initialNote:e,initialNoteKey:t,onSaveNote:Le,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),d(null),G()},onSave:()=>{d(null),G()}})})(),f&&a&&(0,Z.jsx)(Ee,{printerId:a,nozzleDiameter:c,existingProfiles:W?.profiles,builtinFilaments:be,filamentPresets:xe,isDualNozzle:Oe,supportsFlowType:ke,onSaveNote:Le,hasPermission:n,onClose:()=>{p(!1),G()},onSave:()=>{p(!1),G()}}),g&&a&&(0,Z.jsx)(Ee,{printerId:a,nozzleDiameter:c,existingProfiles:W?.profiles,builtinFilaments:be,filamentPresets:xe,isDualNozzle:Oe,supportsFlowType:ke,onSaveNote:Le,hasPermission:n,profile:{...g,slot_id:0,name:`${g.name} (Copy)`},onClose:()=>{_(null),G()},onSave:()=>{_(null),G()}}),ne&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(N,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(M,{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)(L,{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:A.size})}),(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(P,{variant:`secondary`,onClick:()=>R(!1),disabled:re,className:`flex-1`,children:e(`common.cancel`)}),(0,Z.jsxs)(P,{onClick:Fe,disabled:re,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[re?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(L,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var ke=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],Ae={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 je(e){let t=e.toUpperCase();for(let e of ke)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function Me(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of ke){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 Ne({preset:e,onDelete:t,onExpand:n,isExpanded:i}){let{t:a}=r(),{hasPermission:o}=te(),s=e.filament_type||je(e.name),c=e.filament_vendor||Me(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=Ae[s.toUpperCase()]||null),(0,Z.jsx)(N,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,Z.jsxs)(M,{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)(L,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`button`,{onClick:()=>n(i?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:i?(0,Z.jsx)(p,{className:`w-3.5 h-3.5`}):(0,Z.jsx)(f,{className:`w-3.5 h-3.5`})})]})]}),i&&(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 Pe(){let{t:e}=r(),{hasPermission:t}=te(),n=o(),{showToast:a}=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}=s({queryKey:[`localPresets`],queryFn:()=>i.getLocalPresets()}),C=c({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await i.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let r=0,i=0,o=0;for(let e of t)r+=e.imported,i+=e.skipped,o+=e.errors.length;r>0&&a(e(`profiles.localProfiles.toast.importSuccess`,{count:r})),i>0&&a(e(`profiles.localProfiles.toast.importSkipped`,{count:i}),`warning`),o>0&&a(e(`profiles.localProfiles.toast.importError`,{count:o}),`error`)},onError:e=>{a(e.message,`error`)}}),T=c({mutationFn:e=>i.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),a(e(`profiles.localProfiles.toast.deleted`))}}),E=(0,Y.useCallback)(e=>{!e||e.length===0||C.mutate(e)},[C]),O=(0,Y.useCallback)(e=>{e.preventDefault(),g(!1),E(e.dataTransfer.files)},[E]),k=(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]),A=(0,Y.useMemo)(()=>k(b?.filament||[]),[b?.filament,k]),j=(0,Y.useMemo)(()=>k(b?.printer||[]),[b?.printer,k]),M=(0,Y.useMemo)(()=>k(b?.process||[]),[b?.process,k]),N=A.length+j.length+M.length,F=(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:O,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)(U,{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`)})]})]}),F&&(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(D,{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`})]}),!F&&!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`)})]}),F&&N===0&&!x&&(0,Z.jsxs)(`div`,{className:`text-center py-12`,children:[(0,Z.jsx)(D,{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`)})]}),N>0&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[A.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:[`(`,A.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:A.map(e=>(0,Z.jsx)(Ne,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),M.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(de,{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:[`(`,M.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:M.map(e=>(0,Z.jsx)(Ne,{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)(ee,{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:[`(`,j.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:j.map(e=>(0,Z.jsx)(Ne,{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)(P,{variant:`secondary`,size:`sm`,onClick:()=>y(null),children:e(`profiles.localProfiles.cancel`)}),(0,Z.jsxs)(P,{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)(L,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function Fe(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 Ie({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:Fe(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(``)},O=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,k=e.filament.length+e.printer.length+e.process.length,A=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)(D,{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)(P,{variant:`secondary`,onClick:n,disabled:r,children:[(0,Z.jsx)(oe,{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)(Ge,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:k},{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)(Ge,{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)(Ge,{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)(Ge,{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)(Ge,{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}),O&&(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)(V,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,F(t.toISOString(),`system`,a)]}),(0,Z.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:T.length,total:k})})]}),T.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(de,{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`)}),O&&(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)(Le,{icon:(0,Z.jsx)(_,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:A(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:x}),(0,Z.jsx)(Le,{icon:(0,Z.jsx)(ee,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:A(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:x}),(0,Z.jsx)(Le,{icon:(0,Z.jsx)(I,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:A(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:x})]}),b&&(0,Z.jsx)(ze,{setting:b,onClose:()=>x(null),t:a})]})}function Le({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)(Re,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function Re({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 ze({setting:e,onClose:t,t:n}){let{data:r,isLoading:a,error:o}=s({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>i.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)(j,{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`})}):o?(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:o.message}):r?(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(r.setting,null,2)}):(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function Be(){let{t:e}=r(),t=o(),{showToast:n}=h(),{hasPermission:a}=te(),l=a(`orca_cloud:auth`),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(5e3),[m,g]=(0,Y.useState)(null),{data:_,isLoading:v}=s({queryKey:[`orcaCloudStatus`],queryFn:i.orcaCloudStatus}),y=!!_?.connected,{data:b,isLoading:x,refetch:S,isRefetching:C,error:T,dataUpdatedAt:E}=s({queryKey:[`orcaCloudProfiles`],queryFn:i.orcaCloudListProfiles,enabled:y,retry:!1,staleTime:1e3*60*5}),{data:D=[]}=s({queryKey:[`printers`],queryFn:i.getPrinters,enabled:y}),[ee,O]=(0,Y.useState)();(0,Y.useEffect)(()=>{E&&O(new Date(E))},[E]);let k=()=>{d(null),p(5e3)},A=t=>{t===`access_denied`?g(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&g(e(`profiles.orcaCloud.errors.expired`)),k()},j=c({mutationFn:i.orcaCloudDeviceStart,onSuccess:e=>{g(null),p(Math.max(1,e.interval)*1e3),d(e)},onError:t=>{g(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),M=c({mutationFn:i.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:N,error:F}=s({queryKey:[`orcaCloudDevicePoll`,u?.user_code??`none`],queryFn:i.orcaCloudDevicePoll,enabled:u!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:u===null?!1:f}),I=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{if(!u||!N)return;let r=N.status;if(r===`slow_down`){p(e=>e+5e3);return}r!==`authorization_pending`&&I.current!==r&&(I.current=r,r===`complete`?(k(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.connectedShort`))):A(r))},[N,u]),(0,Y.useEffect)(()=>{u&&F&&(g(e(`profiles.orcaCloud.errors.pollFailed`)),k())},[F,u]),(0,Y.useEffect)(()=>{u&&(I.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)(P,{variant:`secondary`,size:`sm`,onClick:()=>M.mutate(),disabled:M.isPending||!l,title:l?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,Z.jsx)(G,{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)(P,{onClick:()=>S(),children:e(`profiles.orcaCloud.retry`)})]}):b?(0,Z.jsx)(Ie,{settings:b,lastSyncTime:ee,onRefresh:()=>S(),isRefreshing:C,printers:D,t:e}):null:(0,Z.jsx)(Ve,{pairing:u,connectError:m,onConnect:()=>j.mutate(),onCancel:k,isStarting:j.isPending,canManage:l,t:e})]})}function Ve({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,Z.jsx)(N,{children:(0,Z.jsxs)(M,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,Z.jsx)(B,{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)(P,{className:`w-full mb-3`,children:[(0,Z.jsx)(H,{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)(N,{children:(0,Z.jsxs)(M,{className:`p-8 text-center`,children:[(0,Z.jsx)(B,{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)(P,{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 He(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 Ue(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function We({onSuccess:e,t}){let{showToast:n}=h(),[r,a]=(0,Y.useState)(`email`),[o,s]=(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=c({mutationFn:()=>i.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`)}}),D=c({mutationFn:()=>i.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`)}}),ee=c({mutationFn:()=>i.cloudSetToken(p,g),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),O=e=>{e.preventDefault(),r===`email`?E.mutate():r===`code`?D.mutate():r===`token`&&ee.mutate()},k=E.isPending||D.isPending||ee.isPending;return(0,Z.jsx)(N,{className:`max-w-md mx-auto`,children:(0,Z.jsxs)(M,{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)(B,{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&&r!==`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)(R,{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)(le,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,Z.jsxs)(`form`,{onSubmit:O,className:`space-y-4`,children:[r===`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=>s(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`)})]})]})]}),r===`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})]}),r===`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:[r===`code`&&(0,Z.jsx)(P,{type:`button`,variant:`secondary`,onClick:()=>a(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,Z.jsxs)(P,{type:`submit`,disabled:k,className:`flex-1`,children:[k?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(T,{className:`w-4 h-4`}),t(r===`email`?`profiles.login.loginButton`:r===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),r===`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)(le,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),r===`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 Ge({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 Ke(){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 qe({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=He(e.name),l=Ue(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 Je(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`"""
- `+t.map(e=>n+` `+e).join(`
- `)+`
- `+n+`"""`}return JSON.stringify(e)}if(typeof e==`number`||typeof e==`boolean`)return String(e);if(Array.isArray(e))return e.length===0?`[]`:`[
- `+e.map(e=>n+` `+Je(e,t+1)).join(`,
- `)+`
- `+n+`]`;if(typeof e==`object`){let r=Object.entries(e);return r.length===0?`{}`:`{
- `+r.map(([e,r])=>n+` `+JSON.stringify(e)+`: `+Je(r,t+1)).join(`,
- `)+`
- `+n+`}`}return String(e)}function Ye({setting:e,onClose:t,onDeleted:n,onDuplicate:r,onEdit:a,hasPermission:l,t:u}){let{showToast:d}=h(),f=o(),[p,m]=(0,Y.useState)(!1),{data:_,isLoading:v}=s({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>i.getCloudSettingDetail(e.setting_id)}),y=c({mutationFn:()=>i.deleteCloudSetting(e.setting_id),onSuccess:()=>{d(u(`profiles.presets.toast.deleted`)),f.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>d(e.message,`error`)}),b=Ue(e.setting_id),x=He(e.name,_?.setting?.inherits);return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(N,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,Z.jsxs)(M,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(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)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),b&&(0,Z.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full`,children:u(`profiles.presets.editable`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,Z.jsx)(`span`,{className:`capitalize`,children:u(`profiles.presets.types.${e.type}`)}),x.printer&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{children:`•`}),(0,Z.jsx)(`span`,{children:x.printer})]})]})]}),(0,Z.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,Z.jsx)(j,{className:`w-5 h-5`})})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children: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.jsx)(`pre`,{className:`text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full`,children:Je(_)}):(0,Z.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:u(`profiles.presets.failedToLoadDetails`)})}),p?(0,Z.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-700 dark:text-red-400`,children:[(0,Z.jsx)(A,{className:`w-5 h-5`}),(0,Z.jsx)(`span`,{className:`font-medium`,children:u(`profiles.presets.deleteConfirm`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:u(`profiles.presets.deleteWarning`,{name:e.name})}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(P,{variant:`secondary`,onClick:()=>m(!1),disabled:y.isPending,className:`flex-1`,children:u(`common.cancel`)}),(0,Z.jsxs)(P,{variant:`danger`,onClick:()=>y.mutate(),disabled:y.isPending,className:`flex-1`,children:[y.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(L,{className:`w-4 h-4`}),u(`common.delete`)]})]})]}):(0,Z.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(P,{variant:`secondary`,onClick:t,className:`flex-1`,children:u(`common.close`)}),(0,Z.jsxs)(P,{variant:`secondary`,onClick:r,disabled:!l(`cloud:auth`),title:l(`cloud:auth`)?void 0:u(`profiles.presets.noDuplicatePermission`),children:[(0,Z.jsx)(g,{className:`w-4 h-4`}),u(`profiles.presets.duplicate`)]}),b&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(P,{variant:`secondary`,onClick:a,disabled:v||!_||!l(`cloud:auth`),title:l(`cloud:auth`)?void 0:u(`profiles.presets.noEditPermission`),children:[(0,Z.jsx)(W,{className:`w-4 h-4`}),u(`common.edit`)]}),(0,Z.jsx)(P,{variant:`danger`,onClick:()=>m(!0),disabled:!l(`cloud:auth`),title:l(`cloud:auth`)?void 0:u(`profiles.presets.noDeletePermission`),children:(0,Z.jsx)(L,{className:`w-4 h-4`})})]})]})})]})})})}function Xe(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function Ze(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function Qe({onClose:e,onApply:t,t:n}){let{showToast:r}=h(),[i,a]=(0,Y.useState)(Xe),[o,s]=(0,Y.useState)(`all`),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(``),[m,g]=(0,Y.useState)(`{}`),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),C=o===`all`?i:i.filter(e=>e.type===o),w=e=>{a(e),Ze(e)},T=e=>{w(i.filter(t=>t.id!==e)),S(null),r(n(`profiles.templates.toast.deleted`))},E=e=>{l(e.id),d(e.name),p(e.description),g(JSON.stringify(e.settings,null,2)),b(null)},D=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m);w(i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t)),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){b(e.message)}},k=()=>{l(null),d(``),p(``),g(`{}`),b(null)},te=e=>{w(i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t))},F={filament:{label:n(`profiles.presets.types.filament`),icon:_,color:`text-amber-600 dark:text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:ee,color:`text-blue-600 dark:text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:I,color:`text-purple-600 dark:text-purple-400`}},R=x?i.find(e=>e.id===x):null;return(0,Y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(x?S(null):c?k():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[x,c,e]),(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[R&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,Z.jsx)(N,{className:`w-full max-w-md`,children:(0,Z.jsxs)(M,{className:`p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,Z.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,Z.jsx)(A,{className:`w-6 h-6 text-red-600 dark:text-red-400`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,Z.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:R.name})}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(P,{variant:`secondary`,onClick:()=>S(null),className:`flex-1`,children:n(`common.cancel`)}),(0,Z.jsxs)(P,{onClick:()=>T(x),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,Z.jsx)(L,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,Z.jsx)(N,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,Z.jsxs)(M,{className:`p-0 flex flex-col h-full`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between 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)(O,{className:`w-5 h-5 text-amber-600 dark:text-amber-400`}),n(`profiles.templates.title`)]}),(0,Z.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,Z.jsx)(j,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,Z.jsx)(`button`,{onClick:()=>s(e),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:e===`all`?n(`common.all`):F[e].label},e))]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:C.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,Z.jsx)(O,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,Z.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,Z.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,Z.jsx)(`div`,{className:`space-y-2`,children:C.map(e=>{let r=F[e.type],i=r.icon;return c===e.id?(0,Z.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,Z.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`profiles.templates.namePlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,Z.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:n(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,Z.jsxs)(`div`,{className:`mb-3`,children:[(0,Z.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,Z.jsx)(`textarea`,{value:m,onChange:e=>{g(e.target.value),b(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${y?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),y&&(0,Z.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:y})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsxs)(P,{size:`sm`,onClick:D,disabled:!u.trim(),children:[(0,Z.jsx)(z,{className:`w-4 h-4`}),`Save`]}),(0,Z.jsx)(P,{size:`sm`,variant:`secondary`,onClick:k,children:`Cancel`})]})]},e.id):(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors`,children:[(0,Z.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded`,children:n(`profiles.templates.fieldsCount`,{count:Object.keys(e.settings).length})}),(0,Z.jsx)(`button`,{onClick:()=>te(e.id),className:`p-1 transition-colors ${e.showInModal?`text-bambu-green hover:text-bambu-green/70`:`text-bambu-gray hover:text-white`}`,title:e.showInModal?n(`profiles.templates.shownInModals`):n(`profiles.templates.hiddenInModals`),children:e.showInModal?(0,Z.jsx)(ne,{className:`w-4 h-4`}):(0,Z.jsx)(v,{className:`w-4 h-4`})}),(0,Z.jsx)(`button`,{onClick:()=>t(e),className:`px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors`,children:n(`profiles.templates.apply`)}),(0,Z.jsx)(`button`,{onClick:()=>E(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,Z.jsx)(W,{className:`w-4 h-4`})}),(0,Z.jsx)(`button`,{onClick:()=>S(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`,title:n(`common.delete`),children:(0,Z.jsx)(L,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function $e({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,Y.useState)(`changes`),[c,u]=(0,Y.useState)(``),d=(0,Y.useMemo)(()=>{let e=new Set([...Object.keys(t),...Object.keys(n)]),r=[];for(let i of e){if(i===`inherits`||i===`version`)continue;let e=t[i],a=n[i],o=i in t,s=i in n,c;c=!o&&s?`added`:o&&!s?`removed`:JSON.stringify(e)===JSON.stringify(a)?`same`:`changed`,r.push({key:i,left:e,right:a,status:c})}return r.sort((e,t)=>{let n={changed:0,added:1,removed:2,same:3};return n[e.status]===n[t.status]?e.key.localeCompare(t.key):n[e.status]-n[t.status]})},[t,n]),f=(0,Y.useMemo)(()=>{let e=[...d];if(o===`changes`&&(e=e.filter(e=>e.status!==`same`)),c){let t=c.toLowerCase();e=e.filter(e=>e.key.toLowerCase().includes(t)||String(e.left).toLowerCase().includes(t)||String(e.right).toLowerCase().includes(t))}return e},[d,o,c]),p=(0,Y.useMemo)(()=>({added:d.filter(e=>e.status===`added`).length,removed:d.filter(e=>e.status===`removed`).length,changed:d.filter(e=>e.status===`changed`).length,same:d.filter(e=>e.status===`same`).length}),[d]),m=e=>{if(e===void 0)return`—`;if(e===null)return`null`;if(Array.isArray(e))return e.length===0?`[]`:e.length===1?String(e[0]):e.join(`, `);if(typeof e==`object`)return JSON.stringify(e);let t=String(e);if(t.includes(`\\n`)||t.length>100){let e=t.split(`\\n`).length;if(e>1)return`[${e} lines of G-code/script]`;if(t.length>100)return t.substring(0,100)+`…`}return t};return(0,Y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(N,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,Z.jsxs)(M,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between 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)(x,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),a(`profiles.diff.title`)]}),(0,Z.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,Z.jsx)(j,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark`,children:[(0,Z.jsxs)(`div`,{className:`text-center`,children:[(0,Z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,Z.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,Z.jsxs)(`div`,{className:`text-center`,children:[(0,Z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,Z.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,Z.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,Z.jsx)(ue,{className:`w-3.5 h-3.5`}),p.added,` `,a(`profiles.diff.added`)]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,Z.jsx)(E,{className:`w-3.5 h-3.5`}),p.removed,` `,a(`profiles.diff.removed`)]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-700 dark:text-amber-400`,children:[(0,Z.jsx)(l,{className:`w-3.5 h-3.5`}),p.changed,` `,a(`profiles.diff.changed`)]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,Z.jsx)(J,{className:`w-3.5 h-3.5`}),p.same,` `,a(`profiles.diff.same`)]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(D,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:c,onChange:e=>u(e.target.value),placeholder:a(`profiles.diff.searchFields`),className:`pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48`})]}),p.same>0&&(0,Z.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`button`,{onClick:()=>s(`changes`),className:`px-3 py-1.5 text-sm transition-colors ${o===`changes`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`profiles.diff.changes`)}),(0,Z.jsx)(`button`,{onClick:()=>s(`all`),className:`px-3 py-1.5 text-sm transition-colors ${o===`all`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`common.all`)})]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:f.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,Z.jsx)(J,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,Z.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,Z.jsxs)(`table`,{className:`w-full`,children:[(0,Z.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,Z.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,Z.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,Z.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,Z.jsx)(`tbody`,{children:f.map(e=>{let t={added:`bg-green-500/10`,removed:`bg-red-500/10`,changed:`bg-amber-500/10`,same:``}[e.status],n={added:(0,Z.jsx)(ue,{className:`w-3.5 h-3.5 text-green-600 dark:text-green-400`}),removed:(0,Z.jsx)(E,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400`}),changed:(0,Z.jsx)(l,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),same:(0,Z.jsx)(J,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,Z.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,Z.jsx)(`td`,{className:`p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,Z.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,Z.jsx)(`td`,{className:`p-3`,children:(0,Z.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`removed`?`text-red-700 dark:text-red-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:m(e.left)})}),(0,Z.jsx)(`td`,{className:`p-3`,children:(0,Z.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`added`?`text-green-700 dark:text-green-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:m(e.right)})})]},e.key)})})]})})]})})})}function et({onClose:e,initialData:t,allPresets:n,t:r}){let{showToast:a}=h(),l=o(),u=!!t?.setting_id,[f,p]=(0,Y.useState)(`common`),[g,_]=(0,Y.useState)(t?.type||`filament`),[y,b]=(0,Y.useState)(t?.name?u?t.name:`${t.name} (Copy)`:``),[S,T]=(0,Y.useState)(t?.base_id||``),[E,ee]=(0,Y.useState)(``),[k,A]=(0,Y.useState)(t?.setting||{inherits:``}),[te,F]=(0,Y.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[I,L]=(0,Y.useState)(null),[R,re]=(0,Y.useState)(``),[B,V]=(0,Y.useState)(!1),[H,ie]=(0,Y.useState)(``),[ae,oe]=(0,Y.useState)(!1),[W,le]=(0,Y.useState)(Xe),[de,G]=(0,Y.useState)(!1),[K,q]=(0,Y.useState)(``),[fe,J]=(0,Y.useState)(``),[X,me]=(0,Y.useState)(!0),[he,ge]=(0,Y.useState)(null),[_e,ve]=(0,Y.useState)(!1),ye=(0,Y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[g]||[],[n,g]),be=(0,Y.useMemo)(()=>ye.filter(e=>Ue(e.setting_id)),[ye]),{data:xe}=s({queryKey:[`cloudFields`,g],queryFn:()=>i.getCloudFields(g===`print`?`process`:g),staleTime:1e3*60*60}),{data:Se}=s({queryKey:[`allPresetDetails`,g,be.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t<be.length;t+=5){let n=be.slice(t,t+5);(await Promise.all(n.map(async e=>{try{let t=await i.getCloudSettingDetail(e.setting_id);return{id:e.setting_id,detail:t}}catch{return null}}))).forEach(t=>{t&&(e[t.id]=t.detail)})}return e},enabled:be.length>0,staleTime:1e3*60*10}),{data:Q,isLoading:$}=s({queryKey:[`cloudSettingDetail`,S],queryFn:()=>i.getCloudSettingDetail(S),enabled:!!S});(0,Y.useEffect)(()=>{f!==`json`&&F(JSON.stringify(k,null,2))},[k,f]);let Ce=(0,Y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[g]||[]).filter(e=>!Ue(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,g]);(0,Y.useEffect)(()=>{if(!S)return;let e=Ce.find(e=>e.setting_id===S);e&&(ee(e.name),u||(A({inherits:e.name}),F(JSON.stringify({inherits:e.name},null,2))))},[S,Ce,u]);let we=(0,Y.useMemo)(()=>{let e=xe?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,i=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);Se&&Object.values(Se).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)})}),Object.keys(k).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)});let a=Array.from(n).sort().map(e=>({key:e,label:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),type:`text`,category:`discovered`,description:r(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[xe,Se,k,r]),Te=we.filter(e=>e.label.toLowerCase().includes(R.toLowerCase())||e.key.toLowerCase().includes(R.toLowerCase())),Ee=()=>{if(H.trim()){let e=H.trim().toLowerCase().replace(/\s+/g,`_`);De(e,``),ie(``),oe(!1),a(r(`profiles.presets.toast.fieldAdded`,{key:e}))}},De=(e,t)=>{A(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},Oe=e=>{A(t=>({...t,...e.settings})),ge(e.name),a(r(`profiles.templates.toast.applied`))},ke=()=>{if(!K.trim())return;let e={...k};if(delete e.inherits,Object.keys(e).length===0){a(r(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:K.trim(),description:fe.trim()||r(`profiles.presets.customTemplate`),type:g,settings:e,showInModal:X},n=[...W,t];le(n),Ze(n),G(!1),q(``),J(``),me(!0),a(r(`profiles.templates.toast.created`))},Ae=(0,Y.useMemo)(()=>W.filter(e=>e.type===g&&e.showInModal),[g,W]),je=e=>{F(e);try{A(JSON.parse(e)),L(null)}catch(e){L(e.message)}},Me=e=>{e.preventDefault(),V(!1);let t=e.dataTransfer.files[0];if(t&&t.name.endsWith(`.json`)){let e=new FileReader;e.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),i=n.setting||n;A(e=>({...e,...i})),F(JSON.stringify({...k,...i},null,2)),a(r(`profiles.presets.fileImported`))}catch{a(r(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},Ne=c({mutationFn:()=>{let e={...k},t=g===`filament`?`filament_settings_id`:g===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${y}"`;let n={type:g,name:y,base_id:S,setting:e};return i.createCloudSetting(n)},onSuccess:async()=>{a(r(`profiles.presets.toast.created`)),await l.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>a(e.message,`error`)}),Pe=c({mutationFn:()=>{if(!t?.setting_id)throw Error(r(`profiles.presets.noSettingId`));return i.updateCloudSetting(t.setting_id,{name:y,setting:k})},onSuccess:async()=>{a(r(`profiles.presets.toast.updated`)),l.removeQueries({queryKey:[`cloudSettingDetail`]}),await l.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>a(e.message,`error`)}),Fe=u?Pe:Ne,Ie=Q?.setting?.inherits,Le=Ie?Ce.find(e=>e.name===Ie):void 0,{data:Re}=s({queryKey:[`cloudSettingDetail`,Le?.setting_id],queryFn:()=>i.getCloudSettingDetail(Le.setting_id),enabled:!!Le?.setting_id}),ze=(0,Y.useMemo)(()=>{let e=Re?.setting||{},t=Q?.setting||{},n=S&&Se?.[S]?.setting?Se[S].setting:{};return{...e,...t,...n}},[S,Q,Re,Se]),Be=e=>{if(e==null)return``;if(Array.isArray(e)){let t=[...new Set(e.map(e=>String(e)))];return t.length===1?t[0]:e.join(`, `)}return String(e)},Ve=e=>{let t=k[e.key],n=ze[e.key],i=Be(n),a=$?r(`common.loading`):i||``,o=`w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`;if(e.type===`boolean`){let r=t===`1`||t===void 0&&n===`1`;return(0,Z.jsx)(`button`,{type:`button`,onClick:()=>De(e.key,t===`1`?`0`:`1`),className:`w-8 h-5 rounded-full transition-colors ${r?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,Z.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${r?`translate-x-3.5`:`translate-x-0.5`}`})})}return e.type===`select`?(0,Z.jsxs)(`select`,{value:t||``,onChange:t=>De(e.key,t.target.value),className:o,children:[(0,Z.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:t===void 0?``:String(t),onChange:t=>De(e.key,t.target.value),step:e.step,min:e.min,max:e.max,placeholder:a,className:o}),e.unit&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},He=(0,Y.useMemo)(()=>Q?.setting?Q.setting:{},[Q]);return(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),V(!0)},onDragLeave:()=>V(!1),onDrop:Me,children:[_e&&S&&(0,Z.jsx)($e,{onClose:()=>ve(!1),leftPreset:He,rightPreset:k,leftLabel:r(`profiles.presets.baseLabel`,{name:E||S}),rightLabel:r(`profiles.presets.currentLabel`,{name:y||r(`profiles.presets.newPreset`)}),t:r}),(0,Z.jsx)(N,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,Z.jsxs)(M,{className:`p-0 flex flex-col h-full`,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-xl font-semibold text-white`,children:r(u?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`profiles.presets.customizeSettings`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[S&&(0,Z.jsxs)(`button`,{onClick:()=>ve(!0),className:`flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:r(`profiles.presets.compareWithBase`),children:[(0,Z.jsx)(x,{className:`w-4 h-4`}),r(`profiles.presets.compare`)]}),(0,Z.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,Z.jsx)(j,{className:`w-5 h-5`})})]})]}),B&&(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10`,children:(0,Z.jsxs)(`div`,{className:`text-center`,children:[(0,Z.jsx)(U,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,Z.jsx)(`p`,{className:`text-bambu-green font-medium`,children:r(`profiles.presets.dropJsonToImport`)})]})}),(0,Z.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`common.type`)}),(0,Z.jsxs)(`select`,{value:g,onChange:e=>{_(e.target.value),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,Z.jsx)(`option`,{value:`filament`,children:r(`profiles.presets.types.filament`)}),(0,Z.jsx)(`option`,{value:`print`,children:r(`profiles.presets.types.process`)}),(0,Z.jsx)(`option`,{value:`printer`,children:r(`profiles.presets.types.printer`)})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.basePreset`)}),(0,Z.jsxs)(`select`,{value:S,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 text-sm focus:border-bambu-green focus:outline-none`,children:[(0,Z.jsx)(`option`,{value:``,children:r(`profiles.presets.selectBasePreset`)}),Ce.map(e=>(0,Z.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.presetName`)}),(0,Z.jsx)(`input`,{type:`text`,value:y,onChange:e=>b(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`,placeholder:r(`profiles.presets.myCustomPreset`)})]})]}),E&&(0,Z.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,Z.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(d,{className:`w-3 h-3 text-bambu-green`}),r(`profiles.presets.inheritsFrom`),` `,(0,Z.jsx)(`span`,{className:`text-white`,children:E}),$&&(0,Z.jsx)(w,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,Z.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,Z.jsxs)(`button`,{onClick:()=>p(`common`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${f===`common`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,Z.jsx)(pe,{className:`w-4 h-4`}),r(`profiles.presets.tabs.common`)]}),(0,Z.jsxs)(`button`,{onClick:()=>p(`fields`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${f===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,Z.jsx)(C,{className:`w-4 h-4`}),r(`profiles.presets.tabs.allFields`)]}),(0,Z.jsxs)(`button`,{onClick:()=>p(`json`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${f===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,Z.jsx)(se,{className:`w-4 h-4`}),`JSON`,I&&(0,Z.jsx)(m,{className:`w-3 h-3 text-red-600 dark:text-red-400`})]}),(0,Z.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,Z.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:y,type:g,base_id:S,setting:k},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${y||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),a(r(`profiles.presets.toast.exported`))},className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.exportToJson`),children:[(0,Z.jsx)(ce,{className:`w-4 h-4`}),r(`common.download`)]}),(0,Z.jsxs)(`button`,{onClick:()=>document.getElementById(`file-import`)?.click(),className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.importFromJson`),children:[(0,Z.jsx)(U,{className:`w-4 h-4`}),r(`common.upload`)]}),(0,Z.jsx)(`input`,{id:`file-import`,type:`file`,accept:`.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result),n=t.setting||t;A(e=>({...e,...n})),a(r(`profiles.presets.fileImported`))}catch{a(r(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,Z.jsxs)(`div`,{className:`flex-1 p-4`,children:[f===`common`&&(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,Z.jsx)(O,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),r(`profiles.templates.title`)]}),Object.keys(k).filter(e=>e!==`inherits`).length>0&&(0,Z.jsxs)(`button`,{onClick:()=>G(!de),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,Z.jsx)(z,{className:`w-3 h-3`}),r(`profiles.presets.saveAsTemplate`)]})]}),de&&(0,Z.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,Z.jsx)(`input`,{type:`text`,value:K,onChange:e=>q(e.target.value),placeholder:r(`profiles.templates.namePlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,Z.jsx)(`input`,{type:`text`,value:fe,onChange:e=>J(e.target.value),placeholder:r(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsxs)(P,{size:`sm`,onClick:ke,disabled:!K.trim(),children:[(0,Z.jsx)(z,{className:`w-3 h-3`}),r(`common.save`)]}),(0,Z.jsx)(P,{size:`sm`,variant:`secondary`,onClick:()=>G(!1),children:r(`common.cancel`)})]}),(0,Z.jsxs)(`button`,{onClick:()=>me(!X),className:`flex items-center gap-1.5 text-xs transition-colors ${X?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[X?(0,Z.jsx)(ne,{className:`w-3.5 h-3.5`}):(0,Z.jsx)(v,{className:`w-3.5 h-3.5`}),r(X?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),he&&(0,Z.jsxs)(`div`,{className:`mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2`,children:[(0,Z.jsx)(d,{className:`w-4 h-4 text-bambu-green`}),(0,Z.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[r(`profiles.presets.templateApplied`),` `,(0,Z.jsx)(`span`,{className:`font-medium`,children:he})]}),(0,Z.jsx)(`button`,{onClick:()=>ge(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,Z.jsx)(j,{className:`w-4 h-4`})})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[Ae.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>Oe(e),className:`p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),Ae.length===0&&(0,Z.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:r(`profiles.presets.noTemplatesSelected`)})]}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:r(`profiles.presets.manageTemplatesHint`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.commonSettings`)}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:we.slice(0,10).map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,Z.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,Z.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:Ve(e)})]},e.key))})]}),Object.keys(k).length>1&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.currentOverrides`)}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(k).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded`,children:[e,`: `,String(t).slice(0,20),(0,Z.jsx)(`button`,{onClick:()=>De(e,void 0),className:`hover:text-white`,children:(0,Z.jsx)(j,{className:`w-3 h-3`})})]},e))})]})]}),f===`fields`&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,Z.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.availableFields`)}),(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:Se?r(`profiles.templates.fieldsCount`,{count:we.length}):r(`common.loading`)})]}),(0,Z.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,Z.jsx)(D,{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:R,onChange:e=>re(e.target.value),placeholder:r(`profiles.presets.searchFieldsPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[Te.filter(e=>!(e.key in k)).map(e=>{let t=ze[e.key],n=Be(t);return(0,Z.jsxs)(`div`,{onClick:()=>{A(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate`,title:n,children:[n.slice(0,20),n.length>20?`...`:``]}),(0,Z.jsx)(`div`,{className:`w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors`,children:(0,Z.jsx)(ue,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),Te.filter(e=>!(e.key in k)).length===0&&(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:r(R?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,Z.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:ae?(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`input`,{type:`text`,value:H,onChange:e=>ie(e.target.value),onKeyDown:e=>e.key===`Enter`&&Ee(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,Z.jsx)(P,{size:`sm`,onClick:Ee,disabled:!H.trim(),children:(0,Z.jsx)(ue,{className:`w-4 h-4`})}),(0,Z.jsx)(P,{size:`sm`,variant:`secondary`,onClick:()=>{oe(!1),ie(``)},children:(0,Z.jsx)(j,{className:`w-4 h-4`})})]}):(0,Z.jsxs)(`button`,{onClick:()=>oe(!0),className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,Z.jsx)(ue,{className:`w-4 h-4`}),r(`profiles.presets.addCustomField`)]})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.yourOverrides`)}),(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`profiles.templates.fieldsCount`,{count:Object.keys(k).filter(e=>e!==`inherits`).length})})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(k).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=we.find(t=>t.key===e);return(0,Z.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,Z.jsx)(`button`,{onClick:()=>De(e,void 0),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,children:(0,Z.jsx)(j,{className:`w-4 h-4`})})]}),n?Ve(n):(0,Z.jsx)(`input`,{type:`text`,value:String(t),onChange:t=>De(e,t.target.value),className:`w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]},e)}),Object.keys(k).filter(e=>e!==`inherits`).length===0&&(0,Z.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,Z.jsx)(pe,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:r(`profiles.presets.noOverridesYet`)}),(0,Z.jsx)(`p`,{className:`text-xs mt-1`,children:r(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(k).filter(e=>e!==`inherits`).length>0&&(0,Z.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,Z.jsxs)(`button`,{onClick:()=>{G(!0),p(`common`)},className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,Z.jsx)(z,{className:`w-4 h-4`}),r(`profiles.presets.saveAsTemplate`)]})})]})]}),f===`json`&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[I&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,Z.jsx)(m,{className:`w-4 h-4`}),I]}),(0,Z.jsx)(`textarea`,{value:te,onChange:e=>je(e.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${I?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`profiles.presets.jsonTip`)})]})]}),(0,Z.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,Z.jsx)(P,{variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,Z.jsxs)(P,{onClick:()=>Fe.mutate(),disabled:Fe.isPending||!y.trim()||!u&&!S||!!I,className:`flex-1`,children:[Fe.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):u?(0,Z.jsx)(z,{className:`w-4 h-4`}):(0,Z.jsx)(ue,{className:`w-4 h-4`}),r(u?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function tt({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:a,hasPermission:s,t:c}){let[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(`all`),[m,h]=(0,Y.useState)(`all`),[g,v]=(0,Y.useState)(`all`),[b,S]=(0,Y.useState)(`all`),[C,w]=(0,Y.useState)(`all`),[T,E]=(0,Y.useState)(`all`),[k,A]=(0,Y.useState)(null),[j,te]=(0,Y.useState)(!1),[M,N]=(0,Y.useState)(!1),[ne,L]=(0,Y.useState)(null),[R,re]=(0,Y.useState)(null),[z,B]=(0,Y.useState)(null),[H,ie]=(0,Y.useState)(!1),[U,ae]=(0,Y.useState)([null,null]),[W,se]=(0,Y.useState)(!1),[ce,le]=(0,Y.useState)(null),G=o(),K=(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:He(e.name)})),[e]),q=(0,Y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return K.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:a.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))}},[K,a]),fe=(0,Y.useMemo)(()=>g===`all`?null:a.find(e=>e.id.toString()===g)?.model||null,[g,a]),J=(0,Y.useMemo)(()=>K.filter(e=>f===`all`||e.type===f).filter(e=>{if(m===`all`)return!0;let t=Ue(e.setting_id);return m===`custom`?t:!t}).filter(e=>{if(g===`all`||!fe)return!0;let t=e.meta.printer?.toLowerCase()||``,n=fe.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>b===`all`||e.meta.nozzle===b).filter(e=>C===`all`||e.meta.filamentType===C).filter(e=>T===`all`||e.meta.layerHeight===T).filter(e=>u===``||e.name.toLowerCase().includes(u.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[K,f,m,g,fe,b,C,T,u]),pe=e=>{if(H){let t=U[0]?.setting_id===e.setting_id,n=U[1]?.setting_id===e.setting_id;if(t)ae([U[1],null]);else if(n)ae([U[0],null]);else if(!U[0])ae([e,null]);else if(U[1]){if(U[0].type!==e.type)return;ae([U[0],e])}else{if(U[0].type!==e.type)return;ae([U[0],e])}}else A(e)},X=e=>{if(U[0]?.setting_id===e.setting_id)return 0;if(U[1]?.setting_id===e.setting_id)return 1},me=async e=>{try{let t=await i.getCloudSettingDetail(e.setting_id);L({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),A(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},he=async e=>{try{G.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await i.getCloudSettingDetail(e.setting_id);re({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),A(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},ge=()=>{p(`all`),h(`all`),v(`all`),S(`all`),w(`all`),E(`all`),d(``)},_e=f!==`all`||m!==`all`||g!==`all`||b!==`all`||C!==`all`||T!==`all`||u!==``,ve=e.filament.length+e.printer.length+e.process.length;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)(D,{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:u,onChange:e=>d(e.target.value),placeholder:c(`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.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,Z.jsxs)(P,{variant:H?`primary`:`secondary`,onClick:()=>{H?(ie(!1),ae([null,null])):ie(!0)},children:[(0,Z.jsx)(x,{className:`w-4 h-4`}),c(H?`common.cancel`:`profiles.presets.compare`)]}),(0,Z.jsxs)(P,{variant:`secondary`,onClick:()=>N(!0),disabled:!s(`cloud:auth`),title:s(`cloud:auth`)?void 0:c(`profiles.cloudView.noTemplatesPermission`),children:[(0,Z.jsx)(O,{className:`w-4 h-4`}),c(`profiles.cloudView.templates`)]}),(0,Z.jsxs)(P,{variant:`secondary`,onClick:n,disabled:r||!s(`cloud:auth`),title:s(`cloud:auth`)?void 0:c(`profiles.cloudView.noRefreshPermission`),children:[(0,Z.jsx)(oe,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),c(`profiles.cloudView.refresh`)]}),(0,Z.jsxs)(P,{onClick:()=>te(!0),disabled:!s(`cloud:auth`),title:s(`cloud:auth`)?void 0:c(`profiles.cloudView.noCreatePermission`),children:[(0,Z.jsx)(ue,{className:`w-4 h-4`}),c(`profiles.cloudView.newPreset`)]})]})]}),(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)(Ge,{label:c(`profiles.cloudView.filters.type`),value:f,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`),count:ve},{value:`filament`,label:c(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:c(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:c(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>p(e)}),(0,Z.jsx)(Ge,{label:c(`profiles.cloudView.filters.owner`),value:m,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},{value:`custom`,label:c(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:c(`profiles.cloudView.filters.builtIn`)}],onChange:e=>h(e)}),q.printers.length>0&&(0,Z.jsx)(Ge,{label:c(`profiles.cloudView.filters.printer`),value:g,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...q.printers.map(e=>({value:e.id,label:e.name}))],onChange:v}),q.nozzles.length>0&&(0,Z.jsx)(Ge,{label:c(`profiles.cloudView.filters.nozzle`),value:b,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...q.nozzles.map(e=>({value:e,label:e}))],onChange:S}),q.filaments.length>0&&(f===`all`||f===`filament`)&&(0,Z.jsx)(Ge,{label:c(`profiles.cloudView.filters.filament`),value:C,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...q.filaments.map(e=>({value:e,label:e}))],onChange:w}),q.layerHeights.length>0&&(f===`all`||f===`process`)&&(0,Z.jsx)(Ge,{label:c(`profiles.cloudView.filters.layer`),value:T,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...q.layerHeights.map(e=>({value:e,label:e}))],onChange:E}),_e&&(0,Z.jsx)(`button`,{onClick:ge,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:c(`profiles.cloudView.clearFilters`)})]})]}),H&&(0,Z.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Z.jsx)(x,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),(0,Z.jsx)(`span`,{className:`text-white font-medium`,children:c(`profiles.cloudView.compareMode`)}),(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:U[0]?c(`profiles.cloudView.selectAnotherPreset`,{type:U[0].type}):c(`profiles.cloudView.clickTwoPresets`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${U[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:U[0]?U[0].name:c(`profiles.cloudView.selectFirst`)}),(0,Z.jsx)(l,{className:`w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${U[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:U[1]?U[1].name:c(`profiles.cloudView.selectSecond`)})]}),U[0]&&U[1]&&(0,Z.jsxs)(P,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([i.getCloudSettingDetail(U[0].setting_id),i.getCloudSettingDetail(U[1].setting_id)]);le([e.setting||{},t.setting||{}]),se(!0)}catch{}},children:[(0,Z.jsx)(x,{className:`w-4 h-4`}),c(`profiles.cloudView.compareNow`)]})]})]})}),(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)(V,{className:`w-3 h-3`}),c(`profiles.cloudView.lastSynced`),` `,F(t.toISOString(),`system`,c)]}),(0,Z.jsx)(`span`,{children:c(`profiles.cloudView.showingCount`,{showing:J.length,total:ve})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,Z.jsxs)(`span`,{children:[`= `,c(`profiles.presets.myPreset`)]})]})]}),J.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(de,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:c(`profiles.cloudView.noPresetsFound`)}),_e&&(0,Z.jsx)(`button`,{onClick:ge,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:c(`profiles.cloudView.clearFilters`)})]}):(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,Z.jsx)(_,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:c(`profiles.cloudView.columns.filament`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,J.filter(e=>e.type===`filament`).length,`)`]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[J.filter(e=>e.type===`filament`).map(e=>(0,Z.jsx)(qe,{setting:e,onClick:()=>pe(e),onDuplicate:()=>me(e),compareMode:H,isCompareSelected:X(e)!==void 0,compareIndex:X(e),compareDisabled:H&&!!U[0]&&U[0].type!==e.type,t:c},e.setting_id)),J.filter(e=>e.type===`filament`).length===0&&(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:c(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,Z.jsx)(ee,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:c(`profiles.cloudView.columns.process`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,J.filter(e=>e.type===`process`).length,`)`]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[J.filter(e=>e.type===`process`).map(e=>(0,Z.jsx)(qe,{setting:e,onClick:()=>pe(e),onDuplicate:()=>me(e),compareMode:H,isCompareSelected:X(e)!==void 0,compareIndex:X(e),compareDisabled:H&&!!U[0]&&U[0].type!==e.type,t:c},e.setting_id)),J.filter(e=>e.type===`process`).length===0&&(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:c(`profiles.cloudView.noProcessPresets`)})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,Z.jsx)(I,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:c(`profiles.cloudView.columns.printer`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,J.filter(e=>e.type===`printer`).length,`)`]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[J.filter(e=>e.type===`printer`).map(e=>(0,Z.jsx)(qe,{setting:e,onClick:()=>pe(e),onDuplicate:()=>me(e),compareMode:H,isCompareSelected:X(e)!==void 0,compareIndex:X(e),compareDisabled:H&&!!U[0]&&U[0].type!==e.type,t:c},e.setting_id)),J.filter(e=>e.type===`printer`).length===0&&(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:c(`profiles.cloudView.noPrinterPresets`)})]})]})]}),k&&(0,Z.jsx)(Ye,{setting:k,onClose:()=>A(null),onDeleted:()=>A(null),onDuplicate:()=>me(k),onEdit:()=>he(k),hasPermission:s,t:c}),(j||ne||R||z)&&(0,Z.jsx)(et,{onClose:()=>{te(!1),L(null),re(null),B(null)},initialData:R||ne||(z?{type:z.type,name:``,base_id:``,setting:z.setting}:void 0),allPresets:e,t:c}),M&&(0,Z.jsx)(Qe,{onClose:()=>N(!1),onApply:e=>{B({type:e.type,setting:e.settings}),N(!1)},t:c}),W&&ce&&U[0]&&U[1]&&(0,Z.jsx)($e,{onClose:()=>{se(!1),le(null)},leftPreset:ce[0],rightPreset:ce[1],leftLabel:U[0].name,rightLabel:U[1].name,t:c})]})}function nt(){let{t:e}=r(),t=o(),{showToast:n}=h(),{hasPermission:a}=te(),[l,u]=(0,Y.useState)(`cloud`),[d,f]=(0,Y.useState)(),{data:p,isLoading:m}=s({queryKey:[`cloudStatus`],queryFn:i.getCloudStatus}),{data:g=[]}=s({queryKey:[`printers`],queryFn:i.getPrinters}),{data:_,isLoading:v,refetch:y,dataUpdatedAt:x}=s({queryKey:[`cloudSettings`],queryFn:()=>i.getCloudSettings(),enabled:!!p?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,Y.useEffect)(()=>{x&&f(new Date(x))},[x]);let C=c({mutationFn:i.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),n(e(`profiles.toast.loggedOut`))}});return m?(0,Z.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,Z.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,Z.jsxs)(`div`,{className:`mb-6`,children:[(0,Z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,Z.jsx)(B,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,Z.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,Z.jsxs)(`button`,{onClick:()=>u(`cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,Z.jsx)(B,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,Z.jsxs)(`button`,{onClick:()=>u(`orca_cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,Z.jsx)(B,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,Z.jsxs)(`button`,{onClick:()=>u(`local`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,Z.jsx)(S,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,Z.jsxs)(`button`,{onClick:()=>u(`kprofiles`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l===`kprofiles`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,Z.jsx)(b,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),l===`cloud`&&(0,Z.jsxs)(Z.Fragment,{children:[p?.is_authenticated&&(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.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,Z.jsx)(`span`,{className:`text-white`,children:p.email}),p.region&&(0,Z.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:p.region===`china`?e(`profiles.login.regionChina`):e(`profiles.login.regionGlobal`)})]})]}),(0,Z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>C.mutate(),disabled:C.isPending||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,Z.jsx)(G,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),p?.sign_in_expired&&(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 p-3 mb-6 rounded-lg border border-yellow-500/40 bg-yellow-500/10`,children:[(0,Z.jsx)(A,{className:`w-5 h-5 shrink-0 text-yellow-400 mt-0.5`}),(0,Z.jsxs)(`div`,{className:`text-sm`,children:[(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:e(`profiles.signInExpiredTitle`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.signInExpiredBody`)})]})]}),p?.is_authenticated?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.jsx)(tt,{settings:_,lastSyncTime:d,onRefresh:()=>y(),isRefreshing:v,printers:g,hasPermission:a,t:e}):(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,Z.jsx)(P,{onClick:()=>y(),children:e(`profiles.retry`)})]}):(0,Z.jsx)(We,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),l===`orca_cloud`&&(0,Z.jsx)(Be,{}),l===`local`&&(0,Z.jsx)(Pe,{}),l===`kprofiles`&&(0,Z.jsx)(Oe,{}),(0,Z.jsx)(Ke,{})]})}export{Ge as FilterDropdown,We as LoginForm,nt as ProfilesPage};
|