ProfilesPage-8GDEGaLA.js 132 KB

12345678910111213
  1. import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{C as t,T as n,a as r,k as i,t as a,w as o}from"./client-Wixdakxn.js";import{n as s}from"./QueryClientProvider-DEK0HFZS.js";import{t as c}from"./useQuery-DkJQ4hAK.js";import{t as l}from"./useMutation-C6DF_nPh.js";import{t as u}from"./arrow-right-CPB2cBg2.js";import{t as d}from"./arrow-up-BaBYmkVO.js";import{t as f}from"./check-COe945qP.js";import{a as p,i as m,r as h}from"./info-Cs6q0Q_N.js";import{n as g}from"./ToastContext-FG4Q6YJB.js";import{t as _}from"./clock-M9OLfc7b.js";import{t as v}from"./cloud-CpBSLfQ1.js";import{t as y}from"./code-DGLbGShL.js";import{t as b}from"./copy-C5VUM1CC.js";import{t as x}from"./download-CIYQYgRy.js";import{t as S}from"./droplet-B85KijsS.js";import{t as C}from"./external-link-CpoYqNMx.js";import{t as w}from"./eye-off-JHnOs927.js";import{t as T}from"./eye-DotmdMYm.js";import{t as E}from"./funnel-BeTiBRWw.js";import{t as D}from"./gauge-BaygFYlZ.js";import{t as O}from"./git-compare-BwnM3DFa.js";import{t as k}from"./hard-drive-C8AuvCFo.js";import{t as A}from"./key-DP9lXZjm.js";import{t as j}from"./layers-CK1fp1GK.js";import{t as M}from"./list-hG7kdFCu.js";import{t as N}from"./loader-circle-HWxuHTYP.js";import{t as P}from"./log-in-9sbLJwsV.js";import{t as F}from"./log-out-DEHZfwc9.js";import{t as I}from"./minus-DK1o3-UW.js";import{t as L}from"./pencil-DAgasOWC.js";import{t as R}from"./plus-U2b2Cojy.js";import{t as ee}from"./printer-iJmXXvF8.js";import{t as te}from"./refresh-cw-BALUgglx.js";import{t as z}from"./save-an2AxxYE.js";import{t as ne}from"./search-W6Qccq34.js";import{t as B}from"./settings-2-DjCtXdKz.js";import{t as re}from"./shield-alert-DhDK-8wS.js";import{t as V}from"./sparkles-CdDZgnnX.js";import{t as ie}from"./square-check-big-DfFLDmui.js";import{t as H}from"./square-BJXrnkDa.js";import{t as ae}from"./sticky-note-DvGy0XIc.js";import{t as U}from"./trash-2-BuReB2M2.js";import{t as W}from"./triangle-alert-B2iRG1RO.js";import{t as oe}from"./upload-sRQO417K.js";import{t as se}from"./wifi-off-EtDnmBfi.js";import{t as G}from"./x-vFoBjOZn.js";import{n as ce}from"./AuthContext-CtlY1WKC.js";import{n as K,t as q}from"./Card-FgTRnwUz.js";import{t as J}from"./Button-Bj3LhBE2.js";import{u as Y}from"./date-G9KUauqz.js";import{j as X}from"./amsHelpers-DDsrDUnz.js";import{u as le}from"./utils-CRm_p6_K.js";import{t as Z}from"./useCancellableTimeout-CGrjpQD3.js";var ue=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`}]]),Q=e(i(),1),fe={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 pe(e){let t=(e||``).toUpperCase().trim();return t&&(fe[t]||fe[t.replace(/[-\s]?CF$/,``)]||fe[t.replace(/\+$/,``)]||fe[t.split(/[-\s]/)[0]])||``}function me(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var he={local:0,orca_cloud:1,cloud:2,builtin:3};function ge(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=me(e.name),n=e.filament_type||le(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:pe(n),filamentType:n||``})}for(let e of n??[]){let t=me(e.name),n=le(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:pe(n),filamentType:n})}for(let e of r??[]){let t=me(e.name),n=e.setting_id.startsWith(`GFS`)?X(e,{pickedFromList:!0}):``;u(`cloud`,t,e.setting_id,n||void 0)&&a.push({id:e.setting_id,name:t,source:`cloud`,filamentId:n,filamentType:le(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:le(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):he[e.source]-he[t.source])}async function _e(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 ve(e){return e.confirmed===!1}function ye(e,t){return ve(e)?{key:`kProfiles.toast.writeUnconfirmed`,type:`warning`}:{key:t,type:`success`}}var $=o(),be=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),xe=`HS00`,Se=`HH00`,Ce=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:xe},we=e=>Ce(e)===Se?`HF`:`S`,Te=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 Ee({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=we(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)(ie,{className:`w-4 h-4 text-bambu-green`}):(0,$.jsx)(H,{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:be(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)(ae,{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)(b,{className:`w-4 h-4`})})]})}function De({profile:e,printerId:t,nozzleDiameter:i,existingProfiles:a=[],builtinFilaments:o=[],filamentPresets:s=[],isDualNozzle:c=!1,supportsFlowType:u=!0,initialNote:d=``,initialNoteKey:f=null,onClose:p,onSave:m,onSaveNote:h,hasPermission:_}){let{t:v}=n(),{showToast:y}=g(),[b,x]=(0,Q.useState)(e?.name||``),[S,C]=(0,Q.useState)(e?.k_value?be(e.k_value):`0.020`),[w,T]=(0,Q.useState)(e?.filament_id||``),[E,O]=(0,Q.useState)(e?Ce(e.nozzle_id):xe),[k,A]=(0,Q.useState)(e?.nozzle_diameter||i),[j,M]=(0,Q.useState)(e?[e.extruder_id]:c?[0,1]:[0]),[P,F]=(0,Q.useState)(!1),[I,L]=(0,Q.useState)({current:0,total:0}),[R,ee]=(0,Q.useState)(d),[te,z]=(0,Q.useState)(``),{schedule:B}=Z(),re=Q.useMemo(()=>e?.filament_id?o.find(t=>t.filament_id===e.filament_id)?.name||Te(a.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,a,o]),V=Q.useMemo(()=>{let e=[[`local`,v(`kProfiles.modal.source.local`)],[`orca_cloud`,v(`kProfiles.modal.source.orcaCloud`)],[`cloud`,v(`kProfiles.modal.source.bambuCloud`)],[`builtin`,v(`kProfiles.modal.source.builtin`)]],t=te.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,te,v]),ie=l({mutationFn:e=>(console.log(`[KProfile] Calling API...`),r.setKProfile(t,e)),onSuccess:(t,n)=>{console.log(`[KProfile] Save success:`,t);let r=ye(t,`kProfiles.toast.profileSaved`);if(y(v(r.key),r.type),h&&R!==d){let t;t=R===``&&f?f:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${b}_${n.filament_id}`,h(t,R)}F(!0),B(()=>{F(!1),m()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),y(e.message,`error`),F(!1)}}),H=l({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),r.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e);let t=ye(e,`kProfiles.toast.profileDeleted`);y(v(t.key),t.type),F(!0),B(()=>{F(!1),p()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),y(e.message,`error`),F(!1)}}),[ae,W]=(0,Q.useState)(!1),oe=()=>{e&&H.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)(q,{className:`w-full max-w-md relative`,children:[P&&(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)(N,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,$.jsx)(`p`,{className:`text-white font-medium`,children:I.total>1?v(`kProfiles.modal.savingExtruder`,{current:I.current,total:I.total}):v(`kProfiles.modal.syncing`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:v(`kProfiles.modal.pleaseWait`)})]}),(0,$.jsxs)(K,{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:v(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,$.jsx)(`button`,{onClick:p,className:`text-bambu-gray hover:text-white transition-colors`,disabled:P,children:(0,$.jsx)(G,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),c&&!e&&j.length===0){y(v(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let i=parseFloat(S).toFixed(6),a=`${E}-${k}`,o=e&&e.nozzle_id||a,l=e?e.nozzle_diameter:k,u=e?.filament_id||``;if(!e){let e=s.find(e=>e.id===w);if(!e){y(v(`kProfiles.toast.selectFilament`),`error`);return}if(u=await _e(e,r.getCloudSettingDetail),!u){y(v(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||j.length===1){let t={name:b,k_value:i,filament_id:u,nozzle_id:o,nozzle_diameter:l,extruder_id:e?e.extruder_id:j[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),ie.mutate(t);return}F(!0),L({current:1,total:j.length});let d=j.map(e=>({name:b,k_value:i,filament_id:u,nozzle_id:a,nozzle_diameter:k,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${d.length} profiles in batch:`,d);try{let e=ye(await r.setKProfilesBatch(t,d),`kProfiles.toast.profilesSaved`);y(v(e.key,{count:j.length}),e.type),h&&R&&h(`name_${b}_${u}`,R)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),y(v(`kProfiles.toast.failedToSaveBatch`),`error`),F(!1),L({current:0,total:0});return}L({current:j.length,total:j.length}),B(()=>{F(!1),L({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:v(`kProfiles.modal.profileName`)}),(0,$.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:v(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.kValue`)}),(0,$.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:S,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&C(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||C((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:v(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.kValueHelp`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`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:re||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)(ne,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,value:te,onChange:e=>z(e.target.value),placeholder:v(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:V.length===0?(0,$.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:s.length===0?v(`kProfiles.modal.noFilamentsHelp`):v(`kProfiles.modal.noFilamentMatches`)}):V.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:()=>{T(e.id),b||x(`${E===Se?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${w===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:v(`kProfiles.modal.flowType`)}),(0,$.jsxs)(`select`,{value:E,onChange:t=>{let n=t.target.value;if(O(n),!e&&w&&!b){let e=s.find(e=>e.id===w);e&&x(`${n===Se?`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:Se,children:v(`kProfiles.modal.highFlow`)}),(0,$.jsx)(`option`,{value:xe,children:v(`kProfiles.modal.standard`)})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.nozzleSize`)}),(0,$.jsxs)(`select`,{value:k,onChange:e=>A(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`})]})]})]}),c&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(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?v(`kProfiles.modal.left`):v(`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:j.includes(1),onChange:e=>{e.target.checked?M([...j,1]):M(j.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:v(`kProfiles.modal.left`)})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:j.includes(0),onChange:e=>{e.target.checked?M([...j,0]):M(j.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:v(`kProfiles.modal.right`)})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.notes`)}),(0,$.jsx)(`textarea`,{value:R,onChange:e=>ee(e.target.value),placeholder:v(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none`}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.notesHelp`)})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,$.jsx)(J,{type:`button`,variant:`secondary`,onClick:()=>W(!0),disabled:H.isPending||P||!_(`kprofiles:delete`),title:_(`kprofiles:delete`)?void 0:v(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:H.isPending?(0,$.jsx)(N,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(U,{className:`w-4 h-4`})}),(0,$.jsx)(J,{type:`button`,variant:`secondary`,onClick:p,disabled:P,className:`flex-1`,children:v(`common.cancel`)}),(0,$.jsxs)(J,{type:`submit`,disabled:ie.isPending||P||!_(e?`kprofiles:update`:`kprofiles:create`),title:_(e?`kprofiles:update`:`kprofiles:create`)?void 0:v(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[ie.isPending?(0,$.jsx)(N,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(D,{className:`w-4 h-4`}),v(`common.save`)]})]})]})]})]}),ae&&(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,$.jsx)(q,{className:`w-full max-w-sm`,children:(0,$.jsxs)(K,{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)(U,{className:`w-5 h-5 text-red-500`})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:v(`kProfiles.deleteConfirm.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:v(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,$.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:v(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,$.jsxs)(`div`,{className:`flex gap-3`,children:[(0,$.jsx)(J,{variant:`secondary`,onClick:()=>W(!1),className:`flex-1`,children:v(`common.cancel`)}),(0,$.jsxs)(J,{onClick:()=>{W(!1),oe()},disabled:H.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[H.isPending?(0,$.jsx)(N,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(U,{className:`w-4 h-4`}),v(`common.delete`)]})]})]})})})]})}var Oe={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function ke(){let{t:e}=n(),{showToast:t}=g(),{hasPermission:i}=ce(),[o,s]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(()=>localStorage.getItem(Oe.NOZZLE_DIAMETER)||`0.4`),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(`all`),[w,T]=(0,Q.useState)(`all`),[E,O]=(0,Q.useState)(()=>localStorage.getItem(Oe.SORT_OPTION)||`name`),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(new Set),[P,F]=(0,Q.useState)(!1),[I,L]=(0,Q.useState)(!1),z=(0,Q.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,Q.useEffect)(()=>{localStorage.setItem(Oe.NOZZLE_DIAMETER,l)},[l]),(0,Q.useEffect)(()=>{localStorage.setItem(Oe.SORT_OPTION,E)},[E]);let{data:B,isLoading:re}=c({queryKey:[`printers`],queryFn:r.getPrinters}),{data:V,isLoading:H,isFetching:ae,error:W,refetch:Y}=c({queryKey:[`kprofiles`,o,l],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,o,`nozzle`,l);let e=await r.getKProfiles(o,l);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!o,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:X}=c({queryKey:[`builtinFilaments`],queryFn:()=>r.getBuiltinFilaments(),staleTime:3e5}),{data:le}=c({queryKey:[`filamentIdMap`],queryFn:()=>r.getFilamentIdMap(),staleTime:3e5}),{data:Z}=c({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets(),retry:!1}),{data:ue}=c({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>r.orcaCloudListProfiles(),retry:!1}),{data:de}=c({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),retry:!1}),{data:fe,refetch:pe}=c({queryKey:[`kprofile-notes`,o],queryFn:()=>r.getKProfileNotes(o),enabled:!!o,staleTime:3e4}),me=W?.message?.includes(`not connected`),he=W instanceof a&&W.status===504;(0,Q.useEffect)(()=>{if(!o&&B&&B.length>0){let e=B.find(e=>e.is_active);e&&s(e.id)}},[o,B]),(0,Q.useEffect)(()=>{if(o){let e=setTimeout(()=>{Y()},150);return()=>clearTimeout(e)}},[o,l]);let _e=B?.filter(e=>e.is_active)||[],ye=Q.useMemo(()=>{let e=new Map;if(X)for(let t of X)e.set(t.filament_id,t.name);if(le)for(let[t,n]of Object.entries(le))e.has(t)||e.set(t,n);return e},[X,le]),be=Q.useMemo(()=>Array.from(ye.entries()).map(([e,t])=>({filament_id:e,name:t})),[ye]),Se=Q.useMemo(()=>ge({localPresets:Z?.filament,orcaProfiles:ue?.filament,cloudSettings:de?.filament,builtinFilaments:X}),[Z?.filament,ue?.filament,de?.filament,X]),Ce=Q.useCallback(e=>ye.get(e.filament_id)||Te(e.name),[ye]),we=Q.useMemo(()=>V?.profiles?V.profiles.filter(e=>{let t=y.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=S===`all`||S===`left`&&e.extruder_id===1||S===`right`&&e.extruder_id===0,i=w===`all`||w===`hf`&&e.nozzle_id.startsWith(`HH`)||w===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(E){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return Ce(e).localeCompare(Ce(t));default:return e.name.localeCompare(t.name)}}):[],[V?.profiles,y,S,w,E,Ce]),ke=B?.find(e=>e.id===o),Ae=ke?.nozzle_count===2,je=ke?.supports_nozzle_flow_type??!0;(0,Q.useEffect)(()=>{je||T(`all`)},[je]),(0,Q.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||d||p||_||(e.key===`r`||e.key===`R`?(e.preventDefault(),Y()):e.key===`n`||e.key===`N`?(e.preventDefault(),m(!0)):e.key===`Escape`&&k&&(e.preventDefault(),A(!1),M(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[d,p,_,k,Y]);let Me=(0,Q.useCallback)(()=>{if(!V?.profiles||V.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:ke?.name||`Unknown`,nozzle_diameter:l,profiles:V.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_${ke?.name||`printer`}_${l}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:V.profiles.length}))},[V?.profiles,ke,l,t,e]),Ne=(0,Q.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(),a=JSON.parse(n);if(!a.profiles||!Array.isArray(a.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0,c=0;for(let e of a.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{let t=await r.setKProfile(o,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${xe}-${l}`,nozzle_diameter:e.nozzle_diameter||l,extruder_id:e.extruder_id??0,slot_id:0});s++,ve(t)&&c++,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:a.profiles.length})),c>0&&t(e(`kProfiles.toast.writesUnconfirmed`,{count:c}),`warning`),Y()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[o,l,t,Y,e]),Pe=(0,Q.useCallback)(e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Fe=(0,Q.useCallback)(()=>{M(new Set(we.map(e=>z(e))))},[we,z]),Ie=(0,Q.useCallback)(()=>{j.size!==0&&F(!0)},[j.size]),Le=(0,Q.useCallback)(async()=>{let n=we.filter(e=>j.has(z(e)));L(!0);let i=0,a=0;for(let e of n)try{let t=await r.deleteKProfile(o,{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++,ve(t)&&a++,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})),a>0&&t(e(`kProfiles.toast.writesUnconfirmed`,{count:a}),`warning`),L(!1),F(!1),A(!1),M(new Set),Y()},[o,j,we,t,Y,z,e]),Re=(0,Q.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},[]),ze=(0,Q.useCallback)(async(n,i)=>{if(o)try{await r.setKProfileNote(o,n,i),pe()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[o,pe,t,e]),Be=(0,Q.useCallback)(e=>{if(!fe?.notes)return{note:``,key:null};let t=Re(e);for(let e of t)if(fe.notes[e])return{note:fe.notes[e],key:e};return{note:``,key:null}},[fe,Re]),Ve=(0,Q.useCallback)(e=>Be(e).note,[Be]);return re?(0,$.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,$.jsx)(N,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!B||B.length===0?(0,$.jsx)(q,{children:(0,$.jsxs)(K,{className:`py-12 text-center`,children:[(0,$.jsx)(h,{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`)})]})}):_e.length===0?(0,$.jsx)(q,{children:(0,$.jsxs)(K,{className:`py-12 text-center`,children:[(0,$.jsx)(ee,{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:[ae&&!H&&(0,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,$.jsx)(N,{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:o||``,onChange:e=>s(parseInt(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:_e.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: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 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)(J,{variant:`secondary`,onClick:()=>Y(),disabled:ae||!i(`kprofiles:read`),title:i(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,$.jsx)(te,{className:`w-4 h-4 ${ae?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,$.jsxs)(J,{onClick:()=>m(!0),disabled:!i(`kprofiles:create`),title:i(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,$.jsx)(R,{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)(ne,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,value:y,onChange:e=>b(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`})]}),Ae&&(0,$.jsx)(`div`,{className:`w-36`,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.allExtruders`)}),(0,$.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,$.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),je&&(0,$.jsx)(`div`,{className:`w-32`,children:(0,$.jsxs)(`select`,{value:w,onChange:e=>T(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white 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:E,onChange:e=>O(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,$.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)(J,{variant:`secondary`,onClick:Me,disabled:!V?.profiles?.length||!i(`kprofiles:read`),title:i(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,$.jsx)(x,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,$.jsxs)(J,{variant:`secondary`,onClick:Ne,disabled:!i(`kprofiles:create`),title:i(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,$.jsx)(oe,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,$.jsx)(`div`,{className:`flex-1`}),k?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(J,{variant:`secondary`,onClick:Fe,children:[(0,$.jsx)(ie,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,$.jsxs)(J,{variant:`secondary`,onClick:Ie,disabled:j.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)(U,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,j.size,`)`]}),(0,$.jsxs)(J,{variant:`secondary`,onClick:()=>{A(!1),M(new Set)},children:[(0,$.jsx)(G,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,$.jsxs)(J,{variant:`secondary`,onClick:()=>A(!0),disabled:!we.length||!i(`kprofiles:delete`),title:i(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,$.jsx)(ie,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),H?(0,$.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,$.jsx)(N,{className:`w-8 h-8 text-bambu-green animate-spin`})}):me?(0,$.jsx)(q,{children:(0,$.jsxs)(K,{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)(J,{variant:`secondary`,onClick:()=>Y(),children:[(0,$.jsx)(te,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):W?(0,$.jsx)(q,{children:(0,$.jsxs)(K,{className:`py-12 text-center`,children:[(0,$.jsx)(h,{className:`w-12 h-12 text-amber-700 dark:text-amber-400 mx-auto mb-4`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.readFailed`)}),(0,$.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:he?e(`kProfiles.noAnswerDesc`):W.message}),(0,$.jsxs)(J,{variant:`secondary`,onClick:()=>Y(),children:[(0,$.jsx)(te,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):we.length>0?Ae?(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:we.filter(e=>e.extruder_id===1).map(e=>(0,$.jsx)(Ee,{profile:e,onEdit:()=>f(e),onCopy:()=>v(e),selectionMode:k,isSelected:j.has(z(e)),onToggleSelect:()=>Pe(z(e)),note:Ve(e)},z(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:we.filter(e=>e.extruder_id===0).map(e=>(0,$.jsx)(Ee,{profile:e,onEdit:()=>f(e),onCopy:()=>v(e),selectionMode:k,isSelected:j.has(z(e)),onToggleSelect:()=>Pe(z(e)),note:Ve(e)},z(e)))})]})]}):(0,$.jsx)(`div`,{className:`space-y-1`,children:we.map(e=>(0,$.jsx)(Ee,{profile:e,onEdit:()=>f(e),onCopy:()=>v(e),selectionMode:k,isSelected:j.has(z(e)),onToggleSelect:()=>Pe(z(e)),note:Ve(e)},z(e)))}):y||S!==`all`||w!==`all`?(0,$.jsx)(q,{children:(0,$.jsxs)(K,{className:`py-12 text-center`,children:[(0,$.jsx)(ne,{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)(q,{children:(0,$.jsxs)(K,{className:`py-12 text-center`,children:[(0,$.jsx)(D,{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:l})}),(0,$.jsxs)(J,{onClick:()=>m(!0),children:[(0,$.jsx)(R,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),d&&o&&(()=>{let{note:e,key:t}=Be(d);return(0,$.jsx)(De,{profile:d,printerId:o,nozzleDiameter:l,existingProfiles:V?.profiles,builtinFilaments:be,filamentPresets:Se,isDualNozzle:Ae,supportsFlowType:je,initialNote:e,initialNoteKey:t,onSaveNote:ze,hasPermission:i,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),f(null),Y()},onSave:()=>{f(null),Y()}})})(),p&&o&&(0,$.jsx)(De,{printerId:o,nozzleDiameter:l,existingProfiles:V?.profiles,builtinFilaments:be,filamentPresets:Se,isDualNozzle:Ae,supportsFlowType:je,onSaveNote:ze,hasPermission:i,onClose:()=>{m(!1),Y()},onSave:()=>{m(!1),Y()}}),_&&o&&(0,$.jsx)(De,{printerId:o,nozzleDiameter:l,existingProfiles:V?.profiles,builtinFilaments:be,filamentPresets:Se,isDualNozzle:Ae,supportsFlowType:je,onSaveNote:ze,hasPermission:i,profile:{..._,slot_id:0,name:`${_.name} (Copy)`},onClose:()=>{v(null),Y()},onSave:()=>{v(null),Y()}}),P&&(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,$.jsx)(q,{className:`w-full max-w-sm`,children:(0,$.jsxs)(K,{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)(U,{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:j.size})}),(0,$.jsxs)(`div`,{className:`flex gap-3`,children:[(0,$.jsx)(J,{variant:`secondary`,onClick:()=>F(!1),disabled:I,className:`flex-1`,children:e(`common.cancel`)}),(0,$.jsxs)(J,{onClick:Le,disabled:I,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[I?(0,$.jsx)(N,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(U,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var Ae=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],je={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 Me(e){let t=e.toUpperCase();for(let e of Ae)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function Ne(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of Ae){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 Pe({preset:e,onDelete:t,onExpand:r,isExpanded:i}){let{t:a}=n(),{hasPermission:o}=ce(),s=e.filament_type||Me(e.name),c=e.filament_vendor||Ne(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=je[s.toUpperCase()]||null),(0,$.jsx)(q,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,$.jsxs)(K,{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)(U,{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)(m,{className:`w-3.5 h-3.5`}):(0,$.jsx)(p,{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 Fe(){let{t:e}=n(),{hasPermission:t}=ce(),i=s(),{showToast:a}=g(),[o,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(null),{data:y,isLoading:b}=c({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets()}),x=l({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`)}}),C=l({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`]}),v(null),a(e(`profiles.localProfiles.toast.deleted`))}}),w=(0,Q.useCallback)(e=>{!e||e.length===0||x.mutate(e)},[x]),T=(0,Q.useCallback)(e=>{e.preventDefault(),m(!1),w(e.dataTransfer.files)},[w]),E=(0,Q.useCallback)(e=>{if(!o)return e;let t=o.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[o]),D=(0,Q.useMemo)(()=>E(y?.filament||[]),[y?.filament,E]),O=(0,Q.useMemo)(()=>E(y?.printer||[]),[y?.printer,E]),A=(0,Q.useMemo)(()=>E(y?.process||[]),[y?.process,E]),M=D.length+O.length+A.length,P=(y?.filament?.length??0)+(y?.printer?.length??0)+(y?.process?.length??0)>0;return b?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(N,{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(),m(!0)},onDragLeave:()=>m(!1),onDrop:T,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=>w(e.target.files)}),x.isPending?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,$.jsx)(N,{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)(oe,{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`)})]})]}),P&&(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(ne,{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=>u(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!P&&!b&&(0,$.jsxs)(`div`,{className:`text-center py-12`,children:[(0,$.jsx)(k,{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`)})]}),P&&M===0&&!b&&(0,$.jsxs)(`div`,{className:`text-center py-12`,children:[(0,$.jsx)(ne,{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`)})]}),M>0&&(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[D.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,$.jsx)(S,{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:[`(`,D.length,`)`]})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:D.map(e=>(0,$.jsx)(Pe,{preset:e,onDelete:e=>v(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)(j,{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)(Pe,{preset:e,onDelete:e=>v(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)(B,{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)(Pe,{preset:e,onDelete:e=>v(e),onExpand:f,isExpanded:d===e.id},e.id))})]})]}),_!==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)(h,{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)(J,{variant:`secondary`,size:`sm`,onClick:()=>v(null),children:e(`profiles.localProfiles.cancel`)}),(0,$.jsxs)(J,{variant:`danger`,size:`sm`,onClick:()=>C.mutate(_),disabled:C.isPending,children:[C.isPending?(0,$.jsx)(N,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(U,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function Ie(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 Le({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(`all`),[u,d]=(0,Q.useState)(`all`),[f,p]=(0,Q.useState)(`all`),[m,h]=(0,Q.useState)(`all`),[g,v]=(0,Q.useState)(`all`),[y,b]=(0,Q.useState)(null),x=(0,Q.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:Ie(e.name)})),[e]),C=(0,Q.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]),w=(0,Q.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),T=(0,Q.useMemo)(()=>x.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!w)return!0;let t=e.meta.printer?.toLowerCase()||``,n=w.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[x,c,u,w,f,m,g,o]),D=()=>{l(`all`),d(`all`),p(`all`),h(`all`),v(`all`),s(``)},O=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,k=e.filament.length+e.printer.length+e.process.length,A=e=>T.filter(t=>t.type===e);return(0,$.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)(ne,{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)(J,{variant:`secondary`,onClick:n,disabled:r,children:[(0,$.jsx)(te,{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)(E,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(Ke,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:k},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),C.printers.length>0&&(0,$.jsx)(Ke,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),C.nozzles.length>0&&(0,$.jsx)(Ke,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.nozzles.map(e=>({value:e,label:e}))],onChange:p}),C.filaments.length>0&&(c===`all`||c===`filament`)&&(0,$.jsx)(Ke,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.filaments.map(e=>({value:e,label:e}))],onChange:h}),C.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,$.jsx)(Ke,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.layerHeights.map(e=>({value:e,label:e}))],onChange:v}),O&&(0,$.jsx)(`button`,{onClick:D,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)(_,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,Y(t.toISOString(),`system`,a)]}),(0,$.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:T.length,total:k})})]}),T.length===0?(0,$.jsxs)(`div`,{className:`text-center py-16`,children:[(0,$.jsx)(j,{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`)}),O&&(0,$.jsx)(`button`,{onClick:D,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)(Re,{icon:(0,$.jsx)(S,{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:b}),(0,$.jsx)(Re,{icon:(0,$.jsx)(B,{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:b}),(0,$.jsx)(Re,{icon:(0,$.jsx)(ee,{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:b})]}),y&&(0,$.jsx)(Be,{setting:y,onClose:()=>b(null),t:a})]})}function Re({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)(ze,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function ze({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 Be({setting:e,onClose:t,t:n}){let{data:i,isLoading:a,error:o}=c({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)(G,{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)(N,{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 Ve(){let{t:e}=n(),t=s(),{showToast:i}=g(),{hasPermission:a}=ce(),o=a(`orca_cloud:auth`),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(5e3),[m,h]=(0,Q.useState)(null),{data:_,isLoading:v}=c({queryKey:[`orcaCloudStatus`],queryFn:r.orcaCloudStatus}),y=!!_?.connected,{data:b,isLoading:x,refetch:S,isRefetching:C,error:w,dataUpdatedAt:T}=c({queryKey:[`orcaCloudProfiles`],queryFn:r.orcaCloudListProfiles,enabled:y,retry:!1,staleTime:1e3*60*5}),{data:E=[]}=c({queryKey:[`printers`],queryFn:r.getPrinters,enabled:y}),[D,O]=(0,Q.useState)();(0,Q.useEffect)(()=>{T&&O(new Date(T))},[T]);let k=()=>{d(null),p(5e3)},A=t=>{t===`access_denied`?h(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&h(e(`profiles.orcaCloud.errors.expired`)),k()},j=l({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`))}}),M=l({mutationFn:r.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),i(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:P,error:I}=c({queryKey:[`orcaCloudDevicePoll`,u?.user_code??`none`],queryFn:r.orcaCloudDevicePoll,enabled:u!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:u!==null&&f}),L=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!u||!P)return;let n=P.status;if(n===`slow_down`){p(e=>e+5e3);return}n!==`authorization_pending`&&L.current!==n&&(L.current=n,n===`complete`?(k(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),i(e(`profiles.orcaCloud.connectedShort`))):A(n))},[P,u]),(0,Q.useEffect)(()=>{u&&I&&(h(e(`profiles.orcaCloud.errors.pollFailed`)),k())},[I,u]),(0,Q.useEffect)(()=>{u&&(L.current=null)},[u]),v?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(N,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,$.jsxs)(`div`,{children:[y&&(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:_?.email?(0,$.jsxs)($.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,$.jsx)(`span`,{className:`text-white`,children:_.email})]}):(0,$.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,$.jsxs)(J,{variant:`secondary`,size:`sm`,onClick:()=>M.mutate(),disabled:M.isPending||!o,title:o?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,$.jsx)(F,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),y?x?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(N,{className:`w-8 h-8 text-bambu-green animate-spin`})}):w?(0,$.jsxs)(`div`,{className:`text-center py-16`,children:[(0,$.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:w.message}),(0,$.jsx)(J,{onClick:()=>S(),children:e(`profiles.orcaCloud.retry`)})]}):b?(0,$.jsx)(Le,{settings:b,lastSyncTime:D,onRefresh:()=>S(),isRefreshing:C,printers:E,t:e}):null:(0,$.jsx)(He,{pairing:u,connectError:m,onConnect:()=>j.mutate(),onCancel:k,isStarting:j.isPending,canManage:o,t:e})]})}function He({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,$.jsx)(q,{children:(0,$.jsxs)(K,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,$.jsx)(v,{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)(J,{className:`w-full mb-3`,children:[(0,$.jsx)(C,{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)(N,{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)(q,{children:(0,$.jsxs)(K,{className:`p-8 text-center`,children:[(0,$.jsx)(v,{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)(J,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,$.jsx)(N,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(f,{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)(h,{className:`w-4 h-4 flex-shrink-0`}),t]})]})]})})}function Ue(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 We(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function Ge({onSuccess:e,t}){let{showToast:n}=g(),[i,a]=(0,Q.useState)(`email`),[o,s]=(0,Q.useState)(``),[c,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(``),[h,_]=(0,Q.useState)(`global`),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(!1),T=l({mutationFn:()=>r.cloudLogin(o,c,h),onSuccess:r=>{if(w(r.reason===`captcha`),r.success)n(t(`profiles.login.toast.loggedIn`)),e();else if(r.reason===`captcha`)return;else r.needs_verification?(b(r.verification_type||`email`),S(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=>{w(!1),n(e.message,`error`)}}),E=l({mutationFn:()=>r.cloudVerify(o,d,x||void 0,h),onSuccess:r=>{w(r.reason===`captcha`),r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.reason!==`captcha`&&n(r.message,`error`)},onError:e=>{w(!1),n(e.message,`error`)}}),D=l({mutationFn:()=>r.cloudSetToken(p,h),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),O=e=>{e.preventDefault(),i===`email`?T.mutate():i===`code`?E.mutate():i===`token`&&D.mutate()},k=T.isPending||E.isPending||D.isPending;return(0,$.jsx)(q,{className:`max-w-md mx-auto`,children:(0,$.jsxs)(K,{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)(v,{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`)})]}),C&&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)(re,{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:()=>{w(!1),a(`token`)},className:`mt-2 text-xs text-bambu-green hover:underline flex items-center gap-1`,children:[(0,$.jsx)(A,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,$.jsxs)(`form`,{onSubmit:O,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:c,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(y===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:y===`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)(J,{type:`button`,variant:`secondary`,onClick:()=>a(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,$.jsxs)(J,{type:`submit`,disabled:k,className:`flex-1`,children:[k?(0,$.jsx)(N,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(P,{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)(A,{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)(P,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function Ke({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,Q.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)(p,{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 qe(){let[e,t]=(0,Q.useState)(!1);return(0,Q.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)(d,{className:`w-5 h-5`})}):null}function Je({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=Ue(e.name),l=We(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)(b,{className:`w-4 h-4`})})]})}function Ye(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(`
  2. `)){let t=e.replace(/\\n/g,`
  3. `).replace(/\\"/g,`"`).replace(/\\t/g,` `).split(`
  4. `);if(t.length>1)return`"""
  5. `+t.map(e=>n+` `+e).join(`
  6. `)+`
  7. `+n+`"""`}return JSON.stringify(e)}if(typeof e==`number`||typeof e==`boolean`)return String(e);if(Array.isArray(e))return e.length===0?`[]`:`[
  8. `+e.map(e=>n+` `+Ye(e,t+1)).join(`,
  9. `)+`
  10. `+n+`]`;if(typeof e==`object`){let r=Object.entries(e);return r.length===0?`{}`:`{
  11. `+r.map(([e,r])=>n+` `+JSON.stringify(e)+`: `+Ye(r,t+1)).join(`,
  12. `)+`
  13. `+n+`}`}return String(e)}function Xe({setting:e,onClose:t,onDeleted:n,onDuplicate:i,onEdit:a,hasPermission:o,t:u}){let{showToast:d}=g(),f=s(),[p,m]=(0,Q.useState)(!1),{data:h,isLoading:_}=c({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>r.getCloudSettingDetail(e.setting_id)}),v=l({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=We(e.setting_id),x=Ue(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)(q,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,$.jsxs)(K,{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}`)}),x.printer&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:`•`}),(0,$.jsx)(`span`,{children:x.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)(G,{className:`w-5 h-5`})})]}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:_?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(N,{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:Ye(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)(W,{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)(J,{variant:`secondary`,onClick:()=>m(!1),disabled:v.isPending,className:`flex-1`,children:u(`common.cancel`)}),(0,$.jsxs)(J,{variant:`danger`,onClick:()=>v.mutate(),disabled:v.isPending,className:`flex-1`,children:[v.isPending?(0,$.jsx)(N,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(U,{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)(J,{variant:`secondary`,onClick:t,className:`flex-1`,children:u(`common.close`)}),(0,$.jsxs)(J,{variant:`secondary`,onClick:i,disabled:!o(`cloud:auth`),title:o(`cloud:auth`)?void 0:u(`profiles.presets.noDuplicatePermission`),children:[(0,$.jsx)(b,{className:`w-4 h-4`}),u(`profiles.presets.duplicate`)]}),y&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(J,{variant:`secondary`,onClick:a,disabled:_||!h||!o(`cloud:auth`),title:o(`cloud:auth`)?void 0:u(`profiles.presets.noEditPermission`),children:[(0,$.jsx)(L,{className:`w-4 h-4`}),u(`common.edit`)]}),(0,$.jsx)(J,{variant:`danger`,onClick:()=>m(!0),disabled:!o(`cloud:auth`),title:o(`cloud:auth`)?void 0:u(`profiles.presets.noDeletePermission`),children:(0,$.jsx)(U,{className:`w-4 h-4`})})]})]})})]})})})}function Ze(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function Qe(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function $e({onClose:e,onApply:t,t:n}){let{showToast:r}=g(),[i,a]=(0,Q.useState)(Ze),[o,s]=(0,Q.useState)(`all`),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(`{}`),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),C=e=>{a(e),Qe(e)},E=e=>{let t=i.filter(t=>t.id!==e);C(t),b(null),r(n(`profiles.templates.toast.deleted`))},D=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),v(null)},O=()=>{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);C(t),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){v(e.message)}},k=()=>{l(null),d(``),p(``),h(`{}`),v(null)},A=e=>{let t=i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t);C(t)},j={filament:{label:n(`profiles.presets.types.filament`),icon:S,color:`text-amber-600 dark:text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:B,color:`text-blue-600 dark:text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:ee,color:`text-purple-600 dark:text-purple-400`}},M=y?i.find(e=>e.id===y):null;return(0,Q.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(y?b(null):c?k():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[y,c,e]),(0,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[M&&(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,$.jsx)(q,{className:`w-full max-w-md`,children:(0,$.jsxs)(K,{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)(W,{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:M.name})}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(J,{variant:`secondary`,onClick:()=>b(null),className:`flex-1`,children:n(`common.cancel`)}),(0,$.jsxs)(J,{onClick:()=>E(y),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,$.jsx)(U,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,$.jsx)(q,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,$.jsxs)(K,{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)(V,{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)(G,{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`):j[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)(V,{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=j[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),v(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 ${_?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),_&&(0,$.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:_})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(J,{size:`sm`,onClick:O,disabled:!u.trim(),children:[(0,$.jsx)(z,{className:`w-4 h-4`}),`Save`]}),(0,$.jsx)(J,{size:`sm`,variant:`secondary`,onClick:k,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:()=>A(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)(T,{className:`w-4 h-4`}):(0,$.jsx)(w,{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:()=>D(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,$.jsx)(L,{className:`w-4 h-4`})}),(0,$.jsx)(`button`,{onClick:()=>b(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`,title:n(`common.delete`),children:(0,$.jsx)(U,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function et({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,Q.useState)(`changes`),[c,l]=(0,Q.useState)(``),d=(0,Q.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,Q.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,Q.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,Q.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)(q,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,$.jsxs)(K,{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)(O,{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)(G,{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)(R,{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)(I,{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)(u,{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)(ue,{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)(ne,{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=>l(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)(ue,{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)(R,{className:`w-3.5 h-3.5 text-green-600 dark:text-green-400`}),removed:(0,$.jsx)(I,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400`}),changed:(0,$.jsx)(u,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),same:(0,$.jsx)(ue,{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 tt({onClose:e,initialData:t,allPresets:n,t:i}){let{showToast:a}=g(),o=s(),u=!!t?.setting_id,[d,p]=(0,Q.useState)(`common`),[m,_]=(0,Q.useState)(t?.type||`filament`),[v,b]=(0,Q.useState)(t?.name?u?t.name:`${t.name} (Copy)`:``),[S,C]=(0,Q.useState)(t?.base_id||``),[E,D]=(0,Q.useState)(``),[k,A]=(0,Q.useState)(t?.setting||{inherits:``}),[j,P]=(0,Q.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[F,I]=(0,Q.useState)(null),[L,ee]=(0,Q.useState)(``),[te,B]=(0,Q.useState)(!1),[re,ie]=(0,Q.useState)(``),[H,ae]=(0,Q.useState)(!1),[U,W]=(0,Q.useState)(Ze),[se,ce]=(0,Q.useState)(!1),[Y,X]=(0,Q.useState)(``),[le,Z]=(0,Q.useState)(``),[ue,fe]=(0,Q.useState)(!0),[pe,me]=(0,Q.useState)(null),[he,ge]=(0,Q.useState)(!1),_e=(0,Q.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[m]||[],[n,m]),ve=(0,Q.useMemo)(()=>_e.filter(e=>We(e.setting_id)),[_e]),{data:ye}=c({queryKey:[`cloudFields`,m],queryFn:()=>r.getCloudFields(m===`print`?`process`:m),staleTime:1e3*60*60}),{data:be}=c({queryKey:[`allPresetDetails`,m,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}=c({queryKey:[`cloudSettingDetail`,S],queryFn:()=>r.getCloudSettingDetail(S),enabled:!!S});(0,Q.useEffect)(()=>{d!==`json`&&P(JSON.stringify(k,null,2))},[k,d]);let Ce=(0,Q.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[m]||[]).filter(e=>!We(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,m]);(0,Q.useEffect)(()=>{if(!S)return;let e=Ce.find(e=>e.setting_id===S);e&&(D(e.name),u||(A({inherits:e.name}),P(JSON.stringify({inherits:e.name},null,2))))},[S,Ce,u]);let we=(0,Q.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(k).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,k,i]),Te=we.filter(e=>e.label.toLowerCase().includes(L.toLowerCase())||e.key.toLowerCase().includes(L.toLowerCase())),Ee=()=>{if(re.trim()){let e=re.trim().toLowerCase().replace(/\s+/g,`_`);De(e,``),ie(``),ae(!1),a(i(`profiles.presets.toast.fieldAdded`,{key:e}))}},De=(e,t)=>{A(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},Oe=e=>{A(t=>({...t,...e.settings})),me(e.name),a(i(`profiles.templates.toast.applied`))},ke=()=>{if(!Y.trim())return;let e={...k};if(delete e.inherits,Object.keys(e).length===0){a(i(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:Y.trim(),description:le.trim()||i(`profiles.presets.customTemplate`),type:m,settings:e,showInModal:ue},n=[...U,t];W(n),Qe(n),ce(!1),X(``),Z(``),fe(!0),a(i(`profiles.templates.toast.created`))},Ae=(0,Q.useMemo)(()=>U.filter(e=>e.type===m&&e.showInModal),[m,U]),je=e=>{P(e);try{let t=JSON.parse(e);A(t),I(null)}catch(e){I(e.message)}},Me=e=>{e.preventDefault(),B(!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;A(e=>({...e,...r})),P(JSON.stringify({...k,...r},null,2)),a(i(`profiles.presets.fileImported`))}catch{a(i(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},Ne=l({mutationFn:()=>{let e={...k},t=m===`filament`?`filament_settings_id`:m===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${v}"`;let n={type:m,name:v,base_id:S,setting:e};return r.createCloudSetting(n)},onSuccess:async()=>{a(i(`profiles.presets.toast.created`)),await o.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>a(e.message,`error`)}),Pe=l({mutationFn:()=>{if(!t?.setting_id)throw Error(i(`profiles.presets.noSettingId`));return r.updateCloudSetting(t.setting_id,{name:v,setting:k})},onSuccess:async()=>{a(i(`profiles.presets.toast.updated`)),o.removeQueries({queryKey:[`cloudSettingDetail`]}),await o.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}=c({queryKey:[`cloudSettingDetail`,Le?.setting_id],queryFn:()=>r.getCloudSettingDetail(Le.setting_id),enabled:!!Le?.setting_id}),ze=(0,Q.useMemo)(()=>{let e=Re?.setting||{},t=xe?.setting||{},n=S&&be?.[S]?.setting?be[S].setting:{};return{...e,...t,...n}},[S,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=k[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,Q.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(),B(!0)},onDragLeave:()=>B(!1),onDrop:Me,children:[he&&S&&(0,$.jsx)(et,{onClose:()=>ge(!1),leftPreset:He,rightPreset:k,leftLabel:i(`profiles.presets.baseLabel`,{name:E||S}),rightLabel:i(`profiles.presets.currentLabel`,{name:v||i(`profiles.presets.newPreset`)}),t:i}),(0,$.jsx)(q,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,$.jsxs)(K,{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:[S&&(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)(O,{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)(G,{className:`w-5 h-5`})})]})]}),te&&(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)(oe,{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:m,onChange:e=>{_(e.target.value),C(``)},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:S,onChange:e=>C(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,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`)})]})]}),E&&(0,$.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,$.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(f,{className:`w-3 h-3 text-bambu-green`}),i(`profiles.presets.inheritsFrom`),` `,(0,$.jsx)(`span`,{className:`text-white`,children:E}),Se&&(0,$.jsx)(N,{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 ${d===`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 ${d===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,$.jsx)(M,{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 ${d===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,$.jsx)(y,{className:`w-4 h-4`}),`JSON`,F&&(0,$.jsx)(h,{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:m,base_id:S,setting:k},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)(x,{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)(oe,{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;A(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:[d===`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)(V,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`profiles.templates.title`)]}),Object.keys(k).filter(e=>e!==`inherits`).length>0&&(0,$.jsxs)(`button`,{onClick:()=>ce(!se),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,$.jsx)(z,{className:`w-3 h-3`}),i(`profiles.presets.saveAsTemplate`)]})]}),se&&(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:Y,onChange:e=>X(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:le,onChange:e=>Z(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)(J,{size:`sm`,onClick:ke,disabled:!Y.trim(),children:[(0,$.jsx)(z,{className:`w-3 h-3`}),i(`common.save`)]}),(0,$.jsx)(J,{size:`sm`,variant:`secondary`,onClick:()=>ce(!1),children:i(`common.cancel`)})]}),(0,$.jsxs)(`button`,{onClick:()=>fe(!ue),className:`flex items-center gap-1.5 text-xs transition-colors ${ue?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[ue?(0,$.jsx)(T,{className:`w-3.5 h-3.5`}):(0,$.jsx)(w,{className:`w-3.5 h-3.5`}),i(ue?`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)(f,{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)(G,{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(k).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(k).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)(G,{className:`w-3 h-3`})})]},e))})]})]}),d===`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)(ne,{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=>ee(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 k)).map(e=>{let t=ze[e.key],n=Be(t);return(0,$.jsxs)(`div`,{onClick:()=>{A(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,$.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)(R,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),Te.filter(e=>!(e.key in k)).length===0&&(0,$.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:i(L?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,$.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:H?(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,value:re,onChange:e=>ie(e.target.value),onKeyDown:e=>e.key===`Enter`&&Ee(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,$.jsx)(J,{size:`sm`,onClick:Ee,disabled:!re.trim(),children:(0,$.jsx)(R,{className:`w-4 h-4`})}),(0,$.jsx)(J,{size:`sm`,variant:`secondary`,onClick:()=>{ae(!1),ie(``)},children:(0,$.jsx)(G,{className:`w-4 h-4`})})]}):(0,$.jsxs)(`button`,{onClick:()=>ae(!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)(R,{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(k).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(k).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)(G,{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(k).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(k).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:()=>{ce(!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)(z,{className:`w-4 h-4`}),i(`profiles.presets.saveAsTemplate`)]})})]})]}),d===`json`&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[F&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,$.jsx)(h,{className:`w-4 h-4`}),F]}),(0,$.jsx)(`textarea`,{value:j,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 ${F?`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)(J,{variant:`secondary`,onClick:e,className:`flex-1`,children:i(`common.cancel`)}),(0,$.jsxs)(J,{onClick:()=>Fe.mutate(),disabled:Fe.isPending||!v.trim()||!u&&!S||!!F,className:`flex-1`,children:[Fe.isPending?(0,$.jsx)(N,{className:`w-4 h-4 animate-spin`}):u?(0,$.jsx)(z,{className:`w-4 h-4`}):(0,$.jsx)(R,{className:`w-4 h-4`}),i(u?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function nt({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:i,printers:a,hasPermission:o,t:c}){let[l,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(`all`),[m,h]=(0,Q.useState)(`all`),[g,v]=(0,Q.useState)(`all`),[y,b]=(0,Q.useState)(`all`),[x,C]=(0,Q.useState)(`all`),[w,T]=(0,Q.useState)(`all`),[D,k]=(0,Q.useState)(null),[A,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)(null),[L,z]=(0,Q.useState)(null),[re,ie]=(0,Q.useState)(null),[H,ae]=(0,Q.useState)(!1),[U,W]=(0,Q.useState)([null,null]),[oe,se]=(0,Q.useState)(!1),[G,ce]=(0,Q.useState)(null),K=s(),q=(0,Q.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:Ue(e.name)})),[e]),X=(0,Q.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return q.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))}},[q,a]),le=(0,Q.useMemo)(()=>g===`all`?null:a.find(e=>e.id.toString()===g)?.model||null,[g,a]),Z=(0,Q.useMemo)(()=>q.filter(e=>f===`all`||e.type===f).filter(e=>{if(m===`all`)return!0;let t=We(e.setting_id);return m===`custom`?t:!t}).filter(e=>{if(g===`all`||!le)return!0;let t=e.meta.printer?.toLowerCase()||``,n=le.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>y===`all`||e.meta.nozzle===y).filter(e=>x===`all`||e.meta.filamentType===x).filter(e=>w===`all`||e.meta.layerHeight===w).filter(e=>l===``||e.name.toLowerCase().includes(l.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[q,f,m,g,le,y,x,w,l]),ue=e=>{if(H){let t=U[0]?.setting_id===e.setting_id,n=U[1]?.setting_id===e.setting_id;if(t)W([U[1],null]);else if(n)W([U[0],null]);else if(!U[0])W([e,null]);else if(U[1]){if(U[0].type!==e.type)return;W([U[0],e])}else{if(U[0].type!==e.type)return;W([U[0],e])}}else k(e)},de=e=>{if(U[0]?.setting_id===e.setting_id)return 0;if(U[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;I({type:n,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),k(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},pe=async e=>{try{K.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await r.getCloudSettingDetail(e.setting_id),n=e.type===`process`?`print`:e.type;z({type:n,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),k(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},me=()=>{p(`all`),h(`all`),v(`all`),b(`all`),C(`all`),T(`all`),d(``)},he=f!==`all`||m!==`all`||g!==`all`||y!==`all`||x!==`all`||w!==`all`||l!==``,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)(ne,{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=>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)(J,{variant:H?`primary`:`secondary`,onClick:()=>{H?(ae(!1),W([null,null])):ae(!0)},children:[(0,$.jsx)(O,{className:`w-4 h-4`}),c(H?`common.cancel`:`profiles.presets.compare`)]}),(0,$.jsxs)(J,{variant:`secondary`,onClick:()=>P(!0),disabled:!o(`cloud:auth`),title:o(`cloud:auth`)?void 0:c(`profiles.cloudView.noTemplatesPermission`),children:[(0,$.jsx)(V,{className:`w-4 h-4`}),c(`profiles.cloudView.templates`)]}),(0,$.jsxs)(J,{variant:`secondary`,onClick:n,disabled:i||!o(`cloud:auth`),title:o(`cloud:auth`)?void 0:c(`profiles.cloudView.noRefreshPermission`),children:[(0,$.jsx)(te,{className:`w-4 h-4 ${i?`animate-spin`:``}`}),c(`profiles.cloudView.refresh`)]}),(0,$.jsxs)(J,{onClick:()=>M(!0),disabled:!o(`cloud:auth`),title:o(`cloud:auth`)?void 0:c(`profiles.cloudView.noCreatePermission`),children:[(0,$.jsx)(R,{className:`w-4 h-4`}),c(`profiles.cloudView.newPreset`)]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(E,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(Ke,{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)(Ke,{label:c(`profiles.cloudView.filters.owner`),value:m,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},{value:`custom`,label:c(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:c(`profiles.cloudView.filters.builtIn`)}],onChange:e=>h(e)}),X.printers.length>0&&(0,$.jsx)(Ke,{label:c(`profiles.cloudView.filters.printer`),value:g,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...X.printers.map(e=>({value:e.id,label:e.name}))],onChange:v}),X.nozzles.length>0&&(0,$.jsx)(Ke,{label:c(`profiles.cloudView.filters.nozzle`),value:y,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...X.nozzles.map(e=>({value:e,label:e}))],onChange:b}),X.filaments.length>0&&(f===`all`||f===`filament`)&&(0,$.jsx)(Ke,{label:c(`profiles.cloudView.filters.filament`),value:x,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...X.filaments.map(e=>({value:e,label:e}))],onChange:C}),X.layerHeights.length>0&&(f===`all`||f===`process`)&&(0,$.jsx)(Ke,{label:c(`profiles.cloudView.filters.layer`),value:w,options:[{value:`all`,label:c(`profiles.cloudView.filters.all`)},...X.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`)})]})]}),H&&(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)(O,{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:U[0]?c(`profiles.cloudView.selectAnotherPreset`,{type:U[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] ${U[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:U[0]?U[0].name:c(`profiles.cloudView.selectFirst`)}),(0,$.jsx)(u,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${U[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:U[1]?U[1].name:c(`profiles.cloudView.selectSecond`)})]}),U[0]&&U[1]&&(0,$.jsxs)(J,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([r.getCloudSettingDetail(U[0].setting_id),r.getCloudSettingDetail(U[1].setting_id)]);ce([e.setting||{},t.setting||{}]),se(!0)}catch{}},children:[(0,$.jsx)(O,{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)(_,{className:`w-3 h-3`}),c(`profiles.cloudView.lastSynced`),` `,Y(t.toISOString(),`system`,c)]}),(0,$.jsx)(`span`,{children:c(`profiles.cloudView.showingCount`,{showing:Z.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`)]})]})]}),Z.length===0?(0,$.jsxs)(`div`,{className:`text-center py-16`,children:[(0,$.jsx)(j,{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)(S,{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:[`(`,Z.filter(e=>e.type===`filament`).length,`)`]})]}),(0,$.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[Z.filter(e=>e.type===`filament`).map(e=>(0,$.jsx)(Je,{setting:e,onClick:()=>ue(e),onDuplicate:()=>fe(e),compareMode:H,isCompareSelected:de(e)!==void 0,compareIndex:de(e),compareDisabled:H&&!!U[0]&&U[0].type!==e.type,t:c},e.setting_id)),Z.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)(B,{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:[`(`,Z.filter(e=>e.type===`process`).length,`)`]})]}),(0,$.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[Z.filter(e=>e.type===`process`).map(e=>(0,$.jsx)(Je,{setting:e,onClick:()=>ue(e),onDuplicate:()=>fe(e),compareMode:H,isCompareSelected:de(e)!==void 0,compareIndex:de(e),compareDisabled:H&&!!U[0]&&U[0].type!==e.type,t:c},e.setting_id)),Z.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)(ee,{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:[`(`,Z.filter(e=>e.type===`printer`).length,`)`]})]}),(0,$.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[Z.filter(e=>e.type===`printer`).map(e=>(0,$.jsx)(Je,{setting:e,onClick:()=>ue(e),onDuplicate:()=>fe(e),compareMode:H,isCompareSelected:de(e)!==void 0,compareIndex:de(e),compareDisabled:H&&!!U[0]&&U[0].type!==e.type,t:c},e.setting_id)),Z.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)(Xe,{setting:D,onClose:()=>k(null),onDeleted:()=>k(null),onDuplicate:()=>fe(D),onEdit:()=>pe(D),hasPermission:o,t:c}),(A||F||L||re)&&(0,$.jsx)(tt,{onClose:()=>{M(!1),I(null),z(null),ie(null)},initialData:L||F||(re?{type:re.type,name:``,base_id:``,setting:re.setting}:void 0),allPresets:e,t:c}),N&&(0,$.jsx)($e,{onClose:()=>P(!1),onApply:e=>{ie({type:e.type,setting:e.settings}),P(!1)},t:c}),oe&&G&&U[0]&&U[1]&&(0,$.jsx)(et,{onClose:()=>{se(!1),ce(null)},leftPreset:G[0],rightPreset:G[1],leftLabel:U[0].name,rightLabel:U[1].name,t:c})]})}function rt(){let{t:e}=n(),t=s(),{showToast:i}=g(),{hasPermission:a}=ce(),[o,u]=(0,Q.useState)(`cloud`),[d,f]=(0,Q.useState)(),{data:p,isLoading:m}=c({queryKey:[`cloudStatus`],queryFn:r.getCloudStatus}),{data:h=[]}=c({queryKey:[`printers`],queryFn:r.getPrinters}),{data:_,isLoading:y,refetch:b,dataUpdatedAt:x}=c({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),enabled:!!p?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,Q.useEffect)(()=>{x&&f(new Date(x))},[x]);let S=l({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)(N,{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)(v,{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 ${o===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,$.jsx)(v,{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 ${o===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,$.jsx)(v,{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 ${o===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,$.jsx)(k,{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 ${o===`kprofiles`?`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.kprofiles`)]})]}),o===`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)(J,{variant:`secondary`,size:`sm`,onClick:()=>S.mutate(),disabled:S.isPending||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,$.jsx)(F,{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)(W,{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?y?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,$.jsx)(N,{className:`w-8 h-8 text-bambu-green animate-spin`})}):_?(0,$.jsx)(nt,{settings:_,lastSyncTime:d,onRefresh:()=>b(),isRefreshing:y,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)(J,{onClick:()=>b(),children:e(`profiles.retry`)})]}):(0,$.jsx)(Ge,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),o===`orca_cloud`&&(0,$.jsx)(Ve,{}),o===`local`&&(0,$.jsx)(Fe,{}),o===`kprofiles`&&(0,$.jsx)(ke,{}),(0,$.jsx)(qe,{})]})}export{Ke as FilterDropdown,Ge as LoginForm,rt as ProfilesPage};