| 12345 |
- <<<<<<<< HEAD:static/assets/SpoolBuddyWriteTagPage-DS4LsSVX.js
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{T as t,a as n,k as r,v as i,w as a}from"./client-MyvT0tak.js";import{u as o}from"./chunk-62JRHF6Z-CCEQZxrX.js";import{t as s}from"./useQuery-CHOG_Fbw.js";import{a as c}from"./info-B6WpRbKo.js";import{t as l}from"./chevron-right-DGzsw50-.js";import{n as u}from"./ToastContext-rCh90cji.js";import{t as d}from"./sparkles-zvq-J42L.js";import{a as f,c as p}from"./colors-D_-ITfUn.js";import{t as m}from"./useColorCatalogVersion-Dqv8GcuB.js";import{n as h}from"./currency-LmqFrzn3.js";import{n as ee}from"./useUiSettings-QPurze9x.js";import{t as g}from"./NumberInput-Dpt1IWQn.js";import{n as te}from"./index-jeq4NBcJ.js";import{n as ne,o as _,r as v,s as re,t as y}from"./AdditionalSection-37O86NZl.js";import{b as ie,c as b,f as ae,g as x,h as S,i as C,n as w,o as T,r as E,s as D,t as O,u as k}from"./utils-BJSIDVPN.js";import{n as A}from"./spoolPaint-Imx_KAjK.js";var j=e(r(),1),M=a();function oe({formData:e,printersWithCalibrations:n,selectedProfiles:r,setSelectedProfiles:i,expandedPrinters:a,setExpandedPrinters:o}){let{t:s}=t(),u=e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},f=(e,t,n)=>{let r=`${e}:${t}:${n??`null`}`,a=`${e}:${n??`null`}`;i(e=>{let t=new Set(e);if(t.has(r))t.delete(r);else{for(let e of Array.from(t)){let n=e.split(`:`);`${n[0]}:${n[2]}`===a&&t.delete(e)}t.add(r)}return t})},p=()=>{let t=new Set;for(let{printer:r,calibrations:i}of n){if(!r.connected)continue;let n=i.filter(t=>T(t,e)),a=new Map;for(let e of n){let t=`${e.extruder_id??`null`}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let[e,n]of a)if(n.length>0){let i=[...n].sort((e,t)=>t.k_value-e.k_value)[0];t.add(`${r.id}:${i.cali_idx}:${e}`)}}i(t)};if(!e.material)return(0,M.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,M.jsx)(`p`,{className:`text-bambu-gray`,children:s(`inventory.selectMaterialFirst`)})});if(n.length===0)return(0,M.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,M.jsx)(`p`,{className:`text-bambu-gray`,children:s(`inventory.noPrintersConfigured`)})});let m=n.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>T(t,e)).length:t,0),h=(e,t)=>{let n=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=r.has(n);return(0,M.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${i?`bg-bambu-green/10 border-bambu-green/30`:`bg-bambu-dark border-transparent hover:bg-bambu-dark/80`}`,children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>f(String(e.id),t.cali_idx,t.extruder_id),className:`w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green`}),(0,M.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,M.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t.nozzle_diameter&&(0,M.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[t.nozzle_diameter,`mm`]}),(0,M.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[`K=`,t.k_value.toFixed(3)]})]})]},`${t.cali_idx}-${t.extruder_id}`)};return(0,M.jsxs)(`div`,{className:`space-y-4`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,M.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[s(`inventory.matchingFilter`),`: `,e.brand||s(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||s(`inventory.anyVariant`)]}),m>0&&(0,M.jsxs)(`button`,{type:`button`,onClick:p,className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,children:[(0,M.jsx)(d,{className:`w-3.5 h-3.5`}),s(`inventory.autoSelect`),` (`,m,`)`]})]}),(0,M.jsx)(`div`,{className:`space-y-3`,children:n.map(({printer:t,calibrations:n})=>{let r=a.has(String(t.id)),i=n.filter(t=>T(t,e)),o=i.length,d=i.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),f=i.filter(e=>e.extruder_id===1),p=i.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,M.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>u(String(t.id)),className:`w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,M.jsx)(c,{className:`w-4 h-4 text-bambu-gray`}):(0,M.jsx)(l,{className:`w-4 h-4 text-bambu-gray`}),(0,M.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),o>0?(0,M.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[o,` `,s(o===1?`inventory.match`:`inventory.matches`)]}):(0,M.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:s(`inventory.noMatches`)})]}),(0,M.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${t.connected?`bg-green-500/20 text-green-500`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.connected?s(`inventory.connected`):s(`inventory.offline`)})]}),r&&(0,M.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?o===0?(0,M.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:s(`inventory.noKProfilesMatch`)}):d?(0,M.jsxs)(M.Fragment,{children:[f.length>0&&(0,M.jsxs)(`div`,{className:`space-y-2`,children:[(0,M.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.leftNozzle`)}),(0,M.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>h(t,e))})]}),p.length>0&&(0,M.jsxs)(`div`,{className:`space-y-2`,children:[(0,M.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.rightNozzle`)}),(0,M.jsx)(`div`,{className:`space-y-2`,children:p.map(e=>h(t,e))})]})]}):(0,M.jsx)(`div`,{className:`space-y-2`,children:i.map(e=>h(t,e))}):(0,M.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:s(`inventory.printerOffline`)})})]},t.id)})}),r.size>0&&(0,M.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,M.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,M.jsx)(`span`,{className:`font-semibold`,children:r.size}),` `,s(`inventory.profilesSelected`)]})})]})}function N(e){return p(e.color_name,e.rgba,e.color_name_is_synthesized)}var se=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function P(){let{t:e}=t(),r=m(),{showToast:a}=u(),{sbState:c}=o(),[l,d]=(0,j.useState)(`existing`),[f,p]=(0,j.useState)(null),[g,ne]=(0,j.useState)(``),[_,v]=(0,j.useState)(`idle`),[re,y]=(0,j.useState)(``),[ie,b]=(0,j.useState)(!1),[ae,x]=(0,j.useState)(!1),[S,C]=(0,j.useState)(null),{data:w}=s({queryKey:[`spoolman-settings`],queryFn:n.getSpoolmanSettings,staleTime:300*1e3}),T=w!==void 0,E=w?.spoolman_enabled===`true`&&!!w?.spoolman_url,{data:D=[],refetch:O}=s({queryKey:[E?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>E?n.getSpoolmanInventorySpools(!1):n.getSpools(!1),refetchInterval:1e4,enabled:T}),{device:k,devices:A,chooseDevice:oe}=te(5e3),{data:se}=ee(),P=c.deviceOnline,R=A.length>1&&A.some(e=>e.online&&e.device_id!==k?.device_id),z=(0,j.useRef)(k?.device_id);(0,j.useEffect)(()=>{z.current=k?.device_id},[k?.device_id]);let B=(0,j.useCallback)(e=>!!z.current&&!!e?.device_id&&e.device_id!==z.current,[]),le=h(se?.currency||`USD`),V=(0,j.useMemo)(()=>{let e;if(l===`existing`)e=D.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at);else if(l===`replace`)e=D.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(g){let t=g.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||N(e)?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[D,l,g,r]),H=(0,j.useCallback)(e=>{let t=e.detail;B(t)||t.sak===0&&(x(!0),C(t.tag_uid??null))},[B]);(0,j.useEffect)(()=>{x(!1),C(null)},[k?.device_id]);let U=(0,j.useCallback)(e=>{let t=e.detail;B(t)||(x(!0),C(t.tag_uid??null))},[B]),W=(0,j.useCallback)(e=>{B(e.detail)||(x(!1),C(null))},[B]),G=(0,j.useCallback)(t=>{t.detail.spool_id===f?.id&&(v(`success`),y(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),O(),setTimeout(()=>{v(`idle`),p(null),y(``)},5e3))},[f,e,O]),K=(0,j.useCallback)(t=>{let n=t.detail;n.spool_id===f?.id&&(v(`error`),y(n.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[f,e]),q=(0,j.useCallback)(t=>{let n=t.detail;if(n.spool_id===f?.id){let t=n.reason;v(`error`),y(e(t===`spoolman_not_configured`?`spoolbuddy.writeTag.linkFailedSpoolmanNotConfigured`:t===`spool_not_found`?`spoolbuddy.writeTag.linkFailedSpoolNotFound`:`spoolbuddy.writeTag.linkFailedSpoolman`)),O()}},[f,e,O]);(0,j.useEffect)(()=>(window.addEventListener(`spoolbuddy-tag-link-failed`,q),window.addEventListener(`spoolbuddy-unknown-tag`,H),window.addEventListener(`spoolbuddy-tag-matched`,U),window.addEventListener(`spoolbuddy-tag-removed`,W),window.addEventListener(`spoolbuddy-tag-written`,G),window.addEventListener(`spoolbuddy-tag-write-failed`,K),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,H),window.removeEventListener(`spoolbuddy-tag-matched`,U),window.removeEventListener(`spoolbuddy-tag-removed`,W),window.removeEventListener(`spoolbuddy-tag-written`,G),window.removeEventListener(`spoolbuddy-tag-write-failed`,K),window.removeEventListener(`spoolbuddy-tag-link-failed`,q)}),[H,U,W,G,K,q]),(0,j.useEffect)(()=>{p(null),v(`idle`),y(``),ne(``)},[l]);let J=async()=>{if(!(!f||!k)){v(`writing`),y(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await i.writeTag(k.device_id,f.id);if(e?.warnings?.length)for(let t of e.warnings)a(t,`warning`)}catch(t){v(`error`);let n=t?.status;y(n===503?e(`spoolbuddy.writeTag.spoolmanUnavailable`):n===409?e(`spoolbuddy.writeTag.linkedToAms`):e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},ue=async()=>{if(k){try{await i.cancelWrite(k.device_id)}catch{}v(`idle`),y(``)}},de=async()=>{if(!(!f||!F(f))){b(!0),v(`idle`),y(``);try{E?await n.linkTagToSpoolmanSpool(f.id,{tag_uid:``,tray_uuid:``}):await n.linkTagToSpool(f.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await O(),p(null),v(`success`),y(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{v(`idle`),y(``)},2500)}catch{v(`error`),y(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{b(!1)}}},fe=(0,j.useCallback)(e=>{p(e),v(`idle`),y(``),O()},[O]),pe=f&&P&&_!==`writing`&&_!==`success`;return(0,M.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,M.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,M.jsx)(`button`,{onClick:()=>d(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${l===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,M.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,M.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:l===`new`?(0,M.jsx)(ce,{currencySymbol:le,onCreated:fe,selectedSpool:f,spoolmanMode:E,t:e}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,M.jsx)(`input`,{type:`text`,value:g,onChange:e=>ne(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,M.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:V.length===0?(0,M.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:l===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):V.map(e=>(0,M.jsx)(I,{spool:e,selected:f?.id===e.id,showTag:l===`replace`,onClick:()=>{p(e),v(`idle`),y(``)}},e.id))})]})}),(0,M.jsxs)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:[R&&(0,M.jsxs)(`label`,{className:`w-full mb-4 text-sm text-white/60`,children:[e(`spoolbuddy.writeTag.writeWith`),(0,M.jsx)(`select`,{value:k?.device_id??``,onChange:e=>oe(e.target.value),disabled:_===`writing`,className:`mt-1 w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white`,children:A.map(t=>(0,M.jsx)(`option`,{value:t.device_id,children:t.online?t.hostname:e(`spoolbuddy.writeTag.deviceOfflineOption`,{name:t.hostname})},t.device_id))})]}),(0,M.jsx)(L,{writeStatus:_,writeMessage:re,selectedSpool:f,tagOnReader:ae,tagUid:S,deviceOnline:P,canWrite:!!pe,isReplace:l===`replace`,canUntag:l===`replace`&&!!f&&F(f),untagging:ie,onWrite:J,onUntag:de,onCancel:ue,onRetry:()=>{v(`idle`),y(``)},t:e})]})]})]})}function F(e){return!!(e.tag_uid||e.tray_uuid)}function I({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,M.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,M.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:A(e)??(e.rgba?f(e.rgba):{backgroundColor:`#666`})}),(0,M.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,M.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[N(e)&&(0,M.jsx)(`span`,{children:N(e)}),(0,M.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,M.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,M.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,M.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function ce({currencySymbol:e,onCreated:t,selectedSpool:r,spoolmanMode:i,t:a}){let{data:o=[]}=s({queryKey:[i?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>i?n.getSpoolmanInventorySpools(!0):n.getSpools(!0)}),{data:c}=ee(),[l,u]=(0,j.useState)(`simple`),[d,p]=(0,j.useState)(`filament`),[m,h]=(0,j.useState)(_),[te,T]=(0,j.useState)(!1),[P,F]=(0,j.useState)({}),[I,ce]=(0,j.useState)(!1),[L,R]=(0,j.useState)(1),[z,B]=(0,j.useState)(!1),[le,V]=(0,j.useState)(null),[H,U]=(0,j.useState)(!1),[W,G]=(0,j.useState)(!1),[K,q]=(0,j.useState)([]),[J,ue]=(0,j.useState)([]),[de,fe]=(0,j.useState)([]),[pe,me]=(0,j.useState)([]),[Y,he]=(0,j.useState)([]),[ge,_e]=(0,j.useState)(``),[ve,ye]=(0,j.useState)([]),[X,be]=(0,j.useState)([]),[xe,Se]=(0,j.useState)(new Set),[Ce,we]=(0,j.useState)(new Set);(0,j.useEffect)(()=>{ye(D())},[]),(0,j.useEffect)(()=>{let e=!1;return(async()=>{if(l===`full`){G(!0);try{let[t,r]=await Promise.allSettled([(async()=>(await n.getCloudStatus()).is_authenticated?{connected:!0,presets:await n.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await n.orcaCloudStatus()).connected?{connected:!0,presets:(await n.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let i=t.status===`fulfilled`&&t.value.connected,a=r.status===`fulfilled`&&r.value.connected,o=t.status===`fulfilled`?t.value.presets:[],s=r.status===`fulfilled`?r.value.presets:[];U(i||a),q([...o,...s])}catch{e||U(!1)}finally{e||G(!1)}n.getSpoolCatalog().then(t=>{e||me(t)}).catch(()=>void 0),n.getColorCatalog().then(t=>{e||he(t)}).catch(()=>void 0),n.getLocalPresets().then(t=>{e||ue(t.filament)}).catch(()=>void 0),n.getBuiltinFilaments().then(t=>{e||fe(t)}).catch(()=>void 0);try{let t=await n.getPrinters(),r=await Promise.all(t.map(e=>n.getPrinterStatus(e.id).catch(()=>null))),i=[];for(let e=0;e<t.length;e++){let n=t[e],a=r[e],o=a?.connected??!1,s=[];o&&(s=await E(n.id,a)),i.push({printer:{...n,connected:o},calibrations:s})}e||be(i)}catch{}}})(),()=>{e=!0}},[l]),(0,j.useEffect)(()=>{X.length>0&&we(new Set(X.map(e=>String(e.printer.id))))},[X]);let Te=(0,j.useMemo)(()=>O(K,new Set,J,de),[K,J,de]),Ee=(0,j.useMemo)(()=>C(m.slicer_filament,Te),[m.slicer_filament,Te]),De=(0,j.useMemo)(()=>{let e=w(K,J),t=Y.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[K,J,Y]),Oe=(0,j.useMemo)(()=>{let e=Y.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...ie,...e])).sort((e,t)=>e.localeCompare(t))},[Y]),Z=(0,j.useMemo)(()=>{let e=[];for(let t of Y){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of K){let n=k(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of J){let n=k(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[K,Y,J]),ke=(0,j.useMemo)(()=>{let e=new Map;for(let t of Z){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[Z]),Ae=(0,j.useMemo)(()=>{let e=new Map;for(let t of Z){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[Z]),je=(0,j.useMemo)(()=>S(De,m.brand),[De,m.brand]),Q=(0,j.useMemo)(()=>S(Oe,m.material),[Oe,m.material]),Me=(0,j.useMemo)(()=>b(je,m.material,Ae),[je,m.material,Ae]),Ne=(0,j.useMemo)(()=>b(Q,m.brand,ke),[Q,m.brand,ke]),$=(e,t)=>{h(n=>({...n,[e]:t})),e===`core_weight`&&T(!0),P[e]&&F(t=>({...t,[e]:void 0}))},Pe=e=>{ye(t=>ae(e,t))},Fe=async e=>{let t=i?n.saveSpoolmanKProfiles:n.saveSpoolKProfiles;if(xe.size===0)return;let r=[];for(let e of xe){let[t,n,i]=e.split(`:`),a=parseInt(t),o=parseInt(n),s=i===`null`?0:parseInt(i),c=X.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o&&(e.extruder_id??0)===s);e&&r.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}r.length>0&&(r=await x(r,m),await t(e,r))},Ie=async()=>{V(null);let e=re(m,l===`simple`||I);if(!e.isValid){F(e.errors),p(`filament`);return}let r=Ee?.displayName||ge||null,o={material:m.material,subtype:m.subtype||null,brand:m.brand||null,color_name:m.color_name||null,rgba:m.rgba||null,extra_colors:m.extra_colors||null,effect_type:m.effect_type||null,label_weight:m.label_weight,...i?te?{core_weight:m.core_weight}:{}:{core_weight:m.core_weight,core_weight_catalog_id:m.core_weight_catalog_id},weight_used:m.weight_used,slicer_filament:m.slicer_filament||null,slicer_filament_name:r,nozzle_temp_min:null,nozzle_temp_max:null,note:m.note||null,cost_per_kg:m.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:m.category.trim()||null,low_stock_threshold_pct:m.low_stock_threshold_pct,material_number:m.material_number.trim()||null};B(!0);try{if(L>1){let e=i?await n.bulkCreateSpoolmanInventorySpools(o,L):await n.bulkCreateSpools(o,L),r=i&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of r)await Fe(e.id);r.length>0&&t(r[0])}else{let e=i?await n.createSpoolmanInventorySpool(o):await n.createSpool(o);await Fe(e.id),t(e)}}catch{V(a(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{B(!1)}},Le=`#${(m.rgba||`808080FF`).slice(0,6)}`;return(0,M.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,M.jsx)(`span`,{className:`text-sm text-zinc-200`,children:a(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,M.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>u(`simple`),className:`px-3 py-1.5 text-xs font-medium ${l===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:a(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>u(`full`),className:`px-3 py-1.5 text-xs font-medium ${l===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:a(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),l===`simple`?r?(0,M.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,M.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:A(r,`preview`)??(r.rgba?f(r.rgba):{backgroundColor:`#666`})}),(0,M.jsxs)(`p`,{className:`text-white font-medium`,children:[r.brand?`${r.brand} `:``,r.material]}),N(r)&&(0,M.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:N(r)}),(0,M.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[r.label_weight,`g`]}),(0,M.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:a(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,M.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.material`,`Material`)}),(0,M.jsx)(`select`,{value:m.material,onChange:e=>$(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:se.map(e=>(0,M.jsx)(`option`,{value:e,children:e},e))})]}),(0,M.jsxs)(`div`,{className:`flex gap-3`,children:[(0,M.jsxs)(`div`,{className:`flex-1`,children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,M.jsx)(`input`,{type:`text`,value:m.color_name,onChange:e=>$(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.color`,`Color`)}),(0,M.jsx)(`input`,{type:`color`,value:Le,onChange:e=>$(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,M.jsx)(`input`,{type:`text`,value:m.brand,onChange:e=>$(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,M.jsx)(g,{value:m.label_weight,onChange:e=>$(`label_weight`,e),fallback:0,min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,M.jsx)(`button`,{onClick:Ie,disabled:z||!m.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:z?a(`spoolbuddy.writeTag.creating`,`Creating...`):a(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,M.jsx)(`span`,{className:`text-sm text-zinc-200`,children:a(`inventory.quickAdd`,`Quick Add`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>ce(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${I?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,M.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${I?`translate-x-6`:`translate-x-1`}`})})]}),(0,M.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,M.jsx)(`button`,{onClick:()=>p(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${d===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:a(`inventory.filamentInfoTab`,`Filament`)}),!I&&(0,M.jsx)(`button`,{onClick:()=>p(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${d===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:a(`inventory.paProfileTab`,`PA Profile`)})]}),(0,M.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:d===`filament`?(0,M.jsxs)(`div`,{className:`space-y-4`,children:[(0,M.jsx)(v,{formData:m,updateField:$,cloudAuthenticated:H,loadingCloudPresets:W,presetInputValue:ge,setPresetInputValue:_e,selectedPresetOption:Ee,filamentOptions:Te,availableBrands:je,availableMaterials:Q,suggestedBrands:Me,suggestedMaterials:Ne,quickAdd:I,detailsRequired:!I,quantity:L,onQuantityChange:R,errors:P}),(0,M.jsx)(ne,{formData:m,updateField:$,recentColors:ve,onColorUsed:Pe,catalogColors:Y}),(0,M.jsx)(y,{formData:m,updateField:$,spoolCatalog:pe,currencySymbol:e,availableCategories:Array.from(new Set(o.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),availableMaterialNumbers:Array.from(new Set(o.map(e=>e.material_number?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),globalLowStockThreshold:c?.low_stock_threshold??20,spoolmanMode:i})]}):(0,M.jsx)(oe,{formData:m,printersWithCalibrations:X,selectedProfiles:xe,setSelectedProfiles:Se,expandedPrinters:Ce,setExpandedPrinters:we})})]}),le&&(0,M.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:le}),l===`full`&&(0,M.jsx)(`button`,{onClick:Ie,disabled:z,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:z?a(`spoolbuddy.writeTag.creating`,`Creating...`):a(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),l===`full`&&r&&(0,M.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,M.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:A(r,`preview`)??(r.rgba?f(r.rgba):{backgroundColor:`#666`})}),(0,M.jsxs)(`p`,{className:`text-white font-medium`,children:[r.brand?`${r.brand} `:``,r.material]}),N(r)&&(0,M.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:N(r)}),(0,M.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[r.label_weight,`g`]}),(0,M.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:a(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function L({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:p,onRetry:m,t:h}){if(e===`success`)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,M.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,M.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,M.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,M.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,M.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.subtype?` ${n.subtype}`:``,N(n)?` - ${N(n)}`:``]})]});if(e===`error`)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,M.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,M.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,M.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,M.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,M.jsx)(`button`,{onClick:m,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:h(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,M.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,M.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,M.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,M.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,M.jsx)(R,{className:`w-8 h-8 text-bambu-green`})})]}),(0,M.jsx)(`p`,{className:`text-bambu-green font-medium`,children:h(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,M.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,M.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:h(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,M.jsx)(R,{className:`w-12 h-12 text-zinc-600`}),(0,M.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:h(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,M.jsx)(R,{className:`w-12 h-12 text-zinc-600`}),(0,M.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:h(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let ee=A(n,`preview`)??(n.rgba?f(n.rgba):{backgroundColor:`#666`});return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,M.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,M.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,M.jsx)(R,{className:`w-8 h-8 text-bambu-green`})})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,M.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,M.jsx)(R,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,M.jsxs)(`div`,{className:`space-y-1`,children:[(0,M.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:h(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,M.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,M.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:h(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,M.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,M.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:ee}),(0,M.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,M.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),N(n)&&(0,M.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:N(n)})]})]}),(0,M.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,M.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:h(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,M.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?h(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):h(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,M.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?h(`spoolbuddy.writeTag.untagging`,`Removing tag...`):h(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function R({className:e}){return(0,M.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,M.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,M.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}export{P as SpoolBuddyWriteTagPage};
- ========
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{T as t,a as n,k as r,v as i,w as a}from"./client-Bol9xAus.js";import{u as o}from"./chunk-62JRHF6Z-KKqrVMYU.js";import{t as s}from"./useQuery-VntlVx44.js";import{a as c}from"./info-DlBw4lHQ.js";import{t as l}from"./chevron-right-BWqRA8hA.js";import{n as u}from"./ToastContext-Ba_la89E.js";import{t as d}from"./sparkles-DirgrQiv.js";import{a as f,c as p}from"./colors-D_-ITfUn.js";import{t as m}from"./useColorCatalogVersion-5VMJBKdj.js";import{n as h}from"./currency-LmqFrzn3.js";import{n as ee}from"./useUiSettings-hktWVJHa.js";import{t as g}from"./NumberInput-BuS_39vU.js";import{n as te}from"./index-DFZVr91Z.js";import{n as ne,o as _,r as v,s as re,t as y}from"./AdditionalSection-DPnTarxs.js";import{b as ie,c as b,f as ae,g as x,h as S,i as C,n as w,o as T,r as E,s as D,t as O,u as k}from"./utils-V9PfQxxz.js";import{n as A}from"./spoolPaint-Imx_KAjK.js";var j=e(r(),1),M=a();function oe({formData:e,printersWithCalibrations:n,selectedProfiles:r,setSelectedProfiles:i,expandedPrinters:a,setExpandedPrinters:o}){let{t:s}=t(),u=e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},f=(e,t,n)=>{let r=`${e}:${t}:${n??`null`}`,a=`${e}:${n??`null`}`;i(e=>{let t=new Set(e);if(t.has(r))t.delete(r);else{for(let e of Array.from(t)){let n=e.split(`:`);`${n[0]}:${n[2]}`===a&&t.delete(e)}t.add(r)}return t})},p=()=>{let t=new Set;for(let{printer:r,calibrations:i}of n){if(!r.connected)continue;let n=i.filter(t=>T(t,e)),a=new Map;for(let e of n){let t=`${e.extruder_id??`null`}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let[e,n]of a)if(n.length>0){let i=[...n].sort((e,t)=>t.k_value-e.k_value)[0];t.add(`${r.id}:${i.cali_idx}:${e}`)}}i(t)};if(!e.material)return(0,M.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,M.jsx)(`p`,{className:`text-bambu-gray`,children:s(`inventory.selectMaterialFirst`)})});if(n.length===0)return(0,M.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,M.jsx)(`p`,{className:`text-bambu-gray`,children:s(`inventory.noPrintersConfigured`)})});let m=n.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>T(t,e)).length:t,0),h=(e,t)=>{let n=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=r.has(n);return(0,M.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${i?`bg-bambu-green/10 border-bambu-green/30`:`bg-bambu-dark border-transparent hover:bg-bambu-dark/80`}`,children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>f(String(e.id),t.cali_idx,t.extruder_id),className:`w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green`}),(0,M.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,M.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t.nozzle_diameter&&(0,M.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[t.nozzle_diameter,`mm`]}),(0,M.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[`K=`,t.k_value.toFixed(3)]})]})]},`${t.cali_idx}-${t.extruder_id}`)};return(0,M.jsxs)(`div`,{className:`space-y-4`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,M.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[s(`inventory.matchingFilter`),`: `,e.brand||s(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||s(`inventory.anyVariant`)]}),m>0&&(0,M.jsxs)(`button`,{type:`button`,onClick:p,className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,children:[(0,M.jsx)(d,{className:`w-3.5 h-3.5`}),s(`inventory.autoSelect`),` (`,m,`)`]})]}),(0,M.jsx)(`div`,{className:`space-y-3`,children:n.map(({printer:t,calibrations:n})=>{let r=a.has(String(t.id)),i=n.filter(t=>T(t,e)),o=i.length,d=i.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),f=i.filter(e=>e.extruder_id===1),p=i.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,M.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>u(String(t.id)),className:`w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,M.jsx)(c,{className:`w-4 h-4 text-bambu-gray`}):(0,M.jsx)(l,{className:`w-4 h-4 text-bambu-gray`}),(0,M.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),o>0?(0,M.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[o,` `,s(o===1?`inventory.match`:`inventory.matches`)]}):(0,M.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:s(`inventory.noMatches`)})]}),(0,M.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${t.connected?`bg-green-500/20 text-green-500`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.connected?s(`inventory.connected`):s(`inventory.offline`)})]}),r&&(0,M.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?o===0?(0,M.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:s(`inventory.noKProfilesMatch`)}):d?(0,M.jsxs)(M.Fragment,{children:[f.length>0&&(0,M.jsxs)(`div`,{className:`space-y-2`,children:[(0,M.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.leftNozzle`)}),(0,M.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>h(t,e))})]}),p.length>0&&(0,M.jsxs)(`div`,{className:`space-y-2`,children:[(0,M.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.rightNozzle`)}),(0,M.jsx)(`div`,{className:`space-y-2`,children:p.map(e=>h(t,e))})]})]}):(0,M.jsx)(`div`,{className:`space-y-2`,children:i.map(e=>h(t,e))}):(0,M.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:s(`inventory.printerOffline`)})})]},t.id)})}),r.size>0&&(0,M.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,M.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,M.jsx)(`span`,{className:`font-semibold`,children:r.size}),` `,s(`inventory.profilesSelected`)]})})]})}function N(e){return p(e.color_name,e.rgba,e.color_name_is_synthesized)}var se=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function P(){let{t:e}=t(),r=m(),{showToast:a}=u(),{sbState:c}=o(),[l,d]=(0,j.useState)(`existing`),[f,p]=(0,j.useState)(null),[g,ne]=(0,j.useState)(``),[_,v]=(0,j.useState)(`idle`),[re,y]=(0,j.useState)(``),[ie,b]=(0,j.useState)(!1),[ae,x]=(0,j.useState)(!1),[S,C]=(0,j.useState)(null),{data:w}=s({queryKey:[`spoolman-settings`],queryFn:n.getSpoolmanSettings,staleTime:300*1e3}),T=w!==void 0,E=w?.spoolman_enabled===`true`&&!!w?.spoolman_url,{data:D=[],refetch:O}=s({queryKey:[E?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>E?n.getSpoolmanInventorySpools(!1):n.getSpools(!1),refetchInterval:1e4,enabled:T}),{device:k,devices:A,chooseDevice:oe}=te(5e3),{data:se}=ee(),P=c.deviceOnline,R=A.length>1&&A.some(e=>e.online&&e.device_id!==k?.device_id),z=(0,j.useRef)(k?.device_id);(0,j.useEffect)(()=>{z.current=k?.device_id},[k?.device_id]);let B=(0,j.useCallback)(e=>!!z.current&&!!e?.device_id&&e.device_id!==z.current,[]),le=h(se?.currency||`USD`),V=(0,j.useMemo)(()=>{let e;if(l===`existing`)e=D.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at);else if(l===`replace`)e=D.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(g){let t=g.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||N(e)?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[D,l,g,r]),H=(0,j.useCallback)(e=>{let t=e.detail;B(t)||t.sak===0&&(x(!0),C(t.tag_uid??null))},[B]);(0,j.useEffect)(()=>{x(!1),C(null)},[k?.device_id]);let U=(0,j.useCallback)(e=>{let t=e.detail;B(t)||(x(!0),C(t.tag_uid??null))},[B]),W=(0,j.useCallback)(e=>{B(e.detail)||(x(!1),C(null))},[B]),G=(0,j.useCallback)(t=>{t.detail.spool_id===f?.id&&(v(`success`),y(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),O(),setTimeout(()=>{v(`idle`),p(null),y(``)},5e3))},[f,e,O]),K=(0,j.useCallback)(t=>{let n=t.detail;n.spool_id===f?.id&&(v(`error`),y(n.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[f,e]),q=(0,j.useCallback)(t=>{let n=t.detail;if(n.spool_id===f?.id){let t=n.reason;v(`error`),y(e(t===`spoolman_not_configured`?`spoolbuddy.writeTag.linkFailedSpoolmanNotConfigured`:t===`spool_not_found`?`spoolbuddy.writeTag.linkFailedSpoolNotFound`:`spoolbuddy.writeTag.linkFailedSpoolman`)),O()}},[f,e,O]);(0,j.useEffect)(()=>(window.addEventListener(`spoolbuddy-tag-link-failed`,q),window.addEventListener(`spoolbuddy-unknown-tag`,H),window.addEventListener(`spoolbuddy-tag-matched`,U),window.addEventListener(`spoolbuddy-tag-removed`,W),window.addEventListener(`spoolbuddy-tag-written`,G),window.addEventListener(`spoolbuddy-tag-write-failed`,K),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,H),window.removeEventListener(`spoolbuddy-tag-matched`,U),window.removeEventListener(`spoolbuddy-tag-removed`,W),window.removeEventListener(`spoolbuddy-tag-written`,G),window.removeEventListener(`spoolbuddy-tag-write-failed`,K),window.removeEventListener(`spoolbuddy-tag-link-failed`,q)}),[H,U,W,G,K,q]),(0,j.useEffect)(()=>{p(null),v(`idle`),y(``),ne(``)},[l]);let J=async()=>{if(!(!f||!k)){v(`writing`),y(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await i.writeTag(k.device_id,f.id);if(e?.warnings?.length)for(let t of e.warnings)a(t,`warning`)}catch(t){v(`error`);let n=t?.status;y(n===503?e(`spoolbuddy.writeTag.spoolmanUnavailable`):n===409?e(`spoolbuddy.writeTag.linkedToAms`):e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},ue=async()=>{if(k){try{await i.cancelWrite(k.device_id)}catch{}v(`idle`),y(``)}},de=async()=>{if(!(!f||!F(f))){b(!0),v(`idle`),y(``);try{E?await n.linkTagToSpoolmanSpool(f.id,{tag_uid:``,tray_uuid:``}):await n.linkTagToSpool(f.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await O(),p(null),v(`success`),y(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{v(`idle`),y(``)},2500)}catch{v(`error`),y(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{b(!1)}}},fe=(0,j.useCallback)(e=>{p(e),v(`idle`),y(``),O()},[O]),pe=f&&P&&_!==`writing`&&_!==`success`;return(0,M.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,M.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,M.jsx)(`button`,{onClick:()=>d(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${l===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,M.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,M.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:l===`new`?(0,M.jsx)(ce,{currencySymbol:le,onCreated:fe,selectedSpool:f,spoolmanMode:E,t:e}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,M.jsx)(`input`,{type:`text`,value:g,onChange:e=>ne(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,M.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:V.length===0?(0,M.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:l===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):V.map(e=>(0,M.jsx)(I,{spool:e,selected:f?.id===e.id,showTag:l===`replace`,onClick:()=>{p(e),v(`idle`),y(``)}},e.id))})]})}),(0,M.jsxs)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:[R&&(0,M.jsxs)(`label`,{className:`w-full mb-4 text-sm text-white/60`,children:[e(`spoolbuddy.writeTag.writeWith`),(0,M.jsx)(`select`,{value:k?.device_id??``,onChange:e=>oe(e.target.value),disabled:_===`writing`,className:`mt-1 w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white`,children:A.map(t=>(0,M.jsx)(`option`,{value:t.device_id,children:t.online?t.hostname:e(`spoolbuddy.writeTag.deviceOfflineOption`,{name:t.hostname})},t.device_id))})]}),(0,M.jsx)(L,{writeStatus:_,writeMessage:re,selectedSpool:f,tagOnReader:ae,tagUid:S,deviceOnline:P,canWrite:!!pe,isReplace:l===`replace`,canUntag:l===`replace`&&!!f&&F(f),untagging:ie,onWrite:J,onUntag:de,onCancel:ue,onRetry:()=>{v(`idle`),y(``)},t:e})]})]})]})}function F(e){return!!(e.tag_uid||e.tray_uuid)}function I({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,M.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,M.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:A(e)??(e.rgba?f(e.rgba):{backgroundColor:`#666`})}),(0,M.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,M.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[N(e)&&(0,M.jsx)(`span`,{children:N(e)}),(0,M.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,M.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,M.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,M.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function ce({currencySymbol:e,onCreated:t,selectedSpool:r,spoolmanMode:i,t:a}){let{data:o=[]}=s({queryKey:[i?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>i?n.getSpoolmanInventorySpools(!0):n.getSpools(!0)}),{data:c}=ee(),[l,u]=(0,j.useState)(`simple`),[d,p]=(0,j.useState)(`filament`),[m,h]=(0,j.useState)(_),[te,T]=(0,j.useState)(!1),[P,F]=(0,j.useState)({}),[I,ce]=(0,j.useState)(!1),[L,R]=(0,j.useState)(1),[z,B]=(0,j.useState)(!1),[le,V]=(0,j.useState)(null),[H,U]=(0,j.useState)(!1),[W,G]=(0,j.useState)(!1),[K,q]=(0,j.useState)([]),[J,ue]=(0,j.useState)([]),[de,fe]=(0,j.useState)([]),[pe,me]=(0,j.useState)([]),[Y,he]=(0,j.useState)([]),[ge,_e]=(0,j.useState)(``),[ve,ye]=(0,j.useState)([]),[X,be]=(0,j.useState)([]),[xe,Se]=(0,j.useState)(new Set),[Ce,we]=(0,j.useState)(new Set);(0,j.useEffect)(()=>{ye(D())},[]),(0,j.useEffect)(()=>{let e=!1;return(async()=>{if(l===`full`){G(!0);try{let[t,r]=await Promise.allSettled([(async()=>(await n.getCloudStatus()).is_authenticated?{connected:!0,presets:await n.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await n.orcaCloudStatus()).connected?{connected:!0,presets:(await n.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let i=t.status===`fulfilled`&&t.value.connected,a=r.status===`fulfilled`&&r.value.connected,o=t.status===`fulfilled`?t.value.presets:[],s=r.status===`fulfilled`?r.value.presets:[];U(i||a),q([...o,...s])}catch{e||U(!1)}finally{e||G(!1)}n.getSpoolCatalog().then(t=>{e||me(t)}).catch(()=>void 0),n.getColorCatalog().then(t=>{e||he(t)}).catch(()=>void 0),n.getLocalPresets().then(t=>{e||ue(t.filament)}).catch(()=>void 0),n.getBuiltinFilaments().then(t=>{e||fe(t)}).catch(()=>void 0);try{let t=await n.getPrinters(),r=await Promise.all(t.map(e=>n.getPrinterStatus(e.id).catch(()=>null))),i=[];for(let e=0;e<t.length;e++){let n=t[e],a=r[e],o=a?.connected??!1,s=[];o&&(s=await E(n.id,a)),i.push({printer:{...n,connected:o},calibrations:s})}e||be(i)}catch{}}})(),()=>{e=!0}},[l]),(0,j.useEffect)(()=>{X.length>0&&we(new Set(X.map(e=>String(e.printer.id))))},[X]);let Te=(0,j.useMemo)(()=>O(K,new Set,J,de),[K,J,de]),Ee=(0,j.useMemo)(()=>C(m.slicer_filament,Te),[m.slicer_filament,Te]),De=(0,j.useMemo)(()=>{let e=w(K,J),t=Y.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[K,J,Y]),Oe=(0,j.useMemo)(()=>{let e=Y.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...ie,...e])).sort((e,t)=>e.localeCompare(t))},[Y]),Z=(0,j.useMemo)(()=>{let e=[];for(let t of Y){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of K){let n=k(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of J){let n=k(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[K,Y,J]),ke=(0,j.useMemo)(()=>{let e=new Map;for(let t of Z){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[Z]),Ae=(0,j.useMemo)(()=>{let e=new Map;for(let t of Z){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[Z]),je=(0,j.useMemo)(()=>S(De,m.brand),[De,m.brand]),Q=(0,j.useMemo)(()=>S(Oe,m.material),[Oe,m.material]),Me=(0,j.useMemo)(()=>b(je,m.material,Ae),[je,m.material,Ae]),Ne=(0,j.useMemo)(()=>b(Q,m.brand,ke),[Q,m.brand,ke]),$=(e,t)=>{h(n=>({...n,[e]:t})),e===`core_weight`&&T(!0),P[e]&&F(t=>({...t,[e]:void 0}))},Pe=e=>{ye(t=>ae(e,t))},Fe=async e=>{let t=i?n.saveSpoolmanKProfiles:n.saveSpoolKProfiles;if(xe.size===0)return;let r=[];for(let e of xe){let[t,n,i]=e.split(`:`),a=parseInt(t),o=parseInt(n),s=i===`null`?0:parseInt(i),c=X.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o&&(e.extruder_id??0)===s);e&&r.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}r.length>0&&(r=await x(r,m),await t(e,r))},Ie=async()=>{V(null);let e=re(m,l===`simple`||I);if(!e.isValid){F(e.errors),p(`filament`);return}let r=Ee?.displayName||ge||null,o={material:m.material,subtype:m.subtype||null,brand:m.brand||null,color_name:m.color_name||null,rgba:m.rgba||null,extra_colors:m.extra_colors||null,effect_type:m.effect_type||null,label_weight:m.label_weight,...i?te?{core_weight:m.core_weight}:{}:{core_weight:m.core_weight,core_weight_catalog_id:m.core_weight_catalog_id},weight_used:m.weight_used,slicer_filament:m.slicer_filament||null,slicer_filament_name:r,nozzle_temp_min:null,nozzle_temp_max:null,note:m.note||null,cost_per_kg:m.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:m.category.trim()||null,low_stock_threshold_pct:m.low_stock_threshold_pct,material_number:m.material_number.trim()||null};B(!0);try{if(L>1){let e=i?await n.bulkCreateSpoolmanInventorySpools(o,L):await n.bulkCreateSpools(o,L),r=i&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of r)await Fe(e.id);r.length>0&&t(r[0])}else{let e=i?await n.createSpoolmanInventorySpool(o):await n.createSpool(o);await Fe(e.id),t(e)}}catch{V(a(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{B(!1)}},Le=`#${(m.rgba||`808080FF`).slice(0,6)}`;return(0,M.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,M.jsx)(`span`,{className:`text-sm text-zinc-200`,children:a(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,M.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>u(`simple`),className:`px-3 py-1.5 text-xs font-medium ${l===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:a(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>u(`full`),className:`px-3 py-1.5 text-xs font-medium ${l===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:a(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),l===`simple`?r?(0,M.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,M.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:A(r,`preview`)??(r.rgba?f(r.rgba):{backgroundColor:`#666`})}),(0,M.jsxs)(`p`,{className:`text-white font-medium`,children:[r.brand?`${r.brand} `:``,r.material]}),N(r)&&(0,M.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:N(r)}),(0,M.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[r.label_weight,`g`]}),(0,M.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:a(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,M.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.material`,`Material`)}),(0,M.jsx)(`select`,{value:m.material,onChange:e=>$(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:se.map(e=>(0,M.jsx)(`option`,{value:e,children:e},e))})]}),(0,M.jsxs)(`div`,{className:`flex gap-3`,children:[(0,M.jsxs)(`div`,{className:`flex-1`,children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,M.jsx)(`input`,{type:`text`,value:m.color_name,onChange:e=>$(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.color`,`Color`)}),(0,M.jsx)(`input`,{type:`color`,value:Le,onChange:e=>$(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,M.jsx)(`input`,{type:`text`,value:m.brand,onChange:e=>$(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,M.jsx)(g,{value:m.label_weight,onChange:e=>$(`label_weight`,e),fallback:0,min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,M.jsx)(`button`,{onClick:Ie,disabled:z||!m.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:z?a(`spoolbuddy.writeTag.creating`,`Creating...`):a(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,M.jsx)(`span`,{className:`text-sm text-zinc-200`,children:a(`inventory.quickAdd`,`Quick Add`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>ce(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${I?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,M.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${I?`translate-x-6`:`translate-x-1`}`})})]}),(0,M.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,M.jsx)(`button`,{onClick:()=>p(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${d===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:a(`inventory.filamentInfoTab`,`Filament`)}),!I&&(0,M.jsx)(`button`,{onClick:()=>p(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${d===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:a(`inventory.paProfileTab`,`PA Profile`)})]}),(0,M.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:d===`filament`?(0,M.jsxs)(`div`,{className:`space-y-4`,children:[(0,M.jsx)(v,{formData:m,updateField:$,cloudAuthenticated:H,loadingCloudPresets:W,presetInputValue:ge,setPresetInputValue:_e,selectedPresetOption:Ee,filamentOptions:Te,availableBrands:je,availableMaterials:Q,suggestedBrands:Me,suggestedMaterials:Ne,quickAdd:I,detailsRequired:!I,quantity:L,onQuantityChange:R,errors:P}),(0,M.jsx)(ne,{formData:m,updateField:$,recentColors:ve,onColorUsed:Pe,catalogColors:Y}),(0,M.jsx)(y,{formData:m,updateField:$,spoolCatalog:pe,currencySymbol:e,availableCategories:Array.from(new Set(o.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),availableMaterialNumbers:Array.from(new Set(o.map(e=>e.material_number?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),globalLowStockThreshold:c?.low_stock_threshold??20,spoolmanMode:i})]}):(0,M.jsx)(oe,{formData:m,printersWithCalibrations:X,selectedProfiles:xe,setSelectedProfiles:Se,expandedPrinters:Ce,setExpandedPrinters:we})})]}),le&&(0,M.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:le}),l===`full`&&(0,M.jsx)(`button`,{onClick:Ie,disabled:z,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:z?a(`spoolbuddy.writeTag.creating`,`Creating...`):a(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),l===`full`&&r&&(0,M.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,M.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:A(r,`preview`)??(r.rgba?f(r.rgba):{backgroundColor:`#666`})}),(0,M.jsxs)(`p`,{className:`text-white font-medium`,children:[r.brand?`${r.brand} `:``,r.material]}),N(r)&&(0,M.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:N(r)}),(0,M.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[r.label_weight,`g`]}),(0,M.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:a(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function L({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:p,onRetry:m,t:h}){if(e===`success`)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,M.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,M.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,M.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,M.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,M.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.subtype?` ${n.subtype}`:``,N(n)?` - ${N(n)}`:``]})]});if(e===`error`)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,M.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,M.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,M.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,M.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,M.jsx)(`button`,{onClick:m,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:h(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,M.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,M.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,M.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,M.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,M.jsx)(R,{className:`w-8 h-8 text-bambu-green`})})]}),(0,M.jsx)(`p`,{className:`text-bambu-green font-medium`,children:h(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,M.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,M.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:h(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,M.jsx)(R,{className:`w-12 h-12 text-zinc-600`}),(0,M.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:h(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,M.jsx)(R,{className:`w-12 h-12 text-zinc-600`}),(0,M.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:h(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let ee=A(n,`preview`)??(n.rgba?f(n.rgba):{backgroundColor:`#666`});return(0,M.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,M.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,M.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,M.jsx)(R,{className:`w-8 h-8 text-bambu-green`})})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,M.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,M.jsx)(R,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,M.jsxs)(`div`,{className:`space-y-1`,children:[(0,M.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:h(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,M.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,M.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:h(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,M.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,M.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:ee}),(0,M.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,M.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),N(n)&&(0,M.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:N(n)})]})]}),(0,M.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,M.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:h(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,M.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?h(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):h(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,M.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?h(`spoolbuddy.writeTag.untagging`,`Removing tag...`):h(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function R({className:e}){return(0,M.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,M.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,M.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}export{P as SpoolBuddyWriteTagPage};
- >>>>>>>> ea0204c3a (Post work PR #1908):static/assets/SpoolBuddyWriteTagPage-BmL-Kkvs.js
|