| 12345678910111213 |
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{C as t,T as n,a as r,k as i,w as a}from"./client-DWQBE01c.js";import{n as o}from"./QueryClientProvider-CfzZA5MJ.js";import{t as s}from"./useQuery-Q4exvDrv.js";import{t as c}from"./useMutation-D7HomC3_.js";import{t as l}from"./arrow-right-NtE9qQKI.js";import{t as u}from"./arrow-up-DJqP6yLh.js";import{t as d}from"./check-DWMoPMOi.js";import{a as f,i as p,r as m}from"./info-CPhSLaIW.js";import{n as ee}from"./ToastContext-Bg6SLDR7.js";import{t as h}from"./clock-B_D089Yk.js";import{t as g}from"./cloud-Z2CCvbpR.js";import{t as _}from"./code-Bj7WYHpL.js";import{t as v}from"./copy-DYtKLuFp.js";import{t as y}from"./download-8MUb8xIU.js";import{t as b}from"./droplet-LWrt2qYt.js";import{t as x}from"./external-link-Dp7WgKqd.js";import{t as S}from"./eye-off-AM0w079U.js";import{t as C}from"./eye-Dq8Pma0q.js";import{t as w}from"./funnel-wdX6_bRQ.js";import{t as T}from"./gauge-BQzJ7Cia.js";import{t as E}from"./git-compare-BI9BULZv.js";import{t as D}from"./hard-drive-DAXuLIvW.js";import{t as O}from"./key-CD1tqr8p.js";import{t as k}from"./layers-CpeKWrvK.js";import{t as A}from"./list-CdplOArc.js";import{t as j}from"./loader-circle-QIogdiwG.js";import{t as te}from"./log-in-DXPBC4IY.js";import{t as M}from"./log-out-DlmPVuYo.js";import{t as N}from"./minus-RDsBstyV.js";import{t as P}from"./pencil-Bu6jcMuL.js";import{t as F}from"./plus-D5MKJLpO.js";import{t as I}from"./printer-B0-V64ms.js";import{t as ne}from"./refresh-cw-CCtLKWuY.js";import{t as L}from"./save-fARYWQM6.js";import{t as re}from"./search-DLu9V8cG.js";import{t as R}from"./settings-2-BiUbKfTt.js";import{t as ie}from"./shield-alert-DQJtOFpK.js";import{t as z}from"./sparkles-DviWgAPD.js";import{t as ae}from"./square-check-big-CcMeYdVA.js";import{t as oe}from"./square-Cu6PTXpS.js";import{t as B}from"./sticky-note-DaZKs4Hb.js";import{t as V}from"./trash-2-BeUbCuhB.js";import{t as H}from"./triangle-alert-C-5b4OJS.js";import{t as U}from"./upload-DsI4ao2o.js";import{t as se}from"./wifi-off-frtFqK7Y.js";import{t as ce}from"./x-Ros7hs1-.js";import{n as le}from"./AuthContext-dqmb9nDE.js";import{n as W,t as G}from"./Card-DwWt21H0.js";import{t as K}from"./Button-CDViejCk.js";import{u as q}from"./date-G9KUauqz.js";import{p as J,u as Y}from"./utils-BGRMUZaT.js";import{t as ue}from"./useCancellableTimeout-DP6PLygv.js";var X=t(`equal`,[[`line`,{x1:`5`,x2:`19`,y1:`9`,y2:`9`,key:`1nwqeh`}],[`line`,{x1:`5`,x2:`19`,y1:`15`,y2:`15`,key:`g8yjpy`}]]),de=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`}]]),Z=e(i(),1),Q={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 fe(e){let t=(e||``).toUpperCase().trim();return t&&(Q[t]||Q[t.replace(/[-\s]?CF$/,``)]||Q[t.replace(/\+$/,``)]||Q[t.split(/[-\s]/)[0]])||``}function pe(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var me={local:0,orca_cloud:1,cloud:2,builtin:3};function he(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=pe(e.name),n=e.filament_type||Y(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:fe(n),filamentType:n||``})}for(let e of n??[]){let t=pe(e.name),n=Y(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:fe(n),filamentType:n})}for(let e of r??[]){let t=pe(e.name),n=e.setting_id.startsWith(`GFS`)?J(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:Y(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:Y(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):me[e.source]-me[t.source])}async function ge(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 _e(e){return e.confirmed===!1}function ve(e,t){return _e(e)?{key:`kProfiles.toast.writeUnconfirmed`,type:`warning`}:{key:t,type:`success`}}var $=a(),ye=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),be=`HS00`,xe=`HH00`,Se=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:be},Ce=e=>Se(e)===xe?`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,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,$.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,$.jsx)(ae,{className:`w-4 h-4 text-bambu-green`}):(0,$.jsx)(oe,{className:`w-4 h-4`})}),(0,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:ye(e.k_value)}),(0,$.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,$.jsx)(`span`,{title:`Has note`,children:(0,$.jsx)(B,{className:`w-3 h-3 text-yellow-500`})}),(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,$.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,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,$.jsx)(v,{className:`w-4 h-4`})})]})}function Ee({profile:e,printerId:t,nozzleDiameter:i,existingProfiles:a=[],builtinFilaments:o=[],filamentPresets:s=[],isDualNozzle:l=!1,supportsFlowType:u=!0,initialNote:d=``,initialNoteKey:f=null,onClose:p,onSave:m,onSaveNote:h,hasPermission:g}){let{t:_}=n(),{showToast:v}=ee(),[y,b]=(0,Z.useState)(e?.name||``),[x,S]=(0,Z.useState)(e?.k_value?ye(e.k_value):`0.020`),[C,w]=(0,Z.useState)(e?.filament_id||``),[E,D]=(0,Z.useState)(e?Se(e.nozzle_id):be),[O,k]=(0,Z.useState)(e?.nozzle_diameter||i),[A,te]=(0,Z.useState)(e?[e.extruder_id]:l?[0,1]:[0]),[M,N]=(0,Z.useState)(!1),[P,F]=(0,Z.useState)({current:0,total:0}),[I,ne]=(0,Z.useState)(d),[L,R]=(0,Z.useState)(``),{schedule:ie}=ue(),z=Z.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]),ae=Z.useMemo(()=>{let e=[[`local`,_(`kProfiles.modal.source.local`)],[`orca_cloud`,_(`kProfiles.modal.source.orcaCloud`)],[`cloud`,_(`kProfiles.modal.source.bambuCloud`)],[`builtin`,_(`kProfiles.modal.source.builtin`)]],t=L.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,L,_]),oe=c({mutationFn:e=>(console.log(`[KProfile] Calling API...`),r.setKProfile(t,e)),onSuccess:(t,n)=>{console.log(`[KProfile] Save success:`,t);let r=ve(t,`kProfiles.toast.profileSaved`);if(v(_(r.key),r.type),h&&I!==d){let t;t=I===``&&f?f:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${y}_${n.filament_id}`,h(t,I)}N(!0),ie(()=>{N(!1),m()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),v(e.message,`error`),N(!1)}}),B=c({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),r.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e);let t=ve(e,`kProfiles.toast.profileDeleted`);v(_(t.key),t.type),N(!0),ie(()=>{N(!1),p()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),v(e.message,`error`),N(!1)}}),[H,U]=(0,Z.useState)(!1),se=()=>{e&&B.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,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,$.jsxs)(G,{className:`w-full max-w-md relative`,children:[M&&(0,$.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,$.jsx)(`p`,{className:`text-white font-medium`,children:P.total>1?_(`kProfiles.modal.savingExtruder`,{current:P.current,total:P.total}):_(`kProfiles.modal.syncing`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:_(`kProfiles.modal.pleaseWait`)})]}),(0,$.jsxs)(W,{className:`p-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:_(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,$.jsx)(`button`,{onClick:p,className:`text-bambu-gray hover:text-white transition-colors`,disabled:M,children:(0,$.jsx)(ce,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),l&&!e&&A.length===0){v(_(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let i=parseFloat(x).toFixed(6),a=`${E}-${O}`,o=e&&e.nozzle_id||a,c=e?e.nozzle_diameter:O,u=e?.filament_id||``;if(!e){let e=s.find(e=>e.id===C);if(!e){v(_(`kProfiles.toast.selectFilament`),`error`);return}if(u=await ge(e,r.getCloudSettingDetail),!u){v(_(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||A.length===1){let t={name:y,k_value:i,filament_id:u,nozzle_id:o,nozzle_diameter:c,extruder_id:e?e.extruder_id:A[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),oe.mutate(t);return}N(!0),F({current:1,total:A.length});let d=A.map(e=>({name:y,k_value:i,filament_id:u,nozzle_id:a,nozzle_diameter:O,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${d.length} profiles in batch:`,d);try{let e=ve(await r.setKProfilesBatch(t,d),`kProfiles.toast.profilesSaved`);v(_(e.key,{count:A.length}),e.type),h&&I&&h(`name_${y}_${u}`,I)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),v(_(`kProfiles.toast.failedToSaveBatch`),`error`),N(!1),F({current:0,total:0});return}F({current:A.length,total:A.length}),ie(()=>{N(!1),F({current:0,total:0}),m()},3e3)},className:`p-4 space-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(`kProfiles.modal.profileName`)}),(0,$.jsx)(`input`,{type:`text`,value:y,onChange:e=>b(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:_(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(`kProfiles.modal.kValue`)}),(0,$.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:x,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&S(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||S((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:_(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:_(`kProfiles.modal.kValueHelp`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(`kProfiles.modal.filament`)}),e?(0,$.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:z||e.filament_id}):(0,$.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`relative border-b border-bambu-dark-tertiary`,children:[(0,$.jsx)(re,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,value:L,onChange:e=>R(e.target.value),placeholder:_(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:ae.length===0?(0,$.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:s.length===0?_(`kProfiles.modal.noFilamentsHelp`):_(`kProfiles.modal.noFilamentMatches`)}):ae.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.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,$.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-bambu-green`,children:e.label}),(0,$.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:e.items.length})]}),e.items.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>{w(e.id),y||b(`${E===xe?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${C===e.id?`bg-bambu-green/20 text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))]},e.source))})]})]}),(0,$.jsxs)(`div`,{className:u?`grid grid-cols-2 gap-4`:``,children:[(0,$.jsxs)(`div`,{className:u?``:`hidden`,children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(`kProfiles.modal.flowType`)}),(0,$.jsxs)(`select`,{value:E,onChange:t=>{let n=t.target.value;if(D(n),!e&&C&&!y){let e=s.find(e=>e.id===C);e&&b(`${n===xe?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,$.jsx)(`option`,{value:xe,children:_(`kProfiles.modal.highFlow`)}),(0,$.jsx)(`option`,{value:be,children:_(`kProfiles.modal.standard`)})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(`kProfiles.modal.nozzleSize`)}),(0,$.jsxs)(`select`,{value:O,onChange:e=>k(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,$.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,$.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,$.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,$.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),l&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,$.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?_(`kProfiles.modal.left`):_(`kProfiles.modal.right`)}):(0,$.jsxs)(`div`,{className:`flex gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:A.includes(1),onChange:e=>{e.target.checked?te([...A,1]):te(A.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,$.jsx)(`span`,{className:`text-white`,children:_(`kProfiles.modal.left`)})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:A.includes(0),onChange:e=>{e.target.checked?te([...A,0]):te(A.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,$.jsx)(`span`,{className:`text-white`,children:_(`kProfiles.modal.right`)})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(`kProfiles.modal.notes`)}),(0,$.jsx)(`textarea`,{value:I,onChange:e=>ne(e.target.value),placeholder:_(`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,$.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:_(`kProfiles.modal.notesHelp`)})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,$.jsx)(K,{type:`button`,variant:`secondary`,onClick:()=>U(!0),disabled:B.isPending||M||!g(`kprofiles:delete`),title:g(`kprofiles:delete`)?void 0:_(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:B.isPending?(0,$.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(V,{className:`w-4 h-4`})}),(0,$.jsx)(K,{type:`button`,variant:`secondary`,onClick:p,disabled:M,className:`flex-1`,children:_(`common.cancel`)}),(0,$.jsxs)(K,{type:`submit`,disabled:oe.isPending||M||!g(e?`kprofiles:update`:`kprofiles:create`),title:g(e?`kprofiles:update`:`kprofiles:create`)?void 0:_(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[oe.isPending?(0,$.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(T,{className:`w-4 h-4`}),_(`common.save`)]})]})]})]})]}),H&&(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,$.jsx)(G,{className:`w-full max-w-sm`,children:(0,$.jsxs)(W,{className:`p-6`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,$.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,$.jsx)(V,{className:`w-5 h-5 text-red-500`})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:_(`kProfiles.deleteConfirm.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:_(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,$.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:_(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,$.jsxs)(`div`,{className:`flex gap-3`,children:[(0,$.jsx)(K,{variant:`secondary`,onClick:()=>U(!1),className:`flex-1`,children:_(`common.cancel`)}),(0,$.jsxs)(K,{onClick:()=>{U(!1),se()},disabled:B.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[B.isPending?(0,$.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(V,{className:`w-4 h-4`}),_(`common.delete`)]})]})]})})})]})}var De={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function Oe(){let{t:e}=n(),{showToast:t}=ee(),{hasPermission:i}=le(),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(()=>localStorage.getItem(De.NOZZLE_DIAMETER)||`0.4`),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(``),[b,x]=(0,Z.useState)(`all`),[S,C]=(0,Z.useState)(`all`),[w,E]=(0,Z.useState)(()=>localStorage.getItem(De.SORT_OPTION)||`name`),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(new Set),[te,M]=(0,Z.useState)(!1),[N,P]=(0,Z.useState)(!1),L=(0,Z.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,Z.useEffect)(()=>{localStorage.setItem(De.NOZZLE_DIAMETER,c)},[c]),(0,Z.useEffect)(()=>{localStorage.setItem(De.SORT_OPTION,w)},[w]);let{data:R,isLoading:ie}=s({queryKey:[`printers`],queryFn:r.getPrinters}),{data:z,isLoading:oe,isFetching:B,error:H,refetch:q}=s({queryKey:[`kprofiles`,a,c],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,a,`nozzle`,c);let e=await r.getKProfiles(a,c);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!a,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:J}=s({queryKey:[`builtinFilaments`],queryFn:()=>r.getBuiltinFilaments(),staleTime:3e5}),{data:Y}=s({queryKey:[`filamentIdMap`],queryFn:()=>r.getFilamentIdMap(),staleTime:3e5}),{data:ue}=s({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets(),retry:!1}),{data:X}=s({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>r.orcaCloudListProfiles(),retry:!1}),{data:de}=s({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),retry:!1}),{data:Q,refetch:fe}=s({queryKey:[`kprofile-notes`,a],queryFn:()=>r.getKProfileNotes(a),enabled:!!a,staleTime:3e4}),pe=H?.message?.includes(`not connected`);(0,Z.useEffect)(()=>{if(!a&&R&&R.length>0){let e=R.find(e=>e.is_active);e&&o(e.id)}},[a,R]),(0,Z.useEffect)(()=>{if(a){let e=setTimeout(()=>{q()},150);return()=>clearTimeout(e)}},[a,c]);let me=R?.filter(e=>e.is_active)||[],ge=Z.useMemo(()=>{let e=new Map;if(J)for(let t of J)e.set(t.filament_id,t.name);if(Y)for(let[t,n]of Object.entries(Y))e.has(t)||e.set(t,n);return e},[J,Y]),ve=Z.useMemo(()=>Array.from(ge.entries()).map(([e,t])=>({filament_id:e,name:t})),[ge]),ye=Z.useMemo(()=>he({localPresets:ue?.filament,orcaProfiles:X?.filament,cloudSettings:de?.filament,builtinFilaments:J}),[ue?.filament,X?.filament,de?.filament,J]),xe=Z.useCallback(e=>ge.get(e.filament_id)||we(e.name),[ge]),Se=Z.useMemo(()=>z?.profiles?z.profiles.filter(e=>{let t=_.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=b===`all`||b===`left`&&e.extruder_id===1||b===`right`&&e.extruder_id===0,i=S===`all`||S===`hf`&&e.nozzle_id.startsWith(`HH`)||S===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(w){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return xe(e).localeCompare(xe(t));default:return e.name.localeCompare(t.name)}}):[],[z?.profiles,_,b,S,w,xe]),Ce=R?.find(e=>e.id===a),Oe=Ce?.nozzle_count===2,ke=Ce?.supports_nozzle_flow_type??!0;(0,Z.useEffect)(()=>{ke||C(`all`)},[ke]),(0,Z.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||u||f||h||(e.key===`r`||e.key===`R`?(e.preventDefault(),q()):e.key===`n`||e.key===`N`?(e.preventDefault(),p(!0)):e.key===`Escape`&&D&&(e.preventDefault(),O(!1),A(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,f,h,D,q]);let Ae=(0,Z.useCallback)(()=>{if(!z?.profiles||z.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:z.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:z.profiles.length}))},[z?.profiles,Ce,c,t,e]),je=(0,Z.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0,l=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{let t=await r.setKProfile(a,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${be}-${c}`,nozzle_diameter:e.nozzle_diameter||c,extruder_id:e.extruder_id??0,slot_id:0});s++,_e(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`),q()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[a,c,t,q,e]),Me=(0,Z.useCallback)(e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Ne=(0,Z.useCallback)(()=>{A(new Set(Se.map(e=>L(e))))},[Se,L]),Pe=(0,Z.useCallback)(()=>{k.size!==0&&M(!0)},[k.size]),Fe=(0,Z.useCallback)(async()=>{let n=Se.filter(e=>k.has(L(e)));P(!0);let i=0,o=0;for(let e of n)try{let t=await r.deleteKProfile(a,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id});i++,_e(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:i})),o>0&&t(e(`kProfiles.toast.writesUnconfirmed`,{count:o}),`warning`),P(!1),M(!1),O(!1),A(new Set),q()},[a,k,Se,t,q,L,e]),Ie=(0,Z.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,Z.useCallback)(async(n,i)=>{if(a)try{await r.setKProfileNote(a,n,i),fe()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[a,fe,t,e]),Re=(0,Z.useCallback)(e=>{if(!Q?.notes)return{note:``,key:null};let t=Ie(e);for(let e of t)if(Q.notes[e])return{note:Q.notes[e],key:e};return{note:``,key:null}},[Q,Ie]),ze=(0,Z.useCallback)(e=>Re(e).note,[Re]);return ie?(0,$.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!R||R.length===0?(0,$.jsx)(G,{children:(0,$.jsxs)(W,{className:`py-12 text-center`,children:[(0,$.jsx)(m,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):me.length===0?(0,$.jsx)(G,{children:(0,$.jsxs)(W,{className:`py-12 text-center`,children:[(0,$.jsx)(I,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,$.jsxs)($.Fragment,{children:[B&&!oe&&(0,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,$.jsx)(j,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,$.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,$.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:me.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,$.jsxs)(`div`,{className:`w-32`,children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,$.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,$.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,$.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,$.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,$.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,$.jsxs)(K,{variant:`secondary`,onClick:()=>q(),disabled:B||!i(`kprofiles:read`),title:i(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,$.jsx)(ne,{className:`w-4 h-4 ${B?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,$.jsxs)(K,{onClick:()=>p(!0),disabled:!i(`kprofiles:create`),title:i(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,$.jsx)(F,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,$.jsx)(re,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(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,$.jsx)(`div`,{className:`w-36`,children:(0,$.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,$.jsx)(`option`,{value:`all`,children:e(`kProfiles.allExtruders`)}),(0,$.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,$.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),ke&&(0,$.jsx)(`div`,{className:`w-32`,children:(0,$.jsxs)(`select`,{value:S,onChange:e=>C(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,$.jsx)(`option`,{value:`all`,children:e(`kProfiles.allFlow`)}),(0,$.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,$.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,$.jsx)(`div`,{className:`w-32`,children:(0,$.jsxs)(`select`,{value:w,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,$.jsx)(`option`,{value:`name`,children:e(`kProfiles.sortName`)}),(0,$.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,$.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,$.jsxs)(K,{variant:`secondary`,onClick:Ae,disabled:!z?.profiles?.length||!i(`kprofiles:read`),title:i(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,$.jsx)(y,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,$.jsxs)(K,{variant:`secondary`,onClick:je,disabled:!i(`kprofiles:create`),title:i(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,$.jsx)(U,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,$.jsx)(`div`,{className:`flex-1`}),D?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(K,{variant:`secondary`,onClick:Ne,children:[(0,$.jsx)(ae,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,$.jsxs)(K,{variant:`secondary`,onClick:Pe,disabled:k.size===0||!i(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:i(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,$.jsx)(V,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,k.size,`)`]}),(0,$.jsxs)(K,{variant:`secondary`,onClick:()=>{O(!1),A(new Set)},children:[(0,$.jsx)(ce,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,$.jsxs)(K,{variant:`secondary`,onClick:()=>O(!0),disabled:!Se.length||!i(`kprofiles:delete`),title:i(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,$.jsx)(ae,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),oe?(0,$.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin`})}):pe?(0,$.jsx)(G,{children:(0,$.jsxs)(W,{className:`py-12 text-center`,children:[(0,$.jsx)(se,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,$.jsxs)(K,{variant:`secondary`,onClick:()=>q(),children:[(0,$.jsx)(ne,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):Se.length>0?Oe?(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:Se.filter(e=>e.extruder_id===1).map(e=>(0,$.jsx)(Te,{profile:e,onEdit:()=>d(e),onCopy:()=>g(e),selectionMode:D,isSelected:k.has(L(e)),onToggleSelect:()=>Me(L(e)),note:ze(e)},L(e)))})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:Se.filter(e=>e.extruder_id===0).map(e=>(0,$.jsx)(Te,{profile:e,onEdit:()=>d(e),onCopy:()=>g(e),selectionMode:D,isSelected:k.has(L(e)),onToggleSelect:()=>Me(L(e)),note:ze(e)},L(e)))})]})]}):(0,$.jsx)(`div`,{className:`space-y-1`,children:Se.map(e=>(0,$.jsx)(Te,{profile:e,onEdit:()=>d(e),onCopy:()=>g(e),selectionMode:D,isSelected:k.has(L(e)),onToggleSelect:()=>Me(L(e)),note:ze(e)},L(e)))}):_||b!==`all`||S!==`all`?(0,$.jsx)(G,{children:(0,$.jsxs)(W,{className:`py-12 text-center`,children:[(0,$.jsx)(re,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,$.jsx)(G,{children:(0,$.jsxs)(W,{className:`py-12 text-center`,children:[(0,$.jsx)(T,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:c})}),(0,$.jsxs)(K,{onClick:()=>p(!0),children:[(0,$.jsx)(F,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),u&&a&&(()=>{let{note:e,key:t}=Re(u);return(0,$.jsx)(Ee,{profile:u,printerId:a,nozzleDiameter:c,existingProfiles:z?.profiles,builtinFilaments:ve,filamentPresets:ye,isDualNozzle:Oe,supportsFlowType:ke,initialNote:e,initialNoteKey:t,onSaveNote:Le,hasPermission:i,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),d(null),q()},onSave:()=>{d(null),q()}})})(),f&&a&&(0,$.jsx)(Ee,{printerId:a,nozzleDiameter:c,existingProfiles:z?.profiles,builtinFilaments:ve,filamentPresets:ye,isDualNozzle:Oe,supportsFlowType:ke,onSaveNote:Le,hasPermission:i,onClose:()=>{p(!1),q()},onSave:()=>{p(!1),q()}}),h&&a&&(0,$.jsx)(Ee,{printerId:a,nozzleDiameter:c,existingProfiles:z?.profiles,builtinFilaments:ve,filamentPresets:ye,isDualNozzle:Oe,supportsFlowType:ke,onSaveNote:Le,hasPermission:i,profile:{...h,slot_id:0,name:`${h.name} (Copy)`},onClose:()=>{g(null),q()},onSave:()=>{g(null),q()}}),te&&(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,$.jsx)(G,{className:`w-full max-w-sm`,children:(0,$.jsxs)(W,{className:`p-6`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,$.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,$.jsx)(V,{className:`w-5 h-5 text-red-500`})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,$.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:k.size})}),(0,$.jsxs)(`div`,{className:`flex gap-3`,children:[(0,$.jsx)(K,{variant:`secondary`,onClick:()=>M(!1),disabled:N,className:`flex-1`,children:e(`common.cancel`)}),(0,$.jsxs)(K,{onClick:Fe,disabled:N,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[N?(0,$.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(V,{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:r,isExpanded:i}){let{t:a}=n(),{hasPermission:o}=le(),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,$.jsx)(G,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,$.jsxs)(W,{className:`p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,$.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,$.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s&&(0,$.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:s}),c&&(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c}),(0,$.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,$.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[o(`settings:update`)&&(0,$.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,$.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,$.jsx)(`button`,{onClick:()=>r(i?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:i?(0,$.jsx)(p,{className:`w-3.5 h-3.5`}):(0,$.jsx)(f,{className:`w-3.5 h-3.5`})})]})]}),i&&(0,$.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[s&&(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.filamentType`)}),(0,$.jsx)(`span`,{className:`text-white`,children:s})]}),c&&(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.vendor`)}),(0,$.jsx)(`span`,{className:`text-white`,children:c})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.nozzleTemp`)}),(0,$.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.cost`)}),(0,$.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.density`)}),(0,$.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.pressureAdvance`)}),(0,$.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.compatiblePrinters`)}),(0,$.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,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.inheritsFrom`)}),(0,$.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.source`)}),(0,$.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function Pe(){let{t:e}=n(),{hasPermission:t}=le(),i=o(),{showToast:a}=ee(),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(null),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(null),{data:v,isLoading:y}=s({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets()}),x=c({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await r.importLocalPresets(e))}return t},onSuccess:t=>{i.invalidateQueries({queryKey:[`localPresets`]}),i.invalidateQueries({queryKey:[`slicerPresets`]});let n=0,r=0,o=0;for(let e of t)n+=e.imported,r+=e.skipped,o+=e.errors.length;n>0&&a(e(`profiles.localProfiles.toast.importSuccess`,{count:n})),r>0&&a(e(`profiles.localProfiles.toast.importSkipped`,{count:r}),`warning`),o>0&&a(e(`profiles.localProfiles.toast.importError`,{count:o}),`error`)},onError:e=>{a(e.message,`error`)}}),S=c({mutationFn:e=>r.deleteLocalPreset(e),onSuccess:(t,n)=>{i.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==n),printer:e.printer.filter(e=>e.id!==n),process:e.process.filter(e=>e.id!==n)}),i.invalidateQueries({queryKey:[`localPresets`]}),i.invalidateQueries({queryKey:[`slicerPresets`]}),_(null),a(e(`profiles.localProfiles.toast.deleted`))}}),C=(0,Z.useCallback)(e=>{!e||e.length===0||x.mutate(e)},[x]),w=(0,Z.useCallback)(e=>{e.preventDefault(),h(!1),C(e.dataTransfer.files)},[C]),T=(0,Z.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]),E=(0,Z.useMemo)(()=>T(v?.filament||[]),[v?.filament,T]),O=(0,Z.useMemo)(()=>T(v?.printer||[]),[v?.printer,T]),A=(0,Z.useMemo)(()=>T(v?.process||[]),[v?.process,T]),te=E.length+O.length+A.length,M=(v?.filament?.length??0)+(v?.printer?.length??0)+(v?.process?.length??0)>0;return y?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,$.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,$.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),h(!0)},onDragLeave:()=>h(!1),onDrop:w,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,$.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=>C(e.target.files)}),x.isPending?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,$.jsx)(j,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(U,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,$.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),M&&(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(re,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.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`})]}),!M&&!y&&(0,$.jsxs)(`div`,{className:`text-center py-12`,children:[(0,$.jsx)(D,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),M&&te===0&&!y&&(0,$.jsxs)(`div`,{className:`text-center py-12`,children:[(0,$.jsx)(re,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),te>0&&(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[E.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,$.jsx)(b,{className:`w-4 h-4 text-bambu-green`}),(0,$.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,E.length,`)`]})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:E.map(e=>(0,$.jsx)(Ne,{preset:e,onDelete:e=>_(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),A.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,$.jsx)(k,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,$.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,A.length,`)`]})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:A.map(e=>(0,$.jsx)(Ne,{preset:e,onDelete:e=>_(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),O.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,$.jsx)(R,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,$.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,O.length,`)`]})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:O.map(e=>(0,$.jsx)(Ne,{preset:e,onDelete:e=>_(e),onExpand:f,isExpanded:d===e.id},e.id))})]})]}),g!==null&&(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,$.jsx)(m,{className:`w-5 h-5 text-red-600 dark:text-red-400`}),(0,$.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(K,{variant:`secondary`,size:`sm`,onClick:()=>_(null),children:e(`profiles.localProfiles.cancel`)}),(0,$.jsxs)(K,{variant:`danger`,size:`sm`,onClick:()=>S.mutate(g),disabled:S.isPending,children:[S.isPending?(0,$.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(V,{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,Z.useState)(``),[c,l]=(0,Z.useState)(`all`),[u,d]=(0,Z.useState)(`all`),[f,p]=(0,Z.useState)(`all`),[m,ee]=(0,Z.useState)(`all`),[g,_]=(0,Z.useState)(`all`),[v,y]=(0,Z.useState)(null),x=(0,Z.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]),S=(0,Z.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return x.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[x,i]),C=(0,Z.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),T=(0,Z.useMemo)(()=>x.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!C)return!0;let t=e.meta.printer?.toLowerCase()||``,n=C.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[x,c,u,C,f,m,g,o]),E=()=>{l(`all`),d(`all`),p(`all`),ee(`all`),_(`all`),s(``)},D=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,O=e.filament.length+e.printer.length+e.process.length,A=e=>T.filter(t=>t.type===e);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(re,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.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,$.jsx)(`div`,{className:`flex gap-2`,children:(0,$.jsxs)(K,{variant:`secondary`,onClick:n,disabled:r,children:[(0,$.jsx)(ne,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(w,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(Ge,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:O},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),S.printers.length>0&&(0,$.jsx)(Ge,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),S.nozzles.length>0&&(0,$.jsx)(Ge,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.nozzles.map(e=>({value:e,label:e}))],onChange:p}),S.filaments.length>0&&(c===`all`||c===`filament`)&&(0,$.jsx)(Ge,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.filaments.map(e=>({value:e,label:e}))],onChange:ee}),S.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,$.jsx)(Ge,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.layerHeights.map(e=>({value:e,label:e}))],onChange:_}),D&&(0,$.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,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(h,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,q(t.toISOString(),`system`,a)]}),(0,$.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:T.length,total:O})})]}),T.length===0?(0,$.jsxs)(`div`,{className:`text-center py-16`,children:[(0,$.jsx)(k,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),D&&(0,$.jsx)(`button`,{onClick:E,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,$.jsx)(Le,{icon:(0,$.jsx)(b,{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:y}),(0,$.jsx)(Le,{icon:(0,$.jsx)(R,{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:y}),(0,$.jsx)(Le,{icon:(0,$.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:y})]}),v&&(0,$.jsx)(ze,{setting:v,onClose:()=>y(null),t:a})]})}function Le({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,$.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,$.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,$.jsx)(Re,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function Re({preset:e,onClick:t}){return(0,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function ze({setting:e,onClose:t,t:n}){let{data:i,isLoading:a,error:o}=s({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>r.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,$.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,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,$.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,$.jsx)(ce,{className:`w-5 h-5`})})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:a?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin`})}):o?(0,$.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:o.message}):i?(0,$.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(i.setting,null,2)}):(0,$.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function Be(){let{t:e}=n(),t=o(),{showToast:i}=ee(),{hasPermission:a}=le(),l=a(`orca_cloud:auth`),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(5e3),[m,h]=(0,Z.useState)(null),{data:g,isLoading:_}=s({queryKey:[`orcaCloudStatus`],queryFn:r.orcaCloudStatus}),v=!!g?.connected,{data:y,isLoading:b,refetch:x,isRefetching:S,error:C,dataUpdatedAt:w}=s({queryKey:[`orcaCloudProfiles`],queryFn:r.orcaCloudListProfiles,enabled:v,retry:!1,staleTime:1e3*60*5}),{data:T=[]}=s({queryKey:[`printers`],queryFn:r.getPrinters,enabled:v}),[E,D]=(0,Z.useState)();(0,Z.useEffect)(()=>{w&&D(new Date(w))},[w]);let O=()=>{d(null),p(5e3)},k=t=>{t===`access_denied`?h(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&h(e(`profiles.orcaCloud.errors.expired`)),O()},A=c({mutationFn:r.orcaCloudDeviceStart,onSuccess:e=>{h(null),p(Math.max(1,e.interval)*1e3),d(e)},onError:t=>{h(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),te=c({mutationFn:r.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),i(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:N,error:P}=s({queryKey:[`orcaCloudDevicePoll`,u?.user_code??`none`],queryFn:r.orcaCloudDevicePoll,enabled:u!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:u!==null&&f}),F=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{if(!u||!N)return;let n=N.status;if(n===`slow_down`){p(e=>e+5e3);return}n!==`authorization_pending`&&F.current!==n&&(F.current=n,n===`complete`?(O(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),i(e(`profiles.orcaCloud.connectedShort`))):k(n))},[N,u]),(0,Z.useEffect)(()=>{u&&P&&(h(e(`profiles.orcaCloud.errors.pollFailed`)),O())},[P,u]),(0,Z.useEffect)(()=>{u&&(F.current=null)},[u]),_?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,$.jsxs)(`div`,{children:[v&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,$.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:g?.email?(0,$.jsxs)($.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,$.jsx)(`span`,{className:`text-white`,children:g.email})]}):(0,$.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,$.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>te.mutate(),disabled:te.isPending||!l,title:l?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,$.jsx)(M,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),v?b?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin`})}):C?(0,$.jsxs)(`div`,{className:`text-center py-16`,children:[(0,$.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:C.message}),(0,$.jsx)(K,{onClick:()=>x(),children:e(`profiles.orcaCloud.retry`)})]}):y?(0,$.jsx)(Ie,{settings:y,lastSyncTime:E,onRefresh:()=>x(),isRefreshing:S,printers:T,t:e}):null:(0,$.jsx)(Ve,{pairing:u,connectError:m,onConnect:()=>A.mutate(),onCancel:O,isStarting:A.isPending,canManage:l,t:e})]})}function Ve({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,$.jsx)(G,{children:(0,$.jsxs)(W,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,$.jsx)(g,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,$.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.device.title`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:o(`profiles.orcaCloud.device.instruction`)}),(0,$.jsx)(`p`,{className:`text-xs uppercase tracking-wide text-bambu-gray mb-2`,children:o(`profiles.orcaCloud.device.codeLabel`)}),(0,$.jsx)(`div`,{className:`mb-6 py-3 px-4 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:(0,$.jsx)(`span`,{className:`text-2xl font-mono font-bold tracking-[0.3em] text-white select-all`,children:e.user_code})}),(0,$.jsx)(`a`,{href:e.verification_uri_complete,target:`_blank`,rel:`noopener noreferrer`,children:(0,$.jsxs)(K,{className:`w-full mb-3`,children:[(0,$.jsx)(x,{className:`w-4 h-4`}),o(`profiles.orcaCloud.device.openButton`)]})}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray break-all mb-6`,children:o(`profiles.orcaCloud.device.manualHint`,{url:e.verification_uri})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-bambu-gray mb-4`,children:[(0,$.jsx)(j,{className:`w-4 h-4 animate-spin text-bambu-green`}),o(`profiles.orcaCloud.device.waiting`)]}),(0,$.jsx)(`button`,{type:`button`,onClick:r,className:`text-bambu-gray hover:text-white text-sm`,children:o(`profiles.orcaCloud.device.cancel`)})]})}):(0,$.jsx)(G,{children:(0,$.jsxs)(W,{className:`p-8 text-center`,children:[(0,$.jsx)(g,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,$.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.connect.title`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:o(`profiles.orcaCloud.connect.description`)}),(0,$.jsxs)(`div`,{className:`max-w-sm mx-auto`,children:[(0,$.jsxs)(K,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,$.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(d,{className:`w-4 h-4`}),o(`profiles.orcaCloud.connectButton`)]}),t&&(0,$.jsxs)(`p`,{className:`mt-3 text-sm text-red-700 dark:text-red-400 flex items-center justify-center gap-2`,children:[(0,$.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}=ee(),[i,a]=(0,Z.useState)(`email`),[o,s]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(``),[h,_]=(0,Z.useState)(`global`),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(null),[S,C]=(0,Z.useState)(!1),w=c({mutationFn:()=>r.cloudLogin(o,l,h),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`)}}),T=c({mutationFn:()=>r.cloudVerify(o,d,b||void 0,h),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`)}}),E=c({mutationFn:()=>r.cloudSetToken(p,h),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),D=e=>{e.preventDefault(),i===`email`?w.mutate():i===`code`?T.mutate():i===`token`&&E.mutate()},k=w.isPending||T.isPending||E.isPending;return(0,$.jsx)(G,{className:`max-w-md mx-auto`,children:(0,$.jsxs)(W,{children:[(0,$.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,$.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,$.jsx)(g,{className:`w-6 h-6 text-bambu-green`})}),(0,$.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),S&&i!==`token`&&(0,$.jsx)(`div`,{role:`alert`,className:`mb-4 p-3 rounded-lg border border-amber-500/40 bg-amber-500/10`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(ie,{className:`w-4 h-4 text-amber-400 shrink-0 mt-0.5`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-amber-300`,children:t(`profiles.login.captchaTitle`)}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`profiles.login.captchaBody`)}),(0,$.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,$.jsx)(O,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,$.jsxs)(`form`,{onSubmit:D,className:`space-y-4`,children:[i===`email`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,$.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,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,$.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,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,$.jsxs)(`select`,{value:h,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,$.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,$.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),i===`code`&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(v===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:v===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:o})}),(0,$.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),i===`token`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,$.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,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,$.jsxs)(`select`,{value:h,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,$.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,$.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[i===`code`&&(0,$.jsx)(K,{type:`button`,variant:`secondary`,onClick:()=>a(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,$.jsxs)(K,{type:`submit`,disabled:k,className:`flex-1`,children:[k?(0,$.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(te,{className:`w-4 h-4`}),t(i===`email`?`profiles.login.loginButton`:i===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),i===`email`&&(0,$.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,$.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,$.jsx)(O,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),i===`token`&&(0,$.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,$.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,$.jsx)(te,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function Ge({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,Z.useState)(!1),o=n.find(e=>e.value===t);return(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.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,$.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,$.jsx)(`span`,{children:o?.label||`All`}),(0,$.jsx)(f,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,$.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,$.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,$.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,$.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function Ke(){let[e,t]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,$.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,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,$.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,$.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,$.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,$.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,$.jsx)(v,{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:i,onEdit:a,hasPermission:l,t:u}){let{showToast:d}=ee(),f=o(),[p,m]=(0,Z.useState)(!1),{data:h,isLoading:g}=s({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>r.getCloudSettingDetail(e.setting_id)}),_=c({mutationFn:()=>r.deleteCloudSetting(e.setting_id),onSuccess:()=>{d(u(`profiles.presets.toast.deleted`)),f.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>d(e.message,`error`)}),y=Ue(e.setting_id),b=He(e.name,h?.setting?.inherits);return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,$.jsx)(G,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,$.jsxs)(W,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),y&&(0,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,$.jsx)(`span`,{className:`capitalize`,children:u(`profiles.presets.types.${e.type}`)}),b.printer&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`•`}),(0,$.jsx)(`span`,{children:b.printer})]})]})]}),(0,$.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,$.jsx)(ce,{className:`w-5 h-5`})})]}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:g?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin`})}):h?(0,$.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(h)}):(0,$.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:u(`profiles.presets.failedToLoadDetails`)})}),p?(0,$.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-700 dark:text-red-400`,children:[(0,$.jsx)(H,{className:`w-5 h-5`}),(0,$.jsx)(`span`,{className:`font-medium`,children:u(`profiles.presets.deleteConfirm`)})]}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:u(`profiles.presets.deleteWarning`,{name:e.name})}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(K,{variant:`secondary`,onClick:()=>m(!1),disabled:_.isPending,className:`flex-1`,children:u(`common.cancel`)}),(0,$.jsxs)(K,{variant:`danger`,onClick:()=>_.mutate(),disabled:_.isPending,className:`flex-1`,children:[_.isPending?(0,$.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(V,{className:`w-4 h-4`}),u(`common.delete`)]})]})]}):(0,$.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(K,{variant:`secondary`,onClick:t,className:`flex-1`,children:u(`common.close`)}),(0,$.jsxs)(K,{variant:`secondary`,onClick:i,disabled:!l(`cloud:auth`),title:l(`cloud:auth`)?void 0:u(`profiles.presets.noDuplicatePermission`),children:[(0,$.jsx)(v,{className:`w-4 h-4`}),u(`profiles.presets.duplicate`)]}),y&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(K,{variant:`secondary`,onClick:a,disabled:g||!h||!l(`cloud:auth`),title:l(`cloud:auth`)?void 0:u(`profiles.presets.noEditPermission`),children:[(0,$.jsx)(P,{className:`w-4 h-4`}),u(`common.edit`)]}),(0,$.jsx)(K,{variant:`danger`,onClick:()=>m(!0),disabled:!l(`cloud:auth`),title:l(`cloud:auth`)?void 0:u(`profiles.presets.noDeletePermission`),children:(0,$.jsx)(V,{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}=ee(),[i,a]=(0,Z.useState)(Xe),[o,s]=(0,Z.useState)(`all`),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(`{}`),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),w=e=>{a(e),Ze(e)},T=e=>{let t=i.filter(t=>t.id!==e);w(t),y(null),r(n(`profiles.templates.toast.deleted`))},E=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),_(null)},D=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m),t=i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t);w(t),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){_(e.message)}},O=()=>{l(null),d(``),p(``),h(`{}`),_(null)},k=e=>{let t=i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t);w(t)},A={filament:{label:n(`profiles.presets.types.filament`),icon:b,color:`text-amber-600 dark:text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:R,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`}},j=v?i.find(e=>e.id===v):null;return(0,Z.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(v?y(null):c?O():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[v,c,e]),(0,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[j&&(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,$.jsx)(G,{className:`w-full max-w-md`,children:(0,$.jsxs)(W,{className:`p-6`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,$.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,$.jsx)(H,{className:`w-6 h-6 text-red-600 dark:text-red-400`})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,$.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:j.name})}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(K,{variant:`secondary`,onClick:()=>y(null),className:`flex-1`,children:n(`common.cancel`)}),(0,$.jsxs)(K,{onClick:()=>T(v),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,$.jsx)(V,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,$.jsx)(G,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,$.jsxs)(W,{className:`p-0 flex flex-col h-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,$.jsx)(z,{className:`w-5 h-5 text-amber-600 dark:text-amber-400`}),n(`profiles.templates.title`)]}),(0,$.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,$.jsx)(ce,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,$.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`):A[e].label},e))]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0?(0,$.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,$.jsx)(z,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,$.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,$.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,$.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>{let r=A[e.type],i=r.icon;return c===e.id?(0,$.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,$.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,$.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,$.jsxs)(`div`,{className:`mb-3`,children:[(0,$.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,$.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),_(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 ${g?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),g&&(0,$.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:g})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(K,{size:`sm`,onClick:D,disabled:!u.trim(),children:[(0,$.jsx)(L,{className:`w-4 h-4`}),`Save`]}),(0,$.jsx)(K,{size:`sm`,variant:`secondary`,onClick:O,children:`Cancel`})]})]},e.id):(0,$.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,$.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,$.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,$.jsx)(`button`,{onClick:()=>k(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,$.jsx)(C,{className:`w-4 h-4`}):(0,$.jsx)(S,{className:`w-4 h-4`})}),(0,$.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,$.jsx)(`button`,{onClick:()=>E(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,$.jsx)(P,{className:`w-4 h-4`})}),(0,$.jsx)(`button`,{onClick:()=>y(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`,title:n(`common.delete`),children:(0,$.jsx)(V,{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,Z.useState)(`changes`),[c,u]=(0,Z.useState)(``),d=(0,Z.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,Z.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,Z.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,Z.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,$.jsx)(G,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,$.jsxs)(W,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,$.jsx)(E,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),a(`profiles.diff.title`)]}),(0,$.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,$.jsx)(ce,{className:`w-5 h-5`})})]}),(0,$.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,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,$.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,$.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,$.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,$.jsx)(F,{className:`w-3.5 h-3.5`}),p.added,` `,a(`profiles.diff.added`)]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,$.jsx)(N,{className:`w-3.5 h-3.5`}),p.removed,` `,a(`profiles.diff.removed`)]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-700 dark:text-amber-400`,children:[(0,$.jsx)(l,{className:`w-3.5 h-3.5`}),p.changed,` `,a(`profiles.diff.changed`)]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,$.jsx)(X,{className:`w-3.5 h-3.5`}),p.same,` `,a(`profiles.diff.same`)]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(re,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.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,$.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,$.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,$.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,$.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:f.length===0?(0,$.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,$.jsx)(X,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,$.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,$.jsxs)(`table`,{className:`w-full`,children:[(0,$.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,$.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,$.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,$.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,$.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,$.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,$.jsx)(F,{className:`w-3.5 h-3.5 text-green-600 dark:text-green-400`}),removed:(0,$.jsx)(N,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400`}),changed:(0,$.jsx)(l,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),same:(0,$.jsx)(X,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,$.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,$.jsx)(`td`,{className:`p-3`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,$.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,$.jsx)(`td`,{className:`p-3`,children:(0,$.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,$.jsx)(`td`,{className:`p-3`,children:(0,$.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:i}){let{showToast:a}=ee(),l=o(),u=!!t?.setting_id,[f,p]=(0,Z.useState)(`common`),[h,g]=(0,Z.useState)(t?.type||`filament`),[v,b]=(0,Z.useState)(t?.name?u?t.name:`${t.name} (Copy)`:``),[x,w]=(0,Z.useState)(t?.base_id||``),[T,D]=(0,Z.useState)(``),[O,k]=(0,Z.useState)(t?.setting||{inherits:``}),[te,M]=(0,Z.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[N,P]=(0,Z.useState)(null),[I,ne]=(0,Z.useState)(``),[R,ie]=(0,Z.useState)(!1),[ae,oe]=(0,Z.useState)(``),[B,V]=(0,Z.useState)(!1),[H,se]=(0,Z.useState)(Xe),[le,q]=(0,Z.useState)(!1),[J,Y]=(0,Z.useState)(``),[ue,X]=(0,Z.useState)(``),[Q,fe]=(0,Z.useState)(!0),[pe,me]=(0,Z.useState)(null),[he,ge]=(0,Z.useState)(!1),_e=(0,Z.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[h]||[],[n,h]),ve=(0,Z.useMemo)(()=>_e.filter(e=>Ue(e.setting_id)),[_e]),{data:ye}=s({queryKey:[`cloudFields`,h],queryFn:()=>r.getCloudFields(h===`print`?`process`:h),staleTime:1e3*60*60}),{data:be}=s({queryKey:[`allPresetDetails`,h,ve.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t<ve.length;t+=5){let n=ve.slice(t,t+5);(await Promise.all(n.map(async e=>{try{let t=await r.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:ve.length>0,staleTime:1e3*60*10}),{data:xe,isLoading:Se}=s({queryKey:[`cloudSettingDetail`,x],queryFn:()=>r.getCloudSettingDetail(x),enabled:!!x});(0,Z.useEffect)(()=>{f!==`json`&&M(JSON.stringify(O,null,2))},[O,f]);let Ce=(0,Z.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[h]||[]).filter(e=>!Ue(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,h]);(0,Z.useEffect)(()=>{if(!x)return;let e=Ce.find(e=>e.setting_id===x);e&&(D(e.name),u||(k({inherits:e.name}),M(JSON.stringify({inherits:e.name},null,2))))},[x,Ce,u]);let we=(0,Z.useMemo)(()=>{let e=ye?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,r=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);be&&Object.values(be).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!r.has(e)&&n.add(e)})}),Object.keys(O).forEach(e=>{!t.has(e)&&!r.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:i(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[ye,be,O,i]),Te=we.filter(e=>e.label.toLowerCase().includes(I.toLowerCase())||e.key.toLowerCase().includes(I.toLowerCase())),Ee=()=>{if(ae.trim()){let e=ae.trim().toLowerCase().replace(/\s+/g,`_`);De(e,``),oe(``),V(!1),a(i(`profiles.presets.toast.fieldAdded`,{key:e}))}},De=(e,t)=>{k(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},Oe=e=>{k(t=>({...t,...e.settings})),me(e.name),a(i(`profiles.templates.toast.applied`))},ke=()=>{if(!J.trim())return;let e={...O};if(delete e.inherits,Object.keys(e).length===0){a(i(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:J.trim(),description:ue.trim()||i(`profiles.presets.customTemplate`),type:h,settings:e,showInModal:Q},n=[...H,t];se(n),Ze(n),q(!1),Y(``),X(``),fe(!0),a(i(`profiles.templates.toast.created`))},Ae=(0,Z.useMemo)(()=>H.filter(e=>e.type===h&&e.showInModal),[h,H]),je=e=>{M(e);try{let t=JSON.parse(e);k(t),P(null)}catch(e){P(e.message)}},Me=e=>{e.preventDefault(),ie(!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),r=n.setting||n;k(e=>({...e,...r})),M(JSON.stringify({...O,...r},null,2)),a(i(`profiles.presets.fileImported`))}catch{a(i(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},Ne=c({mutationFn:()=>{let e={...O},t=h===`filament`?`filament_settings_id`:h===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${v}"`;let n={type:h,name:v,base_id:x,setting:e};return r.createCloudSetting(n)},onSuccess:async()=>{a(i(`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(i(`profiles.presets.noSettingId`));return r.updateCloudSetting(t.setting_id,{name:v,setting:O})},onSuccess:async()=>{a(i(`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=xe?.setting?.inherits,Le=Ie?Ce.find(e=>e.name===Ie):void 0,{data:Re}=s({queryKey:[`cloudSettingDetail`,Le?.setting_id],queryFn:()=>r.getCloudSettingDetail(Le.setting_id),enabled:!!Le?.setting_id}),ze=(0,Z.useMemo)(()=>{let e=Re?.setting||{},t=xe?.setting||{},n=x&&be?.[x]?.setting?be[x].setting:{};return{...e,...t,...n}},[x,xe,Re,be]),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=O[e.key],n=ze[e.key],r=Be(n),a=Se?i(`common.loading`):r||``,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,$.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,$.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,$.jsxs)(`select`,{value:t||``,onChange:t=>De(e.key,t.target.value),className:o,children:[(0,$.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.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,$.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},He=(0,Z.useMemo)(()=>xe?.setting?xe.setting:{},[xe]);return(0,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),ie(!0)},onDragLeave:()=>ie(!1),onDrop:Me,children:[he&&x&&(0,$.jsx)($e,{onClose:()=>ge(!1),leftPreset:He,rightPreset:O,leftLabel:i(`profiles.presets.baseLabel`,{name:T||x}),rightLabel:i(`profiles.presets.currentLabel`,{name:v||i(`profiles.presets.newPreset`)}),t:i}),(0,$.jsx)(G,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,$.jsxs)(W,{className:`p-0 flex flex-col h-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:i(u?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`profiles.presets.customizeSettings`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x&&(0,$.jsxs)(`button`,{onClick:()=>ge(!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:i(`profiles.presets.compareWithBase`),children:[(0,$.jsx)(E,{className:`w-4 h-4`}),i(`profiles.presets.compare`)]}),(0,$.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,$.jsx)(ce,{className:`w-5 h-5`})})]})]}),R&&(0,$.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,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(U,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,$.jsx)(`p`,{className:`text-bambu-green font-medium`,children:i(`profiles.presets.dropJsonToImport`)})]})}),(0,$.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`common.type`)}),(0,$.jsxs)(`select`,{value:h,onChange:e=>{g(e.target.value),w(``)},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,$.jsx)(`option`,{value:`filament`,children:i(`profiles.presets.types.filament`)}),(0,$.jsx)(`option`,{value:`print`,children:i(`profiles.presets.types.process`)}),(0,$.jsx)(`option`,{value:`printer`,children:i(`profiles.presets.types.printer`)})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`profiles.presets.basePreset`)}),(0,$.jsxs)(`select`,{value:x,onChange:e=>w(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,$.jsx)(`option`,{value:``,children:i(`profiles.presets.selectBasePreset`)}),Ce.map(e=>(0,$.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`profiles.presets.presetName`)}),(0,$.jsx)(`input`,{type:`text`,value:v,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:i(`profiles.presets.myCustomPreset`)})]})]}),T&&(0,$.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,$.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(d,{className:`w-3 h-3 text-bambu-green`}),i(`profiles.presets.inheritsFrom`),` `,(0,$.jsx)(`span`,{className:`text-white`,children:T}),Se&&(0,$.jsx)(j,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,$.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,$.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,$.jsx)(de,{className:`w-4 h-4`}),i(`profiles.presets.tabs.common`)]}),(0,$.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,$.jsx)(A,{className:`w-4 h-4`}),i(`profiles.presets.tabs.allFields`)]}),(0,$.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,$.jsx)(_,{className:`w-4 h-4`}),`JSON`,N&&(0,$.jsx)(m,{className:`w-3 h-3 text-red-600 dark:text-red-400`})]}),(0,$.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,$.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:v,type:h,base_id:x,setting:O},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${v||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),a(i(`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:i(`profiles.presets.exportToJson`),children:[(0,$.jsx)(y,{className:`w-4 h-4`}),i(`common.download`)]}),(0,$.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:i(`profiles.presets.importFromJson`),children:[(0,$.jsx)(U,{className:`w-4 h-4`}),i(`common.upload`)]}),(0,$.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;k(e=>({...e,...n})),a(i(`profiles.presets.fileImported`))}catch{a(i(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,$.jsxs)(`div`,{className:`flex-1 p-4`,children:[f===`common`&&(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,$.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,$.jsx)(z,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`profiles.templates.title`)]}),Object.keys(O).filter(e=>e!==`inherits`).length>0&&(0,$.jsxs)(`button`,{onClick:()=>q(!le),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,$.jsx)(L,{className:`w-3 h-3`}),i(`profiles.presets.saveAsTemplate`)]})]}),le&&(0,$.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,$.jsx)(`input`,{type:`text`,value:J,onChange:e=>Y(e.target.value),placeholder:i(`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,$.jsx)(`input`,{type:`text`,value:ue,onChange:e=>X(e.target.value),placeholder:i(`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,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(K,{size:`sm`,onClick:ke,disabled:!J.trim(),children:[(0,$.jsx)(L,{className:`w-3 h-3`}),i(`common.save`)]}),(0,$.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>q(!1),children:i(`common.cancel`)})]}),(0,$.jsxs)(`button`,{onClick:()=>fe(!Q),className:`flex items-center gap-1.5 text-xs transition-colors ${Q?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[Q?(0,$.jsx)(C,{className:`w-3.5 h-3.5`}):(0,$.jsx)(S,{className:`w-3.5 h-3.5`}),i(Q?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),pe&&(0,$.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,$.jsx)(d,{className:`w-4 h-4 text-bambu-green`}),(0,$.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[i(`profiles.presets.templateApplied`),` `,(0,$.jsx)(`span`,{className:`font-medium`,children:pe})]}),(0,$.jsx)(`button`,{onClick:()=>me(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,$.jsx)(ce,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[Ae.map(e=>(0,$.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,$.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),Ae.length===0&&(0,$.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:i(`profiles.presets.noTemplatesSelected`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:i(`profiles.presets.manageTemplatesHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:i(`profiles.presets.commonSettings`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:we.slice(0,10).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,$.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,$.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:Ve(e)})]},e.key))})]}),Object.keys(O).length>1&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:i(`profiles.presets.currentOverrides`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(O).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,$.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,$.jsx)(`button`,{onClick:()=>De(e,void 0),className:`hover:text-white`,children:(0,$.jsx)(ce,{className:`w-3 h-3`})})]},e))})]})]}),f===`fields`&&(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,$.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:i(`profiles.presets.availableFields`)}),(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:be?i(`profiles.templates.fieldsCount`,{count:we.length}):i(`common.loading`)})]}),(0,$.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,$.jsx)(re,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,value:I,onChange:e=>ne(e.target.value),placeholder:i(`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,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[Te.filter(e=>!(e.key in O)).map(e=>{let t=ze[e.key],n=Be(t);return(0,$.jsxs)(`div`,{onClick:()=>{k(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,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,$.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,$.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,$.jsx)(F,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),Te.filter(e=>!(e.key in O)).length===0&&(0,$.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:i(I?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,$.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:B?(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,value:ae,onChange:e=>oe(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,$.jsx)(K,{size:`sm`,onClick:Ee,disabled:!ae.trim(),children:(0,$.jsx)(F,{className:`w-4 h-4`})}),(0,$.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>{V(!1),oe(``)},children:(0,$.jsx)(ce,{className:`w-4 h-4`})})]}):(0,$.jsxs)(`button`,{onClick:()=>V(!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,$.jsx)(F,{className:`w-4 h-4`}),i(`profiles.presets.addCustomField`)]})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:i(`profiles.presets.yourOverrides`)}),(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:i(`profiles.templates.fieldsCount`,{count:Object.keys(O).filter(e=>e!==`inherits`).length})})]}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(O).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=we.find(t=>t.key===e);return(0,$.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,$.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,$.jsx)(ce,{className:`w-4 h-4`})})]}),n?Ve(n):(0,$.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(O).filter(e=>e!==`inherits`).length===0&&(0,$.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,$.jsx)(de,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,$.jsx)(`p`,{className:`text-sm`,children:i(`profiles.presets.noOverridesYet`)}),(0,$.jsx)(`p`,{className:`text-xs mt-1`,children:i(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(O).filter(e=>e!==`inherits`).length>0&&(0,$.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,$.jsxs)(`button`,{onClick:()=>{q(!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,$.jsx)(L,{className:`w-4 h-4`}),i(`profiles.presets.saveAsTemplate`)]})})]})]}),f===`json`&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[N&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,$.jsx)(m,{className:`w-4 h-4`}),N]}),(0,$.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 ${N?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`profiles.presets.jsonTip`)})]})]}),(0,$.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,$.jsx)(K,{variant:`secondary`,onClick:e,className:`flex-1`,children:i(`common.cancel`)}),(0,$.jsxs)(K,{onClick:()=>Fe.mutate(),disabled:Fe.isPending||!v.trim()||!u&&!x||!!N,className:`flex-1`,children:[Fe.isPending?(0,$.jsx)(j,{className:`w-4 h-4 animate-spin`}):u?(0,$.jsx)(L,{className:`w-4 h-4`}):(0,$.jsx)(F,{className:`w-4 h-4`}),i(u?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function tt({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:i,printers:a,hasPermission:s,t:c}){let[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(`all`),[m,ee]=(0,Z.useState)(`all`),[g,_]=(0,Z.useState)(`all`),[v,y]=(0,Z.useState)(`all`),[x,S]=(0,Z.useState)(`all`),[C,T]=(0,Z.useState)(`all`),[D,O]=(0,Z.useState)(null),[A,j]=(0,Z.useState)(!1),[te,M]=(0,Z.useState)(!1),[N,P]=(0,Z.useState)(null),[L,ie]=(0,Z.useState)(null),[ae,oe]=(0,Z.useState)(null),[B,V]=(0,Z.useState)(!1),[H,U]=(0,Z.useState)([null,null]),[se,ce]=(0,Z.useState)(!1),[le,W]=(0,Z.useState)(null),G=o(),J=(0,Z.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]),Y=(0,Z.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return J.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))}},[J,a]),ue=(0,Z.useMemo)(()=>g===`all`?null:a.find(e=>e.id.toString()===g)?.model||null,[g,a]),X=(0,Z.useMemo)(()=>J.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`||!ue)return!0;let t=e.meta.printer?.toLowerCase()||``,n=ue.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>v===`all`||e.meta.nozzle===v).filter(e=>x===`all`||e.meta.filamentType===x).filter(e=>C===`all`||e.meta.layerHeight===C).filter(e=>u===``||e.name.toLowerCase().includes(u.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[J,f,m,g,ue,v,x,C,u]),de=e=>{if(B){let t=H[0]?.setting_id===e.setting_id,n=H[1]?.setting_id===e.setting_id;if(t)U([H[1],null]);else if(n)U([H[0],null]);else if(!H[0])U([e,null]);else if(H[1]){if(H[0].type!==e.type)return;U([H[0],e])}else{if(H[0].type!==e.type)return;U([H[0],e])}}else O(e)},Q=e=>{if(H[0]?.setting_id===e.setting_id)return 0;if(H[1]?.setting_id===e.setting_id)return 1},fe=async e=>{try{let t=await r.getCloudSettingDetail(e.setting_id),n=e.type===`process`?`print`:e.type;P({type:n,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),O(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},pe=async e=>{try{G.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await r.getCloudSettingDetail(e.setting_id),n=e.type===`process`?`print`:e.type;ie({type:n,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),O(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},me=()=>{p(`all`),ee(`all`),_(`all`),y(`all`),S(`all`),T(`all`),d(``)},he=f!==`all`||m!==`all`||g!==`all`||v!==`all`||x!==`all`||C!==`all`||u!==``,ge=e.filament.length+e.printer.length+e.process.length;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(re,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.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,$.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,$.jsxs)(K,{variant:B?`primary`:`secondary`,onClick:()=>{B?(V(!1),U([null,null])):V(!0)},children:[(0,$.jsx)(E,{className:`w-4 h-4`}),c(B?`common.cancel`:`profiles.presets.compare`)]}),(0,$.jsxs)(K,{variant:`secondary`,onClick:()=>M(!0),disabled:!s(`cloud:auth`),title:s(`cloud:auth`)?void 0:c(`profiles.cloudView.noTemplatesPermission`),children:[(0,$.jsx)(z,{className:`w-4 h-4`}),c(`profiles.cloudView.templates`)]}),(0,$.jsxs)(K,{variant:`secondary`,onClick:n,disabled:i||!s(`cloud:auth`),title:s(`cloud:auth`)?void 0:c(`profiles.cloudView.noRefreshPermission`),children:[(0,$.jsx)(ne,{className:`w-4 h-4 ${i?`animate-spin`:``}`}),c(`profiles.cloudView.refresh`)]}),(0,$.jsxs)(K,{onClick:()=>j(!0),disabled:!s(`cloud:auth`),title:s(`cloud:auth`)?void 0:c(`profiles.cloudView.noCreatePermission`),children:[(0,$.jsx)(F,{className:`w-4 h-4`}),c(`profiles.cloudView.newPreset`)]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(w,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(Ge,{label:c(`profiles.cloudView.filters.type`),value:f,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`),count:ge},{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,$.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=>ee(e)}),Y.printers.length>0&&(0,$.jsx)(Ge,{label:c(`profiles.cloudView.filters.printer`),value:g,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...Y.printers.map(e=>({value:e.id,label:e.name}))],onChange:_}),Y.nozzles.length>0&&(0,$.jsx)(Ge,{label:c(`profiles.cloudView.filters.nozzle`),value:v,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...Y.nozzles.map(e=>({value:e,label:e}))],onChange:y}),Y.filaments.length>0&&(f===`all`||f===`filament`)&&(0,$.jsx)(Ge,{label:c(`profiles.cloudView.filters.filament`),value:x,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...Y.filaments.map(e=>({value:e,label:e}))],onChange:S}),Y.layerHeights.length>0&&(f===`all`||f===`process`)&&(0,$.jsx)(Ge,{label:c(`profiles.cloudView.filters.layer`),value:C,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...Y.layerHeights.map(e=>({value:e,label:e}))],onChange:T}),he&&(0,$.jsx)(`button`,{onClick:me,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:c(`profiles.cloudView.clearFilters`)})]})]}),B&&(0,$.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(E,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),(0,$.jsx)(`span`,{className:`text-white font-medium`,children:c(`profiles.cloudView.compareMode`)}),(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:H[0]?c(`profiles.cloudView.selectAnotherPreset`,{type:H[0].type}):c(`profiles.cloudView.clickTwoPresets`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${H[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:H[0]?H[0].name:c(`profiles.cloudView.selectFirst`)}),(0,$.jsx)(l,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${H[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:H[1]?H[1].name:c(`profiles.cloudView.selectSecond`)})]}),H[0]&&H[1]&&(0,$.jsxs)(K,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([r.getCloudSettingDetail(H[0].setting_id),r.getCloudSettingDetail(H[1].setting_id)]);W([e.setting||{},t.setting||{}]),ce(!0)}catch{}},children:[(0,$.jsx)(E,{className:`w-4 h-4`}),c(`profiles.cloudView.compareNow`)]})]})]})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(h,{className:`w-3 h-3`}),c(`profiles.cloudView.lastSynced`),` `,q(t.toISOString(),`system`,c)]}),(0,$.jsx)(`span`,{children:c(`profiles.cloudView.showingCount`,{showing:X.length,total:ge})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,$.jsxs)(`span`,{children:[`= `,c(`profiles.presets.myPreset`)]})]})]}),X.length===0?(0,$.jsxs)(`div`,{className:`text-center py-16`,children:[(0,$.jsx)(k,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:c(`profiles.cloudView.noPresetsFound`)}),he&&(0,$.jsx)(`button`,{onClick:me,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:c(`profiles.cloudView.clearFilters`)})]}):(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,$.jsx)(b,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,$.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:c(`profiles.cloudView.columns.filament`)}),(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,X.filter(e=>e.type===`filament`).length,`)`]})]}),(0,$.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[X.filter(e=>e.type===`filament`).map(e=>(0,$.jsx)(qe,{setting:e,onClick:()=>de(e),onDuplicate:()=>fe(e),compareMode:B,isCompareSelected:Q(e)!==void 0,compareIndex:Q(e),compareDisabled:B&&!!H[0]&&H[0].type!==e.type,t:c},e.setting_id)),X.filter(e=>e.type===`filament`).length===0&&(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:c(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,$.jsx)(R,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,$.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:c(`profiles.cloudView.columns.process`)}),(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,X.filter(e=>e.type===`process`).length,`)`]})]}),(0,$.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[X.filter(e=>e.type===`process`).map(e=>(0,$.jsx)(qe,{setting:e,onClick:()=>de(e),onDuplicate:()=>fe(e),compareMode:B,isCompareSelected:Q(e)!==void 0,compareIndex:Q(e),compareDisabled:B&&!!H[0]&&H[0].type!==e.type,t:c},e.setting_id)),X.filter(e=>e.type===`process`).length===0&&(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:c(`profiles.cloudView.noProcessPresets`)})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,$.jsx)(I,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,$.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:c(`profiles.cloudView.columns.printer`)}),(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,X.filter(e=>e.type===`printer`).length,`)`]})]}),(0,$.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[X.filter(e=>e.type===`printer`).map(e=>(0,$.jsx)(qe,{setting:e,onClick:()=>de(e),onDuplicate:()=>fe(e),compareMode:B,isCompareSelected:Q(e)!==void 0,compareIndex:Q(e),compareDisabled:B&&!!H[0]&&H[0].type!==e.type,t:c},e.setting_id)),X.filter(e=>e.type===`printer`).length===0&&(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:c(`profiles.cloudView.noPrinterPresets`)})]})]})]}),D&&(0,$.jsx)(Ye,{setting:D,onClose:()=>O(null),onDeleted:()=>O(null),onDuplicate:()=>fe(D),onEdit:()=>pe(D),hasPermission:s,t:c}),(A||N||L||ae)&&(0,$.jsx)(et,{onClose:()=>{j(!1),P(null),ie(null),oe(null)},initialData:L||N||(ae?{type:ae.type,name:``,base_id:``,setting:ae.setting}:void 0),allPresets:e,t:c}),te&&(0,$.jsx)(Qe,{onClose:()=>M(!1),onApply:e=>{oe({type:e.type,setting:e.settings}),M(!1)},t:c}),se&&le&&H[0]&&H[1]&&(0,$.jsx)($e,{onClose:()=>{ce(!1),W(null)},leftPreset:le[0],rightPreset:le[1],leftLabel:H[0].name,rightLabel:H[1].name,t:c})]})}function nt(){let{t:e}=n(),t=o(),{showToast:i}=ee(),{hasPermission:a}=le(),[l,u]=(0,Z.useState)(`cloud`),[d,f]=(0,Z.useState)(),{data:p,isLoading:m}=s({queryKey:[`cloudStatus`],queryFn:r.getCloudStatus}),{data:h=[]}=s({queryKey:[`printers`],queryFn:r.getPrinters}),{data:_,isLoading:v,refetch:y,dataUpdatedAt:b}=s({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),enabled:!!p?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,Z.useEffect)(()=>{b&&f(new Date(b))},[b]);let x=c({mutationFn:r.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),i(e(`profiles.toast.loggedOut`))}});return m?(0,$.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,$.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,$.jsxs)(`div`,{className:`mb-6`,children:[(0,$.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,$.jsx)(g,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,$.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,$.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,$.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,$.jsx)(g,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,$.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,$.jsx)(g,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,$.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,$.jsx)(D,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,$.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,$.jsx)(T,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),l===`cloud`&&(0,$.jsxs)($.Fragment,{children:[p?.is_authenticated&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,$.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,$.jsx)(`span`,{className:`text-white`,children:p.email}),p.region&&(0,$.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,$.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>x.mutate(),disabled:x.isPending||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,$.jsx)(M,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),p?.sign_in_expired&&(0,$.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,$.jsx)(H,{className:`w-5 h-5 shrink-0 text-yellow-400 mt-0.5`}),(0,$.jsxs)(`div`,{className:`text-sm`,children:[(0,$.jsx)(`p`,{className:`text-white font-medium`,children:e(`profiles.signInExpiredTitle`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.signInExpiredBody`)})]})]}),p?.is_authenticated?v?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(j,{className:`w-8 h-8 text-bambu-green animate-spin`})}):_?(0,$.jsx)(tt,{settings:_,lastSyncTime:d,onRefresh:()=>y(),isRefreshing:v,printers:h,hasPermission:a,t:e}):(0,$.jsxs)(`div`,{className:`text-center py-16`,children:[(0,$.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,$.jsx)(K,{onClick:()=>y(),children:e(`profiles.retry`)})]}):(0,$.jsx)(We,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),l===`orca_cloud`&&(0,$.jsx)(Be,{}),l===`local`&&(0,$.jsx)(Pe,{}),l===`kprofiles`&&(0,$.jsx)(Oe,{}),(0,$.jsx)(Ke,{})]})}export{Ge as FilterDropdown,We as LoginForm,nt as ProfilesPage};
|