Files
bambuddy/static/assets/QueuePage-B1qiE47g.js
T

16 lines
108 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-D0Q3EIO2.js";import{n as o}from"./QueryClientProvider-CsMjD-7g.js";import{t as s}from"./useQuery-DGJURrv0.js";import{t as c}from"./useMutation-D33XgzjB.js";import{t as l}from"./useQueries-pOASHEMB.js";import{t as u}from"./createLucideIcon-BTg337Gy.js";import{t as d}from"./arrow-down--cYuQXi2.js";import{t as f}from"./arrow-up-DAnOQUuf.js";import{a as p,c as m,d as h,f as g,h as _,i as v,l as y,m as b,o as x,p as S,s as ee,t as C,u as te}from"./sortable.esm-CqmZlm2j.js";import{t as w}from"./calendar-CLfoE-ho.js";import{t as ne}from"./check-lecuNcPc.js";import{a as T,i as re,n as E,r as D}from"./info-CYfZ08vK.js";import{n as O,r as k}from"./ToastContext-DvXi5snE.js";import{t as A}from"./coins-dkDEbZk6.js";import{t as j}from"./funnel-CWTiFjnt.js";import{t as M}from"./grip-vertical-iJJ1m5OL.js";import{t as ie}from"./list-B4oui0np.js";import{t as ae}from"./loader-circle-sObvdo_1.js";import{t as N}from"./package-C-zqQjgX.js";import{t as P}from"./pause-D7Vlzoxb.js";import{t as oe}from"./play-DLt8R88D.js";import{t as F}from"./skip-forward-y25qUi6M.js";import{t as I}from"./timer-Di1tolih.js";import{t as L}from"./triangle-alert-boCB5mQC.js";import{t as se}from"./workflow-DTtmvlmi.js";import{t as ce}from"./x-B8rbip0P.js";import{t as le}from"./Card-Bs7yK0-y.js";import{t as R}from"./Button-BAwcIdV7.js";import{c as ue,o as de,u as fe,v as z}from"./date-G9KUauqz.js";import{$t as pe,A as me,At as he,Cn as ge,En as _e,Gt as B,H as ve,Jt as ye,Kt as V,Lt as be,Mn as xe,On as H,Ot as Se,Rn as Ce,Rt as we,T as U,W,Yt as Te,_t as Ee,at as De,b as Oe,cn as ke,ct as G,jn as Ae,jt as je,mn as Me,on as Ne,w as K,wt as Pe,xn as Fe,yt as Ie}from"./index-C-0w3pwY.js";import{t as Le}from"./queueItemName-UFY7kpjG.js";var Re=u(`chart-no-axes-gantt`,[[`path`,{d:`M6 5h12`,key:`fvfigv`}],[`path`,{d:`M4 12h10`,key:`oujl3d`}],[`path`,{d:`M12 19h8`,key:`baeox8`}]]),ze=u(`circle-play`,[[`path`,{d:`M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z`,key:`kmsa83`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Be=u(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),Ve=u(`package-open`,[[`path`,{d:`M12 22v-9`,key:`x3hkom`}],[`path`,{d:`M15.17 2.21a1.67 1.67 0 0 1 1.63 0L21 4.57a1.93 1.93 0 0 1 0 3.36L8.82 14.79a1.655 1.655 0 0 1-1.64 0L3 12.43a1.93 1.93 0 0 1 0-3.36z`,key:`2ntwy6`}],[`path`,{d:`M20 13v3.87a2.06 2.06 0 0 1-1.11 1.83l-6 3.08a1.93 1.93 0 0 1-1.78 0l-6-3.08A2.06 2.06 0 0 1 4 16.87V13`,key:`1pmm1c`}],[`path`,{d:`M21 12.43a1.93 1.93 0 0 0 0-3.36L8.83 2.2a1.64 1.64 0 0 0-1.63 0L3 4.57a1.93 1.93 0 0 0 0 3.36l12.18 6.86a1.636 1.636 0 0 0 1.63 0z`,key:`12ttoo`}]]),He=u(`snail`,[[`path`,{d:`M2 13a6 6 0 1 0 12 0 4 4 0 1 0-8 0 2 2 0 0 0 4 0`,key:`hneq2s`}],[`circle`,{cx:`10`,cy:`13`,r:`8`,key:`194lz3`}],[`path`,{d:`M2 21h12c4.4 0 8-3.6 8-8V7a2 2 0 1 0-4 0v6`,key:`ixqyt7`}],[`path`,{d:`M18 3 19.1 5.2`,key:`9tjm43`}],[`path`,{d:`M22 3 20.9 5.2`,key:`j3odrs`}]]),Ue=u(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]),q=e(n(),1),J=t(),We=[``,`queued`,`slicing`,`dispatching`,`in_progress`,`completed`,`partial_failure`,`failed`,`cancelled`],Y=25;function Ge(){let{t:e}=a(),t=o(),{showToast:n}=O(),[i,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(0),[g,_]=(0,q.useState)(new Set),[v,y]=(0,q.useState)(!1),{data:b}=s({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:x}=s({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),S=(x??[]).reduce((e,t)=>(e[t.id]=t,e),{}),ee=f.startsWith(`p:`)?parseInt(f.slice(2),10):void 0,C=f.startsWith(`c:`)?f.slice(2):void 0,{data:te,isLoading:w}=s({queryKey:[`pipeline-runs-all`,i,u,m,f],queryFn:()=>r.listAllPipelineRuns({limit:Y,offset:m,pipelineId:u??void 0,status:i||void 0,targetPrinterId:ee,targetModelClass:C}),refetchInterval:15e3}),ne=c({mutationFn:e=>r.cancelPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.cancelled`,`Run cancelled`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.cancelFailed`,`Cancel failed`),`error`)}),T=c({mutationFn:e=>r.retryFailedPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.retryStarted`,`Retry started`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.retryFailed`,`Retry failed`),`error`)}),re=c({mutationFn:()=>r.clearTerminalPipelineRuns(),onSuccess:r=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),y(!1),h(0),n(e(`pipelineRuns.toast.cleared`,`{{n}} runs cleared`,{n:r.deleted}),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.clearFailed`,`Clear failed`),`error`)}),E=te?.runs??[],D=te?.total??0,k=(b?.pipelines??[]).reduce((e,t)=>(e[t.id]=t,e),{}),A=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!(i||u!==null||f),ie=(()=>{let e=new Set,t=new Set;for(let n of b?.pipelines??[])n.target_kind===`printer_class`&&n.target_model_class?t.add(n.target_model_class):n.target_printer_id&&e.add(n.target_printer_id);return{printers:(x??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort()}})();return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),"aria-label":e(`common.refresh`,`Refresh`),title:e(`common.refresh`,`Refresh`),className:`p-1.5 text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(qe,{icon:(0,J.jsx)(se,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.pipeline`,`Pipeline`),value:u===null?``:String(u),onChange:e=>{h(0),d(e?parseInt(e,10):null)},options:[{value:``,label:e(`pipelineRuns.filter.allPipelines`,`All pipelines`)},...(b?.pipelines??[]).map(e=>({value:String(e.id),label:e.name}))]}),(0,J.jsx)(qe,{icon:(0,J.jsx)(j,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.status`,`Status`),value:i,onChange:e=>{h(0),l(e)},options:We.map(t=>({value:t,label:t===``?e(`pipelineRuns.filter.allStatus`,`All statuses`):e(`settings.pipelines.runs.status.${t}`,t)}))}),(ie.printers.length>0||ie.classes.length>0)&&(0,J.jsx)(qe,{icon:(0,J.jsx)(ye,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.target`,`Target`),value:f,onChange:e=>{h(0),p(e)},options:[{value:``,label:e(`pipelineRuns.filter.allTargets`,`All targets`)},...ie.printers.map(t=>({value:`p:${t.id}`,label:t.name,group:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)})),...ie.classes.map(t=>({value:`c:${t}`,label:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t}),group:e(`settings.pipelines.field.targetKindClass`,`Printer class`)}))]}),M&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>{l(``),d(null),p(``),h(0)},className:`text-xs text-bambu-gray hover:text-white`,children:e(`pipelineRuns.filter.clear`,`Clear filters`)}),(0,J.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 text-xs text-bambu-gray`,children:[!w&&D>0&&(0,J.jsx)(`span`,{children:e(`pipelineRuns.totalCount`,`{{n}} run`,{n:D,count:D})}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>y(!0),disabled:D===0,className:`flex items-center gap-1 px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,J.jsx)(he,{className:`w-3 h-3`}),e(`pipelineRuns.clearLog`,`Clear log`)]})]})]}),v&&(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:()=>y(!1),role:`dialog`,"aria-modal":`true`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md p-4`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,J.jsx)(he,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),e(`pipelineRuns.clearConfirmTitle`,`Clear log?`)]}),(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`pipelineRuns.clearConfirmBody`,`Delete every completed, failed, cancelled, and partial-failure pipeline run? In-flight runs are kept. This cannot be undone.`)}),(0,J.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-4`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>y(!1),disabled:re.isPending,className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white`,children:e(`common.cancel`,`Cancel`)}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>re.mutate(),disabled:re.isPending,className:`px-3 py-1.5 text-sm bg-red-500 hover:bg-red-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[re.isPending?(0,J.jsx)(ae,{className:`w-3.5 h-3.5 animate-spin`}):(0,J.jsx)(he,{className:`w-3.5 h-3.5`}),e(`pipelineRuns.clearConfirmAction`,`Clear`)]})]})]})}),w&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,J.jsx)(ae,{className:`w-4 h-4 animate-spin`}),e(`pipelineRuns.loading`,`Loading…`)]}),!w&&E.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:M?e(`pipelineRuns.filter.noMatches`,`No runs match the current filters.`):e(`pipelineRuns.empty`,`No pipeline runs yet.`)}),!w&&E.length>0&&(0,J.jsx)(`div`,{className:`space-y-1.5`,children:E.map(e=>(0,J.jsx)(Ke,{run:e,pipeline:e.pipeline_id?k[e.pipeline_id]:void 0,printersById:S,expanded:g.has(e.id),onToggle:()=>A(e.id),onCancel:()=>ne.mutate(e.id),onRetry:()=>T.mutate(e.id),cancelling:ne.isPending,retrying:T.isPending},e.id))}),!w&&D>Y&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between mt-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(Math.max(0,m-Y)),disabled:m===0,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.previous`,`Previous`)}),(0,J.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e(`pipelineRuns.pagination`,`{{start}}–{{end}} of {{total}}`,{start:m+1,end:Math.min(m+Y,D),total:D})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(m+Y),disabled:m+Y>=D,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.next`,`Next`)})]})]})}function Ke({run:e,pipeline:t,printersById:n,expanded:r,onToggle:i,onCancel:o,onRetry:s,cancelling:c,retrying:l}){let{t:u}=a(),d=[`queued`,`slicing`,`dispatching`,`in_progress`].includes(e.status),f=e.status===`partial_failure`||e.status===`failed`,p=e.status===`cancelled`&&e.error_message===`Cancelled by user`,m=e.target_kind===`printer_class`&&e.target_model_class?u(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):e.target_printer_id&&n[e.target_printer_id]?n[e.target_printer_id].name:null;return(0,J.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:i,"aria-label":r?u(`common.collapse`,`Collapse`):u(`common.expand`,`Expand`),"aria-expanded":r,className:`text-bambu-gray hover:text-white flex-shrink-0`,children:r?(0,J.jsx)(T,{className:`w-4 h-4`}):(0,J.jsx)(xe,{className:`w-4 h-4`})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm`,children:[(0,J.jsxs)(`span`,{className:`font-medium text-white`,children:[`#`,e.id]}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:t?.name??e.pipeline_name??`—`}),(0,J.jsx)(X,{status:e.status}),m&&(0,J.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray flex items-center gap-1`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),m]}),e.parent_run_id&&(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray/70 italic`,children:u(`pipelineRuns.retryOf`,`retry of #{{n}}`,{n:e.parent_run_id})})]}),e.source_filename&&(0,J.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-xs text-bambu-gray min-w-0`,children:[(0,J.jsx)(Fe,{className:`w-3 h-3 flex-shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,title:e.source_filename,children:e.source_filename})]}),(0,J.jsxs)(`div`,{className:`mt-0.5 text-xs text-bambu-gray/70 flex flex-wrap items-center gap-x-2`,children:[(0,J.jsx)(`span`,{children:new Date(e.created_at).toLocaleString()}),e.copies>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{children:u(`pipelineRuns.copies`,`{{n}} copies`,{n:e.copies})})]}),(e.copies_completed>0||e.copies_failed>0||e.copies_cancelled>0)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`span`,{className:`text-bambu-green`,children:e.copies_completed}),`/`,e.copies]}),e.copies_failed>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:u(`pipelineRuns.failedCount`,`{{n}} failed`,{n:e.copies_failed})})]})]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[d&&(0,J.jsxs)(`button`,{type:`button`,onClick:o,disabled:c,"aria-label":u(`common.cancel`,`Cancel`),className:`text-xs px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(ce,{className:`w-3 h-3`}),u(`common.cancel`,`Cancel`)]}),f&&(0,J.jsxs)(`button`,{type:`button`,onClick:s,disabled:l,"aria-label":u(`pipelineRuns.retryFailed`,`Retry failed`),className:`text-xs px-2 py-1 text-bambu-green hover:bg-bambu-green/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(B,{className:`w-3 h-3`}),u(`pipelineRuns.retryFailed`,`Retry failed`)]})]})]}),r&&(0,J.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary px-3 py-2 bg-bambu-dark/30`,children:[(0,J.jsx)(`div`,{className:`space-y-1.5`,children:e.jobs.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/60 w-14 flex-shrink-0`,children:u(`pipelineRuns.copyN`,`Copy {{n}}`,{n:e.copy_index+1})}),(0,J.jsx)(Je,{status:e.status}),e.assigned_printer_name&&(0,J.jsxs)(`span`,{className:`text-bambu-gray flex items-center gap-1 truncate`,children:[(0,J.jsx)(ye,{className:`w-3 h-3 text-bambu-gray/60`}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:e.assigned_printer_name})]}),e.error_message&&(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400 truncate`,title:e.error_message,children:e.error_message})]},e.id))}),e.error_message&&!p&&(0,J.jsx)(`div`,{className:`text-xs text-red-700 dark:text-red-400 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:e.error_message}),p&&(0,J.jsx)(`div`,{className:`text-xs text-bambu-gray/70 mt-2 pt-2 border-t border-bambu-dark-tertiary italic`,children:u(`pipelineRuns.cancelledByUser`,`Cancelled by user`)})]})]})}function X({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide whitespace-nowrap ${{queued:`bg-slate-700 text-slate-200`,slicing:`bg-sky-700 text-sky-100`,dispatching:`bg-sky-700 text-sky-100`,in_progress:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,partial_failure:`bg-amber-700 text-amber-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`settings.pipelines.runs.status.${e}`,e)})}function qe({value:e,onChange:t,options:n,icon:r,ariaLabel:i}){let[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=n.find(t=>t.value===e),l=[];for(let e of n){let t=l[l.length-1];t&&t.group===e.group?t.options.push(e):l.push({group:e.group,options:[e]})}return(0,J.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":i,"aria-haspopup":`listbox`,"aria-expanded":a,className:`flex items-center gap-1.5 px-2 py-1 border border-bambu-dark-tertiary rounded bg-bambu-dark/40 text-xs text-white hover:border-bambu-gray/60 focus:outline-none focus:ring-1 focus:ring-bambu-green/40`,children:[r,(0,J.jsx)(`span`,{className:`truncate max-w-[14rem]`,children:c?.label??``}),(0,J.jsx)(T,{className:`w-3 h-3 text-bambu-gray transition-transform ${a?`rotate-180`:``}`})]}),a&&(0,J.jsx)(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-full max-h-72 overflow-auto rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-xl py-1`,children:l.map((n,r)=>(0,J.jsxs)(`div`,{children:[n.group&&(0,J.jsx)(`div`,{className:`px-2 pt-1.5 pb-0.5 text-[10px] uppercase tracking-wider text-bambu-gray/60`,children:n.group}),n.options.map(n=>{let r=n.value===e;return(0,J.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":r,onClick:()=>{t(n.value),o(!1)},className:`flex w-full items-center gap-1.5 text-left px-2 py-1 text-xs whitespace-nowrap ${r?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary/60 hover:text-white`}`,children:[(0,J.jsx)(ne,{className:`w-3 h-3 flex-shrink-0 ${r?`opacity-100`:`opacity-0`}`}),(0,J.jsx)(`span`,{className:`truncate`,children:n.label})]},n.value)})]},r))})]})}function Je({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide ${{pending:`bg-slate-700 text-slate-200`,awaiting_printer:`bg-sky-700 text-sky-100`,queued:`bg-sky-700 text-sky-100`,printing:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`pipelineRuns.jobStatus.${e}`,e)})}function Ye(e){return e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function Xe({activeCount:e,pendingCount:t,totalTime:n,totalWeight:r,historyCount:i,t:a}){return(0,J.jsx)(`div`,{className:`flex items-center gap-3 sm:gap-5 flex-wrap px-4 py-3 bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary mb-6`,children:[{icon:oe,value:e,label:a(`queue.summary.printing`),color:`text-blue-600 dark:text-blue-400`},{icon:H,value:t,label:a(`queue.summary.queued`),color:`text-yellow-600 dark:text-yellow-400`},{icon:I,value:de(n),label:a(`queue.summary.totalTime`),color:`text-bambu-green`},{icon:Pe,value:Ye(r),label:a(`queue.summary.totalWeight`),color:`text-purple-600 dark:text-purple-400`},{icon:k,value:i,label:a(`queue.summary.history`),color:`text-bambu-gray`}].map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t>0&&(0,J.jsx)(`span`,{className:`hidden sm:block text-bambu-dark-tertiary`,children:`|`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(e.icon,{className:`w-4 h-4 ${e.color}`}),(0,J.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:e.value}),(0,J.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e.label})]})]},t))})}var Z={completed:{icon:k,color:`text-emerald-600 dark:text-emerald-400`,border:`border-l-emerald-500`},failed:{icon:E,color:`text-red-600 dark:text-red-400`,border:`border-l-red-500`},skipped:{icon:F,color:`text-orange-600 dark:text-orange-400`,border:`border-l-gray-500`},cancelled:{icon:_,color:`text-gray-400`,border:`border-l-gray-500`}};function Ze(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;return/^0{6,8}$/.test(t)||!/^[0-9a-fA-F]{6,8}$/.test(t)?null:`#${t.slice(0,6)}`}function Qe({item:e,onRequeue:t,onRemove:n,timeFormat:i=`system`,hasPermission:a,canModify:o,t:s}){let c=Z[e.status]||Z.cancelled,l=c.icon,u=Le(e),d=e.archive_thumbnail?r.getArchiveThumbnail(e.archive_id):e.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.library_file_id):null,f=e.completed_at||e.created_at,p=Ze(e.filament_color),m=e.filament_used_grams?Math.round(e.filament_used_grams):null,h=!!e.error_message&&(e.status===`failed`||e.status===`skipped`);return(0,J.jsxs)(`div`,{className:`px-3 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] ${c.border}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,J.jsx)(l,{className:`w-4 h-4 shrink-0 ${c.color}`}),(0,J.jsxs)(`div`,{className:`relative shrink-0 history-thumb-hover`,children:[(0,J.jsx)(`div`,{className:`w-8 h-8 bg-bambu-dark rounded overflow-hidden`,children:d?(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover`}):(0,J.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,J.jsx)(ke,{className:`w-4 h-4`})})}),d&&(0,J.jsx)(`div`,{className:`history-thumb-preview absolute z-[60] left-full top-0 ml-2 w-48 h-48 pointer-events-none opacity-0 transition-opacity`,children:(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover rounded-lg shadow-2xl border-2 border-bambu-dark-tertiary bg-bambu-dark`})})]}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:u}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,title:f??void 0,children:fe(f,i,s)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:t,disabled:!a(`queue:create`),title:a(`queue:create`)?s(`queue.actions.requeue`):s(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:n,disabled:!o(`queue`,`delete`,e.created_by_id),title:o(`queue`,`delete`,e.created_by_id)?s(`common.remove`):s(`queue.permissions.noRemove`),className:`p-1.5`,children:(0,J.jsx)(he,{className:`w-3.5 h-3.5`})})]})]}),(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[e.printer_name&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[100px] sm:max-w-[140px]`,children:e.printer_name})]}),(p||m)&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[p?(0,J.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-full border border-white/15`,style:{backgroundColor:p},"aria-hidden":!0}):(0,J.jsx)(Pe,{className:`w-3 h-3`}),(0,J.jsxs)(`span`,{className:`truncate`,children:[m?`${m}g`:null,m&&e.filament_type?` ${e.filament_type}`:null,!m&&e.filament_type?e.filament_type:null]})]}),e.print_time_seconds&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(I,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.created_by_username&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,title:s(`queue.addedBy`,{name:e.created_by_username}),children:[(0,J.jsx)(Se,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.created_by_username})]})]}),h&&(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex items-start gap-1 text-xs text-red-700 dark:text-red-400`,children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,J.jsx)(`span`,{className:`break-words`,children:e.error_message})]})]})}function $e(e){return e.printer_id==null?e.target_model?`model:${e.target_model}`:`unassigned`:`printer:${e.printer_id}`}function et(e,t,n){if(n){let n=+!!e.been_jumped,r=+!!t.been_jumped;if(n!==r)return r-n;let i=e.print_time_seconds??1/0,a=t.print_time_seconds??1/0;if(i!==a)return i-a}return e.position===t.position?(e.id??0)-(t.id??0):e.position-t.position}function tt(e){return e?e.split(` | `).map(e=>e.trim()).every(e=>e.startsWith(`Busy:`)):!1}var nt=3600*1e3,rt=24,it=rt*nt,at=32,ot=40;function st(e){return e.toLocaleTimeString(void 0,{hour:`numeric`})}function ct(e){return e.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function lt({queueItems:e,printers:t,printerStatuses:n,sjfEnabled:i,onItemClick:a,t:o}){let[s,c]=(0,q.useState)(()=>new Date);(0,q.useEffect)(()=>{let e=setInterval(()=>c(new Date),6e4);return()=>clearInterval(e)},[]);let[l,u]=(0,q.useState)(0),d=(0,q.useMemo)(()=>{let e=s.getTime()+l;return Math.floor(e/nt)*nt},[s,l]),f=d+it,p=s.getTime(),m=(0,q.useMemo)(()=>{let t=[],r=new Map,a=new Set,o=new Map;for(let i of e)if(i.status===`printing`){let e=i.printer_id==null?void 0:n[i.printer_id],r=z(i.started_at)||new Date,s;if(e?.remaining_time!=null&&e.remaining_time>0)s=new Date(p+e.remaining_time*60*1e3);else if(i.print_time_seconds){let t=e?.progress||0,n=Math.max(0,1-t/100);s=new Date(p+i.print_time_seconds*n*1e3)}else s=new Date(p+nt);t.push({item:i,estimatedStart:r,estimatedEnd:s,progress:e?.progress??void 0,type:`printing`});let c=$e(i);a.add(c),o.set(c,Math.max(o.get(c)??p,s.getTime()))}else if(i.status===`pending`){if(i.manual_start||i.waiting_reason&&!tt(i.waiting_reason))continue;let e=$e(i);r.has(e)||r.set(e,[]),r.get(e).push(i)}let s=Date.now()+4320*nt;for(let[e,n]of r){n.sort((e,t)=>et(e,t,i));let r=a.has(e),c=n[0]?z(n[0].scheduled_time):null,l=c&&c.getTime()<=s;if(!r&&!l)continue;let u=o.get(e)??p;for(let e of n){let n=z(e.scheduled_time);n&&n.getTime()<=s&&(u=Math.max(u,n.getTime()));let r=(e.print_time_seconds||3600)*1e3;t.push({item:e,estimatedStart:new Date(u),estimatedEnd:new Date(u+r),type:`queued`}),u+=r}}return t},[e,n,p,i]),h=(0,q.useMemo)(()=>{let e=[];for(let n of t)e.push({key:`printer:${n.id}`,label:n.name,printerId:n.id,targetModel:null});let n=new Set,r=!1;for(let t of m)if(t.item.printer_id==null)if(t.item.target_model){let r=`model:${t.item.target_model}`;n.has(r)||(n.add(r),e.push({key:r,label:`${o(`queue.filter.any`)} ${t.item.target_model}`,printerId:null,targetModel:t.item.target_model}))}else r=!0;return r&&e.push({key:`unassigned`,label:o(`queue.filter.unassigned`),printerId:null,targetModel:null}),e},[t,m,o]),g=(0,q.useMemo)(()=>{let e=new Map;for(let t of m){let n;n=t.item.printer_id==null?t.item.target_model?`model:${t.item.target_model}`:`unassigned`:`printer:${t.item.printer_id}`,e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[m]),_=(0,q.useMemo)(()=>{let e=[];for(let t=0;t<=rt;t+=2){let n=d+t*nt;e.push({ms:n,pct:t/rt*100,label:st(new Date(n))})}return e},[d]),v=(p-d)/it*100,y=v>=0&&v<=100,b=(0,q.useMemo)(()=>{let e=0;for(let t of m)e=Math.max(e,t.estimatedEnd.getTime());return e>0?new Date(e):null},[m]),x=(0,q.useRef)(null);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e-12*nt),className:`p-1.5`,title:o(`queue.timeline.window.back12h`),children:(0,J.jsx)(Ae,{className:`w-4 h-4`})}),(0,J.jsxs)(`span`,{className:`text-sm font-medium text-white min-w-[180px] text-center`,children:[new Date(d).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),` → `,new Date(f).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e+12*nt),className:`p-1.5`,title:o(`queue.timeline.window.forward12h`),children:(0,J.jsx)(xe,{className:`w-4 h-4`})}),l!==0&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(0),className:`text-xs text-bambu-green`,children:o(`queue.timeline.window.now`)})]}),b&&(0,J.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1.5`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),o(`queue.timeline.allDoneBy`,{time:b.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})})]})]}),h.length>0&&m.length===0&&(0,J.jsx)(`div`,{className:`mb-4 p-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 text-xs text-bambu-gray`,children:o(`queue.timeline.nothingCommitted`)}),h.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,J.jsx)(ke,{className:`w-12 h-12 mb-3 opacity-30`}),(0,J.jsx)(`p`,{className:`text-sm`,children:o(`queue.timeline.noData`)})]}):(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-2 text-xs font-medium text-bambu-gray border-r border-bambu-dark-tertiary`,children:o(`queue.timeline.printerColumnHeader`)}),(0,J.jsx)(`div`,{className:`relative flex-1 h-9`,children:_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/40 text-[10px] sm:text-xs text-bambu-gray pl-1 flex items-center`,style:{left:`${e.pct}%`},children:e.label},e.ms))})]}),(0,J.jsxs)(`div`,{ref:x,className:`relative`,children:[h.map(e=>{let t=g.get(e.key)??[];return(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary/40 last:border-b-0`,children:[(0,J.jsxs)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-3 border-r border-bambu-dark-tertiary flex items-center gap-2`,children:[(0,J.jsx)(ye,{className:`w-3.5 h-3.5 shrink-0 ${e.printerId==null&&e.targetModel==null?`text-orange-600 dark:text-orange-400`:e.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,J.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.label})]}),(0,J.jsxs)(`div`,{className:`relative flex-1`,style:{height:56},children:[_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/30`,style:{left:`${e.pct}%`}},e.ms)),(0,J.jsx)(`div`,{className:`absolute inset-0 opacity-30`,style:{backgroundImage:`repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,0.04) 6px, rgba(255,255,255,0.04) 12px)`},"aria-hidden":!0}),t.map(e=>{let t=Math.max(d,e.estimatedStart.getTime()),n=Math.min(f,e.estimatedEnd.getTime());if(n<=d||t>=f)return null;let i=(t-d)/it*100,o=(n-t)/it*100,s=e.item.archive_name||e.item.library_file_name||`#${e.item.id}`,c=e.item.archive_thumbnail?r.getArchiveThumbnail(e.item.archive_id):e.item.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.item.library_file_id):null,l=e.type===`printing`,u=e.item.batch_id!=null;return(0,J.jsxs)(`button`,{onClick:()=>a(e.item),title:[s,`${ct(e.estimatedStart)} → ${ct(e.estimatedEnd)}`,e.item.print_time_seconds?de(e.item.print_time_seconds):null,l&&e.progress!=null?`${Math.round(e.progress)}%`:null,e.item.batch_name?`batch: ${e.item.batch_name}`:null].filter(Boolean).join(` · `),className:`absolute rounded-md transition-all hover:brightness-110 hover:z-10 overflow-hidden flex items-center gap-1.5 px-1.5 text-left ${l?`bg-blue-500/30 border border-blue-400/60`:u?`bg-cyan-500/20 border border-cyan-400/50`:`bg-bambu-green/20 border border-bambu-green/40`}`,style:{left:`${i}%`,width:`max(${at}px, ${o}%)`,top:8,height:ot},children:[c&&(0,J.jsx)(`img`,{src:c,alt:``,className:`w-7 h-7 rounded object-cover shrink-0 bg-bambu-dark`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-xs text-white font-medium truncate leading-tight`,children:s}),(0,J.jsxs)(`div`,{className:`text-[10px] text-bambu-gray truncate leading-tight`,children:[e.item.print_time_seconds?de(e.item.print_time_seconds):``,l&&e.progress!=null?` · ${Math.round(e.progress)}%`:``]})]}),l&&e.progress!=null&&(0,J.jsx)(`div`,{className:`absolute bottom-0 left-0 h-0.5 bg-blue-300`,style:{width:`${e.progress}%`},"aria-hidden":!0})]},e.item.id)})]})]},e.key)}),y&&(0,J.jsxs)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none z-20 flex inset-x-0`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0`}),(0,J.jsx)(`div`,{className:`relative flex-1`,children:(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.6)]`,style:{left:`${v}%`},children:(0,J.jsx)(`div`,{className:`absolute -top-1 -left-1 w-2.5 h-2.5 bg-red-400 rounded-full`})})})]})]})]})]})}function ut({hasPermission:e,t,focusBatchId:n=null}){let i=o(),{showToast:a}=O(),[l,u]=(0,q.useState)(n?`all`:`active`),[d,f]=(0,q.useState)(null),{data:p}=s({queryKey:[`settings`],queryFn:r.getSettings}),m=De(p?.currency||`USD`),{data:h,isLoading:g}=s({queryKey:[`batches`,l],queryFn:()=>r.getBatches(l===`all`?void 0:l)}),_=n!=null&&!!h?.some(e=>e.id===n);(0,q.useEffect)(()=>{_&&document.getElementById(`batch-${n}`)?.scrollIntoView({block:`center`})},[_,n]);let v=()=>{i.invalidateQueries({queryKey:[`batches`]}),i.invalidateQueries({queryKey:[`queue`]})},y=c({mutationFn:({id:e,plateId:t})=>r.dispatchBatch(e,t===void 0?{}:{plate_id:t,only_plate:!0}),onSuccess:e=>{v(),a(t(`queue.batchOrders.dispatched`,{name:e.name}),`success`)},onError:e=>a(e.message,`error`)}),b=c({mutationFn:e=>r.cancelBatch(e),onSuccess:()=>{v(),f(null),a(t(`queue.batchCancelled`),`success`)},onError:e=>a(e.message,`error`)}),x=e(`queue:create`),S=e(`queue:delete_all`);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4`,children:[(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`h2`,{className:`text-base sm:text-lg font-semibold text-white`,children:t(`queue.batchOrders.title`)}),(0,J.jsx)(`div`,{className:`flex gap-1 ml-auto`,children:[`active`,`completed`,`cancelled`,`all`].map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-xs px-2.5 py-1 rounded-full border transition-colors ${l===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:t(`queue.batchOrders.filter.${e}`)},e))})]}),g?(0,J.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:t(`common.loading`)}):h?.length?(0,J.jsx)(`div`,{className:`space-y-4`,children:h.map(e=>(0,J.jsx)(ft,{batch:e,currency:m,canDispatch:x,canCancel:S,isDispatching:y.isPending&&y.variables?.id===e.id,highlighted:e.id===n,onDispatch:t=>y.mutate({id:e.id,plateId:t}),onCancel:()=>f(e),t},e.id))}):(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(N,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:t(`queue.batchOrders.emptyTitle`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:t(`queue.batchOrders.emptyDescription`)})]}),d&&(0,J.jsx)(Ee,{title:t(`queue.cancelBatchConfirmTitle`),message:t(`queue.cancelBatchConfirmMessage`),confirmText:t(`queue.cancelBatch`),variant:`warning`,onConfirm:()=>b.mutate(d.id),onCancel:()=>f(null)})]})}var dt={active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`,completed:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`,cancelled:`bg-bambu-dark-tertiary text-bambu-gray`};function ft({batch:e,currency:t,canDispatch:n,canCancel:r,isDispatching:i,onDispatch:a,onCancel:o,t:s,highlighted:c=!1}){let l=e.has_targets?e.target_count:e.completed_count+e.pending_count+e.printing_count+e.failed_count,u=l>0?Math.round(e.completed_count/l*100):0,d=e.has_targets?e.remaining_count-e.dispatchable_count:0,f=e.due_date?z(e.due_date):null,p=f!=null&&e.status===`active`&&f.getTime()<Date.now();return(0,J.jsxs)(le,{id:`batch-${e.id}`,className:`p-4 ${c?`ring-2 ring-bambu-green`:``}`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3 mb-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,J.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,J.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${dt[e.status]??dt.cancelled}`,children:s(`queue.batchOrders.status.${e.status}`)}),!e.has_targets&&(0,J.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,title:s(`queue.batchOrders.noTargetsHint`),children:s(`queue.batchOrders.noTargets`)})]}),(0,J.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[e.created_by_username?s(`queue.addedBy`,{name:e.created_by_username}):null,f&&(0,J.jsxs)(`span`,{className:p?`text-orange-600 dark:text-orange-400`:``,children:[e.created_by_username?` • `:``,s(`queue.batchOrders.due`,{date:f.toLocaleDateString()})]})]}),e.notes&&(0,J.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 whitespace-pre-wrap`,children:e.notes})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[e.has_targets&&e.dispatchable_count>0&&e.status!==`cancelled`&&n&&(0,J.jsxs)(R,{variant:`primary`,size:`sm`,onClick:()=>a(),disabled:i,children:[(0,J.jsx)(ze,{className:`w-4 h-4 mr-1`}),s(`queue.batchOrders.dispatchRemaining`,{count:e.dispatchable_count})]}),e.status===`active`&&r&&(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:o,children:[(0,J.jsx)(E,{className:`w-4 h-4 mr-1`}),s(`queue.cancelBatch`)]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,J.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,J.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.status===`completed`?`bg-bambu-green`:`bg-blue-500`}`,style:{width:`${Math.min(100,u)}%`}})}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap tabular-nums`,children:s(`queue.batchProgress`,{completed:e.completed_count,total:l})})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-bambu-gray mb-1`,children:[e.printing_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.printing`,{count:e.printing_count})}),e.pending_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batch.pendingCount`,{count:e.pending_count})}),e.failed_count>0&&(0,J.jsxs)(`span`,{className:`text-orange-600 dark:text-orange-400 flex items-center gap-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3`}),s(`queue.batchOrders.failed`,{count:e.failed_count})]}),e.has_targets&&e.remaining_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.remaining`,{count:e.remaining_count})}),e.print_time_seconds>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(H,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.actual_cost!=null&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(A,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costSoFar`,{amount:`${t} ${e.actual_cost.toFixed(2)}`})}),e.estimated_remaining_cost!=null&&e.estimated_remaining_cost>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costRemaining`,{amount:`${t} ${e.estimated_remaining_cost.toFixed(2)}`})})]})]}),d>0&&e.status!==`cancelled`&&(0,J.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-orange-600 dark:text-orange-400 mb-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.strandedNotice`,{runs:d,owed:e.remaining_count})})]}),e.has_targets&&e.plates.length>0&&(0,J.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3 space-y-1.5`,children:e.plates.map(r=>(0,J.jsx)(pt,{plate:r,batchStatus:e.status,currency:t,canDispatch:n,isDispatching:i,onDispatch:()=>a(r.plate_id),t:s},`${r.plate_id??`file`}`))})]})}function pt({plate:e,batchStatus:t,currency:n,canDispatch:r,isDispatching:i,onDispatch:a,t:o}){let s=e.plate_name||(e.plate_id==null?o(`queue.batchOrders.wholeFile`):o(`queue.plateNumber`,{index:e.plate_id}));return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs`,children:[(0,J.jsx)(ke,{className:`w-3.5 h-3.5 text-bambu-gray flex-shrink-0`}),(0,J.jsx)(`span`,{className:`text-white min-w-0 truncate`,children:s}),(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:o(`queue.batchOrders.plateProgress`,{completed:e.completed_count,target:e.quantity_target})}),e.failed_count>0&&(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.failed`,{count:e.failed_count})}),e.actual_cost!=null&&(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:`${n} ${e.actual_cost.toFixed(2)}`}),e.remaining>0&&t!==`cancelled`&&(0,J.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray`,children:o(`queue.batchOrders.remaining`,{count:e.remaining})}),e.can_dispatch?r&&(0,J.jsx)(`button`,{type:`button`,onClick:a,disabled:i,className:`text-bambu-green hover:underline disabled:opacity-50`,children:o(`queue.batchOrders.dispatchPlate`)}):(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.strandedPlate`)})]})]})}function mt(e,t){if(!e?.connected||t>=254)return;let n=t>=128,r=n?t:Math.floor(t/4),i=n?0:t%4,a=e.ams?.find(e=>e.id===r);if(W(n?a?.tray[0]:a?.tray.find(e=>e.id===i))===`physical`)return ve(r,i,n,!1)}function ht(e){return e.slotLabel?[e.slotLabel,e.spoolName||e.type,e.colorName].filter(Boolean).join(` · `):e.colorName}function gt(e,t,n=[],r,i=`Empty`){let a=t=>{let a=t.slotId,o=a>0?e.ams_mapping?.[a-1]:void 0;if(o==null||o<0)return t;let s=n.find(e=>e.globalTrayId===o);if(s)return{slotId:a,type:s.type,color:s.color,colorName:s.colorName,slotLabel:s.label,spoolName:s.spoolName,extraColors:s.extraColors,effectType:s.effectType,subtype:s.spoolSubtype};let c=mt(r,o);return c?{...t,slotLabel:c,spoolName:i,emptySlot:!0}:t},o=e.plate_id==null?t[0]:t.find(t=>t.index===e.plate_id);if(o){let t=new Map((e.filament_overrides??[]).map(e=>[e.slot_id,e]));return o.filaments.filter(e=>e.used_in_plate!==!1&&e.used_grams>0).map(e=>{let n=t.get(e.slot_id),r=n?.color??e.color,i=n?.type??e.type;return a({slotId:e.slot_id,type:i,color:r,colorName:n?.color_name?.trim()||G(r,i)})})}return e.filament_overrides?.length?e.filament_overrides.map(e=>a({slotId:e.slot_id,type:e.type,color:e.color,colorName:e.color_name?.trim()||G(e.color,e.type)})):e.filament_color?[a({slotId:1,type:e.filament_type??``,color:e.filament_color,colorName:G(e.filament_color,e.filament_type)})]:[]}function _t(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function vt({status:e,waitingReason:t,printerState:n,t:r}){if(e===`pending`&&t)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-purple-700 dark:text-purple-400 bg-purple-50 dark:bg-purple-400/10 border-purple-200 dark:border-purple-400/20`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),r(`queue.status.waiting`)]});if(e===`printing`&&n===`PAUSE`)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-400/10 border-yellow-200 dark:border-yellow-400/20`,children:[(0,J.jsx)(P,{className:`w-3.5 h-3.5`}),r(`queue.status.paused`)]});let{icon:i,color:a,label:o}={pending:{icon:H,color:`text-status-warning bg-status-warning/10 border-status-warning/20`,label:r(`queue.status.pending`)},printing:{icon:oe,color:`text-blue-700 dark:text-blue-400 bg-blue-50 dark:bg-blue-400/10 border-blue-200 dark:border-blue-400/20`,label:r(`queue.status.printing`)},completed:{icon:k,color:`text-status-ok bg-status-ok/10 border-status-ok/20`,label:r(`queue.status.completed`)},failed:{icon:E,color:`text-status-error bg-status-error/10 border-status-error/20`,label:r(`queue.status.failed`)},skipped:{icon:F,color:`text-orange-700 dark:text-orange-400 bg-orange-50 dark:bg-orange-400/10 border-orange-200 dark:border-orange-400/20`,label:r(`queue.status.skipped`)},cancelled:{icon:ce,color:`text-gray-400 bg-gray-400/10 border-gray-400/20`,label:r(`queue.status.cancelled`)}}[e];return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a}`,children:[(0,J.jsx)(i,{className:`w-3.5 h-3.5`}),o]})}function yt({selectedCount:e,printers:t,onSave:n,onClose:r,isSaving:i,canControlPrinter:a,hasGcodeSnippets:o,t:s}){let[c,l]=(0,q.useState)(`unchanged`),[u,d]=(0,q.useState)(`unchanged`),[f,p]=(0,q.useState)(`unchanged`),[m,h]=(0,q.useState)(`unchanged`),[g,_]=(0,q.useState)(`unchanged`),[v,y]=(0,q.useState)(`unchanged`),[b,x]=(0,q.useState)(`unchanged`),[S,ee]=(0,q.useState)(`unchanged`),[C,te]=(0,q.useState)(`unchanged`),[w,ne]=(0,q.useState)(`unchanged`),[T,re]=(0,q.useState)(`unchanged`),[E,D]=(0,q.useState)(`unchanged`),[O,k]=(0,q.useState)(`unchanged`),A=t.some(e=>e.nozzle_count===2),j=()=>{let e={};c!==`unchanged`&&(e.printer_id=c),u!==`unchanged`&&(e.manual_start=u),f!==`unchanged`&&(e.auto_off_after=f),m!==`unchanged`&&(e.require_previous_success=m),g!==`unchanged`&&(e.gcode_injection=g),v!==`unchanged`&&(e.bed_levelling=v),b!==`unchanged`&&(e.flow_cali=b),S!==`unchanged`&&(e.vibration_cali=S),C!==`unchanged`&&(e.layer_inspect=C),w!==`unchanged`&&(e.timelapse=w),T!==`unchanged`&&(e.use_ams=T),E!==`unchanged`&&(e.confirm_outcome=E),O!==`unchanged`&&(e.nozzle_offset_cali=O),n(e)},M=c!==`unchanged`||u!==`unchanged`||f!==`unchanged`||m!==`unchanged`||v!==`unchanged`||b!==`unchanged`||S!==`unchanged`||C!==`unchanged`||w!==`unchanged`||T!==`unchanged`||E!==`unchanged`||O!==`unchanged`||g!==`unchanged`;return(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:s(`queue.bulkEdit.title`,{count:e})}),(0,J.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,J.jsx)(ce,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,J.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:s(`queue.bulkEdit.description`)}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printer`)}),(0,J.jsxs)(`select`,{value:c===null?`null`:c===`unchanged`?`unchanged`:String(c),onChange:e=>{let t=e.target.value;l(t===`unchanged`?`unchanged`:t===`null`?null:Number(t))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,J.jsx)(`option`,{value:`unchanged`,children:s(`queue.bulkEdit.noChange`)}),(0,J.jsx)(`option`,{value:`null`,children:s(`queue.filter.unassigned`)}),t.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.queueOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(Q,{label:s(`queue.bulkEdit.staged`),value:u,onChange:d,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.autoPowerOff`),value:f,onChange:p,disabled:!a,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.requirePrevious`),value:m,onChange:h,t:s}),o&&(0,J.jsx)(Q,{label:s(`queue.bulkEdit.gcodeInjection`),value:g,onChange:_,t:s})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(bt,{label:s(`queue.bulkEdit.bedLevelling`),value:v,onChange:y,t:s}),(0,J.jsx)(bt,{label:s(`queue.bulkEdit.flowCalibration`),value:b,onChange:x,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.vibrationCalibration`),value:S,onChange:ee,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.layerInspection`),value:C,onChange:te,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.timelapse`),value:w,onChange:ne,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.useAms`),value:T,onChange:re,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.confirmOutcome`),value:E,onChange:D,t:s}),A&&(0,J.jsx)(bt,{label:s(`queue.bulkEdit.nozzleOffsetCali`),value:O,onChange:k,t:s})]})]})]}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,J.jsx)(R,{variant:`secondary`,onClick:r,children:s(`common.cancel`)}),(0,J.jsx)(R,{onClick:j,disabled:!M||i,children:s(i?`common.saving`:`queue.bulkEdit.applyChanges`)})]})]})})}function Q({label:e,value:t,onChange:n,disabled:r,t:i}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1 ${r?`opacity-50`:``}`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:[(0,J.jsx)(`button`,{onClick:()=>n(`unchanged`),disabled:r,className:`px-2 py-1 text-xs rounded ${t===`unchanged`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:`—`}),(0,J.jsx)(`button`,{onClick:()=>n(!1),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!1?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.off`)}),(0,J.jsx)(`button`,{onClick:()=>n(!0),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!0?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.on`)})]})]})}function bt({label:e,value:t,onChange:n,t:r}){let i=[{key:`unchanged`,label:`—`,active:`bg-bambu-dark-tertiary text-white`},{key:`off`,label:r(`settings.calibrationMode_off`),active:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`},{key:`auto`,label:r(`settings.calibrationMode_auto`),active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},{key:`on`,label:r(`settings.calibrationMode_on`),active:`bg-bambu-green/20 text-bambu-green`}];return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:i.map(({key:e,label:r,active:i})=>(0,J.jsx)(`button`,{onClick:()=>n(e),className:`px-2 py-1 text-xs rounded ${t===e?i:`text-bambu-gray hover:text-white`}`,children:r},e))})]})}function xt({item:e,position:t,onEdit:n,onCancel:i,onRemove:a,onStop:o,onRequeue:c,onStart:l,onMoveUp:u,onMoveDown:d,timeFormat:f=`system`,isSelected:m=!1,onToggleSelect:h,hasPermission:g,canModify:_,printerState:v,showEta:y=!1,etaNow:x,t:S}){let{hasAnyPermission:ee}=Ie(),C=!ee(`queue:update_all`,`queue:start_unreviewed`),te=e.printer_id!=null&&(e.ams_mapping?.some(e=>e>=0)??!1),{data:w}=s({queryKey:[`printerStatus`,e.printer_id],queryFn:()=>r.getPrinterStatus(e.printer_id),refetchInterval:v===`printing`?3e4:!1,enabled:e.printer_id!=null&&(v===`printing`||te)}),{data:E}=s({queryKey:[`printer-inventory-remain`,e.printer_id],queryFn:()=>r.getInventoryRemain(e.printer_id),enabled:te,staleTime:30*1e3}),O=(0,q.useMemo)(()=>{let e=E?.slot_materials;if(!e?.length)return;let t=new Map;return e.forEach(e=>{e.spool&&t.set(e.global_tray_id,e.spool)}),t.size>0?t:void 0},[E]),k=(0,q.useMemo)(()=>me(w,O),[w,O]),A=!!e.library_file_id&&!e.archive_id,{data:j}=s({queryKey:[`archive-plates`,e.archive_id],queryFn:()=>r.getArchivePlates(e.archive_id),enabled:!!e.archive_id&&!A&&!e.archive_deleted}),{data:ie}=s({queryKey:[`library-file-plates`,e.library_file_id],queryFn:()=>r.getLibraryFilePlates(e.library_file_id),enabled:A&&!!e.library_file_id}),ae=A?ie:j,N=ae?.plates??[],P=gt(e,N,k,w,S(`ams.empty`)),F=g(`queue:reorder`),{attributes:L,listeners:se,setNodeRef:le,transform:B,transition:ve,isDragging:be}=p({id:e.id,disabled:e.status!==`pending`||!F}),xe={transform:b.Transform.toString(B),transition:ve},we=e.status===`printing`,W=e.status===`pending`,Ee=[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status),De=W&&y&&e.print_time_seconds!=null&&e.print_time_seconds>0?ue(e.print_time_seconds/60,f,S,x):null,Oe=W&&h;return(0,J.jsxs)(`div`,{ref:le,style:xe,className:`
group relative bg-bambu-dark-secondary rounded-xl border transition-all duration-200
border-l-[3px] ${we?`border-l-blue-500`:W?`border-l-yellow-500`:e.status===`completed`?`border-l-emerald-500`:e.status===`failed`?`border-l-red-500`:`border-l-gray-500`}
${be?`opacity-50 scale-[1.02] shadow-xl z-50`:``}
${we?`border-blue-500/30 bg-gradient-to-r from-blue-500/5 to-transparent`:``}
${m&&Oe?`sm:border-bambu-dark-tertiary border-bambu-green/40`:``}
${!m&&!we?`border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80`:``}
${Oe?`cursor-pointer sm:cursor-default`:``}
`,onClick:Oe?()=>{window.innerWidth<640&&h()}:void 0,children:[Oe&&m&&(0,J.jsx)(`div`,{className:`sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green`}),(0,J.jsxs)(`div`,{className:`flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4`,children:[W&&(u||d)&&(0,J.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(`button`,{type:`button`,onClick:u,disabled:!u,title:S(`queue.moveUp`),"aria-label":S(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(re,{className:`w-5 h-5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:d,disabled:!d,title:S(`queue.moveDown`),"aria-label":S(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(T,{className:`w-5 h-5`})})]}),W&&h&&(0,J.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${m?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,children:m&&(0,J.jsx)(ne,{className:`w-4 h-4`})}),W?(0,J.jsx)(`div`,{...L,...se,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,children:(0,J.jsx)(M,{className:`w-4 h-4 text-bambu-gray`})}):t===void 0?(0,J.jsx)(`div`,{className:`hidden sm:block w-8 shrink-0`}):(0,J.jsxs)(`div`,{className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0`,children:[`#`,t]}),(0,J.jsx)(`div`,{className:`w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden`,children:e.archive_thumbnail?(0,J.jsx)(`img`,{src:e.plate_id==null?r.getArchiveThumbnail(e.archive_id):r.getArchivePlateThumbnail(e.archive_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):e.library_file_thumbnail?(0,J.jsx)(`img`,{src:e.plate_id==null?r.getLibraryFileThumbnailUrl(e.library_file_id):r.getLibraryFilePlateThumbnail(e.library_file_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):(0,J.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,J.jsx)(ke,{className:`w-5 h-5 sm:w-6 sm:h-6`})})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,J.jsxs)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:[Le(e,e=>S(`common.plusNMore`,{count:e})),(ae?.is_multi_plate??!1)&&e.plate_id!==void 0&&e.plate_id!==null&&` • ${N.find(t=>t.index===e.plate_id)?.name||S(`queue.plateNumber`,{index:e.plate_id})}`]}),e.archive_id?(0,J.jsx)(Ce,{to:`/archives?highlight=${e.archive_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:S(`queue.viewArchive`),children:(0,J.jsx)(ge,{className:`w-3.5 h-3.5`})}):e.library_file_id?(0,J.jsx)(Ce,{to:`/library?highlight=${e.library_file_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:S(`queue.viewInFileManager`),children:(0,J.jsx)(ge,{className:`w-3.5 h-3.5`})}):null,e.batch_name&&(0,J.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:e.batch_name})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 ${e.printer_id===null&&!e.target_model?`text-orange-700 dark:text-orange-400`:``} ${e.target_model&&!e.printer_id?`text-blue-700 dark:text-blue-400`:``}`,children:[(0,J.jsx)(ye,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px] sm:max-w-none`,children:(e.variants?.length??0)>1&&!e.printer_id?`${S(`queue.filter.any`)} ${e.variants.map(e=>e.target_model).join(` / `)}${e.target_location?` @ ${e.target_location}`:``}`:e.target_model&&!e.printer_id?`${S(`queue.filter.any`)} ${e.target_model}${e.target_location?` @ ${e.target_location}`:``}${e.required_filament_types?.length?` (${e.required_filament_types.join(`, `)})`:``}`:e.printer_id===null?S(`queue.filter.unassigned`):e.printer_name||`${S(`common.printer`)} #${e.printer_id}`})]}),e.print_time_seconds&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(I,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),de(e.print_time_seconds)]}),De&&(0,J.jsxs)(`span`,{"data-testid":`queue-item-eta`,className:`text-bambu-green font-medium`,title:S(`queue.time.etaIfStartedNow`),children:[`ETA `,De]}),e.filament_used_grams&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(Pe,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),_t(e.filament_used_grams)]}),P.length>2?(0,J.jsxs)(`span`,{"data-testid":`queue-filament-compact`,className:`flex items-center gap-0.5 flex-shrink-0`,title:P.map(ht).join(`
`),role:`img`,"aria-label":P.map(ht).join(`, `),children:[P.map(e=>(0,J.jsx)(K,{rgba:e.color,extraColors:e.extraColors,effectType:e.effectType,subtype:e.subtype,className:`w-2.5 h-2.5 sm:w-3 sm:h-3 pointer-events-none`,effectSize:`table`},`filament-${e.slotId}`)),P.some(e=>e.emptySlot)&&(0,J.jsx)(D,{className:`w-3 h-3 ml-0.5 text-yellow-700 dark:text-yellow-400`,"aria-hidden":`true`})]}):P.map(e=>{let t=ht(e);return(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 min-w-0`,title:t,children:[(0,J.jsx)(K,{rgba:e.color,extraColors:e.extraColors,effectType:e.effectType,subtype:e.subtype,className:`w-3 h-3 sm:w-3.5 sm:h-3.5`,effectSize:`table`}),(0,J.jsx)(`span`,{className:`truncate max-w-[110px] sm:max-w-[260px]${e.emptySlot?` text-yellow-700 dark:text-yellow-400`:``}`,children:t})]},`filament-${e.slotId}`)}),(()=>{let t=U(e.bed_type);return t?(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,title:t.label,children:[(0,J.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 sm:w-4 sm:h-4 object-contain`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px]`,children:t.label})]}):null})(),e.created_by_username&&(0,J.jsxs)(`span`,{className:`hidden sm:flex items-center gap-1.5`,title:S(`queue.addedBy`,{name:e.created_by_username}),children:[(0,J.jsx)(Se,{className:`w-3.5 h-3.5`}),e.created_by_username]}),W&&!e.manual_start&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),e.scheduled_time?(z(e.scheduled_time)?.getTime()??0)-Date.now()<-6e4?S?.(`queue.time.overdue`)??`Overdue`:fe(e.scheduled_time,f,S):S?.(`queue.time.whenFree`)??`When a printer is free`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2`,children:[e.manual_start&&(0,J.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-purple-50 dark:bg-purple-500/10 text-purple-700 dark:text-purple-400 rounded-full border border-purple-200 dark:border-purple-500/20 flex items-center gap-1`,children:[(0,J.jsx)(Me,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(C?`queue.badges.awaitingReview`:`queue.badges.staged`)]}),e.require_previous_success&&(0,J.jsx)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-50 dark:bg-orange-500/10 text-orange-700 dark:text-orange-400 rounded-full border border-orange-200 dark:border-orange-500/20`,children:S(`queue.badges.requiresPrevious`)}),e.auto_off_after&&(0,J.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-400 rounded-full border border-blue-200 dark:border-blue-500/20 flex items-center gap-1`,children:[(0,J.jsx)(Te,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(`queue.badges.autoPowerOff`)]}),e.gcode_injection&&(0,J.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-400 rounded-full border border-emerald-200 dark:border-emerald-500/20 flex items-center gap-1`,children:[(0,J.jsx)(_e,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(`queue.badges.gcodeInjection`)]}),e.confirm_outcome&&(0,J.jsxs)(`span`,{title:S(`queue.badges.confirmOutcomeTitle`),className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 rounded-full border border-green-200 dark:border-green-500/20 flex items-center gap-1`,children:[(0,J.jsx)(je,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(`queue.badges.confirmOutcome`)]})]}),we&&w&&(()=>{let e=w.state===`RUNNING`||w.state===`PAUSE`,t=e&&w.progress||0,n=e?w.remaining_time:null,r=e?w.layer_num:null,i=e?w.total_layers:null;return(0,J.jsxs)(`div`,{className:`mt-2 sm:mt-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-xs sm:text-sm`,children:[(0,J.jsx)(`div`,{className:`flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3`,children:(0,J.jsx)(`div`,{className:`bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all`,style:{width:`${t}%`}})}),(0,J.jsxs)(`span`,{className:`text-white`,children:[Math.round(t),`%`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray`,children:[n!=null&&n>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(H,{className:`w-3 h-3`}),de(n*60)]}),(0,J.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:S(`printers.estimatedCompletion`),children:[`ETA `,ue(n,f,S)]})]}),r!=null&&i!=null&&i>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(ke,{className:`w-3 h-3`}),r,`/`,i]})]})]})})(),e.waiting_reason&&e.status===`pending`&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-purple-700 dark:text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1`,children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:e.waiting_reason})]}),e.filament_short&&e.status===`pending`&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-yellow-700 dark:text-yellow-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:S(`queue.filamentShort.rowTooltip`),children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:S(`queue.filamentShort.rowBadge`)})]}),e.archive_has_slicer_ams_mapping&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-green-700 dark:text-green-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:S(`queue.slicerAmsMapping.rowTooltip`),children:[(0,J.jsx)(ne,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:S(`queue.slicerAmsMapping.rowBadge`)})]}),e.error_message&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-red-700 dark:text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1`,children:[(0,J.jsx)(D,{className:`w-3 h-3`}),e.error_message]})]}),(0,J.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(vt,{status:e.status,waitingReason:e.waiting_reason,printerState:v,t:S}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1`,children:[we&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:o,disabled:!_(`queue`,`update`,e.created_by_id),title:_(`queue`,`update`,e.created_by_id)?S(`queue.actions.stopPrint`):S(`queue.permissions.noStopPrint`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,J.jsx)(Be,{className:`w-4 h-4`})}),W&&(0,J.jsxs)(J.Fragment,{children:[e.manual_start&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:l,disabled:C||!_(`queue`,`update`,e.created_by_id),title:C?S(`queue.permissions.awaitingReview`):_(`queue`,`update`,e.created_by_id)?S(`queue.actions.startPrint`):S(`queue.permissions.noStartPrint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,J.jsx)(oe,{className:`w-4 h-4`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:n,disabled:!_(`queue`,`update`,e.created_by_id),title:_(`queue`,`update`,e.created_by_id)?S(`common.edit`):S(`queue.permissions.noEdit`),className:`p-1.5 sm:p-2`,children:(0,J.jsx)(pe,{className:`w-4 h-4`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:i,disabled:!_(`queue`,`delete`,e.created_by_id),title:_(`queue`,`delete`,e.created_by_id)?S(`common.cancel`):S(`queue.permissions.noCancel`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,J.jsx)(ce,{className:`w-4 h-4`})})]}),Ee&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:c,disabled:!g(`queue:create`),title:g(`queue:create`)?S(`queue.actions.requeue`):S(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,J.jsx)(V,{className:`w-4 h-4`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:a,disabled:!_(`queue`,`delete`,e.created_by_id),title:_(`queue`,`delete`,e.created_by_id)?S(`common.remove`):S(`queue.permissions.noRemove`),className:`p-1.5 sm:p-2`,children:(0,J.jsx)(he,{className:`w-4 h-4`})})]})]})]})]})]})}function St(e){let{row:t,setEditItem:n,setConfirmAction:r,startMutation:i,selectedItems:a,handleToggleSelect:o,timeFormat:s,hasPermission:c,canModify:l,t:u,etaEligibleIds:d,etaNow:f,onMoveUp:p,onMoveDown:m}=e;return t.kind===`item`?(0,J.jsx)(xt,{item:t.item,onEdit:()=>n(t.item),onCancel:()=>r({type:`cancel`,item:t.item}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>i.mutate({id:t.item.id}),onMoveUp:p,onMoveDown:m,timeFormat:s,isSelected:a.includes(t.item.id),onToggleSelect:()=>o(t.item.id),hasPermission:c,canModify:l,showEta:d.has(t.item.id),etaNow:f,t:u}):(0,J.jsx)(Ct,{...e})}function Ct({row:e,collapsed:t,onToggleBatch:n,onUngroup:r,setEditItem:i,setConfirmAction:a,startMutation:o,selectedItems:s,handleToggleSelect:c,timeFormat:l,hasPermission:u,canModify:d,t:f,etaEligibleIds:m,etaNow:h,aggregateForRows:g,onMoveUp:_,onMoveDown:v,onMoveBlock:y}){let x=e,S=u(`queue:reorder`),{attributes:ee,listeners:C,setNodeRef:te,transform:w,transition:E,isDragging:D}=p({id:`batch-${x.batchId}`,disabled:!S}),O={transform:b.Transform.toString(w),transition:E},k=g([x]),A=x.items.map(e=>e.id),j=A.length>0&&A.every(e=>s.includes(e)),ie=new Set(x.items.map(e=>e.status)),ae=ie.has(`failed`)?`failed`:ie.has(`printing`)?`printing`:`pending`,P=x.items.filter(e=>e.status===`pending`).length;return(0,J.jsxs)(`div`,{ref:te,style:O,className:`bg-bambu-dark-secondary rounded-xl border border-l-[3px] border-l-cyan-400 border-bambu-dark-tertiary overflow-hidden ${D?`opacity-50 scale-[1.01] shadow-xl z-50`:``}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 p-3 sm:p-4`,children:[S&&(_||v)&&(0,J.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:_,disabled:!_,title:f(`queue.moveUp`),"aria-label":f(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(re,{className:`w-5 h-5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:v,disabled:!v,title:f(`queue.moveDown`),"aria-label":f(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(T,{className:`w-5 h-5`})})]}),(0,J.jsx)(`button`,{onClick:e=>{e.stopPropagation(),A.forEach(e=>{(j&&s.includes(e)||!j&&!s.includes(e))&&c(e)})},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${j?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,title:f(j?`queue.bulkEdit.deselectAll`:`queue.bulkEdit.selectAll`),children:j&&(0,J.jsx)(ne,{className:`w-4 h-4`})}),S&&(0,J.jsx)(`div`,{...ee,...C,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,title:f(`queue.batch.dragGroup`,{defaultValue:`Drag group`}),children:(0,J.jsx)(M,{className:`w-4 h-4 text-bambu-gray`})}),(0,J.jsx)(`button`,{onClick:n,className:`flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors shrink-0`,title:f(t?`queue.batch.expand`:`queue.batch.collapse`),children:t?(0,J.jsx)(xe,{className:`w-4 h-4 text-bambu-gray`}):(0,J.jsx)(T,{className:`w-4 h-4 text-bambu-gray`})}),(0,J.jsx)(`div`,{className:`w-10 h-10 sm:w-12 sm:h-12 flex-shrink-0 bg-bambu-dark rounded-lg flex items-center justify-center`,children:t?(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}):(0,J.jsx)(Ve,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,J.jsx)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:x.batchName}),(0,J.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/15 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:f(`queue.batch.label`,{count:k.count})})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[k.time>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(I,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),de(k.time)]}),k.weight>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(Pe,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),_t(k.weight)]}),P>0&&ae===`pending`&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 text-yellow-700 dark:text-yellow-400`,children:[(0,J.jsx)(H,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),f(`queue.batch.pendingCount`,{count:P})]})]})]}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:r&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:r,title:f(`queue.batch.ungroup`),className:`text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200 hover:bg-cyan-50 dark:hover:bg-cyan-500/10 p-1.5 sm:p-2`,children:(0,J.jsx)(Ue,{className:`w-4 h-4`})})})]}),!t&&(0,J.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 sm:p-3 space-y-2`,children:x.items.map((e,t)=>(0,J.jsx)(xt,{item:e,onEdit:()=>i(e),onCancel:()=>a({type:`cancel`,item:e}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>o.mutate({id:e.id}),onMoveUp:y&&t>0?()=>y([e.id],x.items[t-1].id,!1):void 0,onMoveDown:y&&t<x.items.length-1?()=>y([e.id],x.items[t+1].id,!0):void 0,timeFormat:l,isSelected:s.includes(e.id),onToggleSelect:()=>c(e.id),hasPermission:u,canModify:d,showEta:m.has(e.id),etaNow:h,t:f},e.id))})]})}function wt({items:e,visibleCount:t,onShowMore:n,sortBy:r,sortAsc:i,onSortByChange:a,onSortAscToggle:o,onRemove:s,onRequeue:c,timeFormat:l,batchCollapsed:u,toggleBatchCollapsed:p,hasPermission:m,canModify:h,t:g}){if(e.length===0)return(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(Ne,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:g(`queue.history.emptyTitle`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:g(`queue.history.emptyDescription`)})]});let v=[],y=new Set;for(let n of e.slice(0,t))if(n.batch_id!=null){if(y.has(n.batch_id))continue;y.add(n.batch_id);let t=e.filter(e=>e.batch_id===n.batch_id);v.push({kind:`batch`,batchId:n.batch_id,batchName:n.batch_name||g(`queue.batch.defaultName`),items:t})}else v.push({kind:`item`,item:n});return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,J.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[g(`queue.sections.history`),(0,J.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,g(`queue.itemCount`,{count:e.length}),`)`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:r,onChange:e=>a(e.target.value),children:[(0,J.jsx)(`option`,{value:`date`,children:g(`queue.sort.byDate`)}),(0,J.jsx)(`option`,{value:`name`,children:g(`queue.sort.byName`)}),(0,J.jsx)(`option`,{value:`printer`,children:g(`queue.sort.byPrinter`)})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:o,title:g(i?`queue.sort.ascendingOldest`:`queue.sort.descendingNewest`),className:`px-2`,children:i?(0,J.jsx)(f,{className:`w-4 h-4`}):(0,J.jsx)(d,{className:`w-4 h-4`})})]})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:v.map(e=>{if(e.kind===`item`)return(0,J.jsx)(Qe,{item:e.item,onRemove:()=>s(e.item),onRequeue:()=>c(e.item),timeFormat:l,hasPermission:m,canModify:h,t:g},e.item.id);let t=u[e.batchId]??!0,n=e.items.filter(e=>e.status===`completed`).length,r=e.items.filter(e=>e.status===`failed`).length,i=e.items.filter(e=>e.status===`skipped`).length,a=e.items.filter(e=>e.status===`cancelled`).length,o=e.items.map(e=>e.completed_at||e.created_at).filter(e=>!!e).sort().at(-1);return(0,J.jsxs)(`div`,{className:`md:col-span-2 xl:col-span-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] border-l-cyan-400`,children:[(0,J.jsxs)(`button`,{onClick:()=>p(e.batchId),className:`w-full flex items-center gap-2 sm:gap-3 px-3 py-2 hover:bg-bambu-dark/30 transition-colors text-left`,title:g(t?`queue.batch.expand`:`queue.batch.collapse`),children:[t?(0,J.jsx)(xe,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,J.jsx)(T,{className:`w-4 h-4 text-bambu-gray shrink-0`}),t?(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}):(0,J.jsx)(Ve,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:e.batchName}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray shrink-0`,children:[n>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-700 dark:text-emerald-400`,children:[(0,J.jsx)(k,{className:`w-3 h-3`}),n]}),r>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,J.jsx)(E,{className:`w-3 h-3`}),r]}),i>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-orange-700 dark:text-orange-400`,children:[(0,J.jsx)(F,{className:`w-3 h-3`}),i]}),a>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-400`,children:[(0,J.jsx)(_,{className:`w-3 h-3`}),a]}),(0,J.jsx)(`span`,{title:o??void 0,children:o?fe(o,l,g):null})]})]}),!t&&(0,J.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:e.items.map(e=>(0,J.jsx)(Qe,{item:e,onRemove:()=>s(e),onRequeue:()=>c(e),timeFormat:l,hasPermission:m,canModify:h,t:g},e.id))})]},`batch-${e.batchId}`)})}),e.length>t&&(0,J.jsxs)(`div`,{className:`mt-4 flex flex-col items-center gap-2`,children:[(0,J.jsx)(R,{variant:`secondary`,size:`sm`,onClick:n,children:g(`queue.history.showMore`)}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:g(`queue.history.showingCount`,{shown:Math.min(t,e.length),total:e.length})})]})]})}var Tt=50;function $(){let{t:e}=a(),t=o(),{showToast:n}=O(),{hasPermission:u,hasAnyPermission:p,canModify:_}=Ie(),[b,ne]=(0,q.useState)(null),[T,re]=(0,q.useState)(``),[E,k]=(0,q.useState)(``),[A,j]=(0,q.useState)(!1),[M,ae]=(0,q.useState)(null),[P,oe]=(0,q.useState)(null),[F,I]=(0,q.useState)(null),[L,ue]=(0,q.useState)([]),[fe,me]=(0,q.useState)(!1),[ge,_e]=(0,q.useState)(null),[B,ve]=(0,q.useState)(()=>localStorage.getItem(`queue.historySortBy`)||`date`),[V,xe]=(0,q.useState)(()=>{let e=localStorage.getItem(`queue.historySortAsc`);return e===null?!1:e===`true`}),[Se,Ce]=(0,q.useState)(Tt),[U,W]=(0,q.useState)(()=>localStorage.getItem(`queue.pendingSortBy`)||`position`),[Te,De]=(0,q.useState)(()=>{let e=localStorage.getItem(`queue.pendingSortAsc`);return e===null?!0:e===`true`}),[ke]=(0,q.useState)(()=>{let e=Number(new URLSearchParams(window.location.search).get(`batch`));return Number.isInteger(e)&&e>0?e:null}),[G,Ae]=(0,q.useState)(()=>{let e=new URLSearchParams(window.location.search),t=e.get(`tab`);if(e.get(`batch`))return`batches`;if(t===`pipelines`||t===`history`||t===`timeline`||t===`queue`||t===`batches`)return t;let n=localStorage.getItem(`queue.activeTab`);return n===`history`||n===`timeline`||n===`pipelines`||n===`batches`?n:`queue`}),[je,Me]=(0,q.useState)(()=>localStorage.getItem(`queue.activeLayout`)===`printer`?`printer`:`position`),[K,Pe]=(0,q.useState)(()=>{try{let e=localStorage.getItem(`queue.batchCollapsed`);return e?JSON.parse(e):{}}catch{return{}}}),[Fe,Be]=(0,q.useState)(null),[Ve,Ue]=(0,q.useState)(!1),[We,Y]=(0,q.useState)(null);(0,q.useEffect)(()=>{localStorage.setItem(`queue.historySortBy`,B)},[B]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.historySortAsc`,String(V))},[V]),(0,q.useEffect)(()=>{Ce(Tt)},[B,V,E]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.pendingSortBy`,U)},[U]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.pendingSortAsc`,String(Te))},[Te]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.activeTab`,G)},[G]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.activeLayout`,je)},[je]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.batchCollapsed`,JSON.stringify(K))},[K]);let Ke=S(g(te,{activationConstraint:{distance:8}}),g(y,{coordinateGetter:v})),{data:X}=s({queryKey:[`settings`],queryFn:r.getSettings}),qe=X?.time_format||`system`,{data:Je}=s({queryKey:[`batches`,`active`],queryFn:()=>r.getBatches(`active`)}),Ye=Je?.length??0,{data:Z,isLoading:Ze}=s({queryKey:[`queue`,b,T],queryFn:()=>r.getQueue(b||void 0,T||void 0),refetchInterval:5e3}),{data:Qe}=s({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),$e=c({mutationFn:e=>r.updateSettings({queue_shortest_first:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]})}}),tt=c({mutationFn:e=>r.cancelQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.cancelled`))},onError:()=>n(e(`queue.toast.cancelFailed`),`error`)}),nt=c({mutationFn:e=>r.removeFromQueue(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(r.deleted===!1?e(`queue.toast.keptForOrder`):e(`queue.toast.removed`))},onError:()=>n(e(`queue.toast.removeFailed`),`error`)}),rt=c({mutationFn:e=>r.stopQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.stopped`))},onError:()=>n(e(`queue.toast.stopFailed`),`error`)}),[it,at]=(0,q.useState)(null),[ot,st]=(0,q.useState)(null),ct=c({mutationFn:({id:e,skipFilamentCheck:t})=>r.startQueueItem(e,{skipFilamentCheck:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.released`)),at(null),st(null)},onError:(t,r)=>{if(t instanceof i&&t.status===409&&t.code===`insufficient_filament`){let e=t.detail?.deficit??[];at({itemId:r.id,deficit:e});return}if(t instanceof i&&t.status===409&&t.code===`unmatched_filament`){let e=t.detail?.missing??[];st({itemId:r.id,missing:e});return}n(e(`queue.toast.startFailed`),`error`)}}),dt=c({mutationFn:e=>r.reorderQueue(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]})},onError:()=>n(e(`queue.toast.reorderFailed`),`error`)}),ft=c({mutationFn:async()=>{let e=Z?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[],t=0,n=0;for(let i of e)(await r.removeFromQueue(i.id)).deleted===!1?n+=1:t+=1;return{cleared:t,kept:n}},onSuccess:({cleared:r,kept:i})=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(i>0?`${e(`queue.toast.historyCleared`,{count:r})} ${e(`queue.toast.historyKeptForOrders`,{kept:i})}`:e(`queue.toast.historyCleared`,{count:r}))},onError:()=>n(e(`queue.toast.clearHistoryFailed`),`error`)}),pt=c({mutationFn:e=>r.bulkUpdateQueue(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`queue`]}),ue([]),me(!1),n(e.message)},onError:()=>n(e(`queue.toast.updateFailed`),`error`)}),mt=c({mutationFn:async e=>{for(let t of e)await r.cancelQueueItem(t);return e.length},onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),ue([]),n(e(`queue.toast.bulkCancelled`,{count:r}))},onError:()=>n(e(`queue.toast.bulkCancelFailed`),`error`)}),ht=c({mutationFn:e=>r.resumeQueueAfterFailure(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),_e(null),n(e(`queue.toast.resumedAfterFailure`,{restored:r.restored,acknowledged:r.acknowledged}))},onError:()=>n(e(`queue.toast.resumeAfterFailureFailed`),`error`)}),gt=c({mutationFn:e=>r.createBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),ue([]),Ue(!1),Pe(e=>({...e,[r.id]:!1})),n(e(`queue.toast.batchCreated`,{name:r.name}))},onError:()=>n(e(`queue.toast.batchCreateFailed`),`error`)}),vt=c({mutationFn:e=>r.ungroupBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),Y(null),n(e(`queue.toast.batchUngrouped`,{count:r.ungrouped_count}))},onError:()=>n(e(`queue.toast.batchUngroupFailed`),`error`)}),Q=e=>{ue(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},bt=(0,q.useMemo)(()=>{let e=new Set;return Qe?.forEach(t=>{t.location&&e.add(t.location)}),Z?.forEach(t=>{t.target_location&&e.add(t.target_location)}),Array.from(e).sort()},[Qe,Z]),Ct=(0,q.useCallback)(e=>E?e.target_location?e.target_location===E:e.printer_id?Qe?.find(t=>t.id===e.printer_id)?.location===E:!1:!0,[E,Qe]),$=(0,q.useMemo)(()=>{let e=Z?.filter(e=>e.status===`pending`)||[];E&&(e=e.filter(Ct));let t=e=>{if(!e.scheduled_time)return 0;let t=z(e.scheduled_time)?.getTime()??0;return t>Date.now()+4320*60*60*1e3?0:t};return X?.queue_shortest_first?[...e].sort((e,t)=>et(e,t,!0)):[...e].sort((e,n)=>{let r;if(U===`name`){let t=e.archive_name||e.library_file_name||``,i=n.archive_name||n.library_file_name||``;r=t.localeCompare(i)}else r=U===`printer`?(e.printer_name||``).localeCompare(n.printer_name||``):U===`time`?t(e)-t(n):e.position-n.position;return Te?r:-r})},[Z,U,Te,Ct,E,X?.queue_shortest_first]),Dt=()=>{let e=$.map(e=>e.id);L.length===e.length?ue([]):ue(e)},Ot=(0,q.useMemo)(()=>{let e=Z?.filter(e=>e.status===`printing`)||[];return E&&(e=e.filter(Ct)),e},[Z,E,Ct]),kt=(0,q.useMemo)(()=>{let e=new Set;if(!Z)return e;let t=new Set;Z.forEach(e=>{e.status===`printing`&&e.printer_id&&t.add(e.printer_id)});let n=e=>e.scheduled_time?(z(e.scheduled_time)?.getTime()??0)>Date.now():!1,r=(e,t)=>et(e,t,X?.queue_shortest_first??!1),i=new Map;return Z.filter(e=>e.status===`pending`&&e.printer_id!=null&&!e.manual_start&&!n(e)).sort(r).forEach(e=>{let t=i.get(e.printer_id)??[];t.push(e),i.set(e.printer_id,t)}),Z.forEach(r=>{if(r.status===`pending`&&!r.waiting_reason&&!n(r)&&!(r.print_time_seconds==null||r.print_time_seconds<=0)&&!r.require_previous_success){if(r.printer_id==null){e.add(r.id);return}if(!t.has(r.printer_id)){if(r.manual_start){e.add(r.id);return}i.get(r.printer_id)?.[0]?.id===r.id&&e.add(r.id)}}}),e},[Z,X?.queue_shortest_first]),[At,jt]=(0,q.useState)(()=>Date.now()),Mt=kt.size>0;(0,q.useEffect)(()=>{if(!Mt)return;jt(Date.now());let e=setInterval(()=>jt(Date.now()),3e4);return()=>clearInterval(e)},[Mt]);let Nt=(0,q.useMemo)(()=>{let e=new Set;return Ot.forEach(t=>{t.printer_id&&e.add(t.printer_id)}),Array.from(e)},[Ot]),Pt=l({queries:Nt.map(e=>({queryKey:[`printerStatus`,e],queryFn:()=>r.getPrinterStatus(e),refetchInterval:5e3}))}),Ft=(0,q.useMemo)(()=>{let e={};return Nt.forEach((t,n)=>{let r=Pt[n];r?.data?.state&&(e[t]=r.data.state)}),e},[Nt,Pt]),It=(0,q.useMemo)(()=>{let e={};return Nt.forEach((t,n)=>{let r=Pt[n];r?.data&&(e[t]={progress:r.data.progress??void 0,remaining_time:r.data.remaining_time??void 0,state:r.data.state??void 0})}),e},[Nt,Pt]),Lt=(0,q.useMemo)(()=>{let e=Z?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[];return E&&(e=e.filter(Ct)),[...e].sort((e,t)=>{let n;if(B===`name`){let r=e.archive_name||e.library_file_name||``,i=t.archive_name||t.library_file_name||``;n=r.localeCompare(i)}else n=B===`printer`?(e.printer_name||``).localeCompare(t.printer_name||``):(z(t.completed_at||t.created_at)?.getTime()??0)-(z(e.completed_at||e.created_at)?.getTime()??0);return V?-n:n})},[Z,B,V,Ct,E]),Rt=(0,q.useMemo)(()=>$.reduce((e,t)=>e+(t.print_time_seconds||0),0),[$]),zt=(0,q.useMemo)(()=>$.reduce((e,t)=>e+(t.filament_used_grams||0),0),[$]),Bt=e=>{let t=e.active.id;Be(typeof t==`number`||typeof t==`string`?t:null)},Vt=e=>{let{active:t,over:n}=e;if(Be(null),!n||t.id===n.id)return;let r,i=t.id;if(typeof i==`string`&&i.startsWith(`batch-`)){let e=Number(i.slice(6));r=$.filter(t=>t.batch_id===e).map(e=>e.id)}else{let e=i;r=L.includes(e)&&L.length>1?L.slice().sort((e,t)=>$.findIndex(t=>t.id===e)-$.findIndex(e=>e.id===t)):[e]}if(r.length===0)return;let a,o=n.id;if(typeof o==`string`&&o.startsWith(`batch-`)){let e=Number(o.slice(6));a=$.findIndex(t=>t.batch_id===e)}else a=$.findIndex(e=>e.id===o);if(a===-1)return;let s=$[a],c=$.filter(e=>!r.includes(e.id)),l=c.findIndex(e=>e.id===s.id);l===-1&&(l=a),$.findIndex(e=>e.id===r[0])<a&&(l+=1);let u=[...c.slice(0,l),...r.map(e=>$.find(t=>t.id===e)).filter(e=>!!e),...c.slice(l)].map((e,t)=>({id:e.id,position:t+1}));dt.mutate(u)},Ht=(0,q.useMemo)(()=>{let t=[],n=new Set;for(let r of $)if(r.batch_id!=null){if(n.has(r.batch_id))continue;n.add(r.batch_id);let i=$.filter(e=>e.batch_id===r.batch_id);t.push({kind:`batch`,batchId:r.batch_id,batchName:r.batch_name||e(`queue.batch.defaultName`),items:i})}else t.push({kind:`item`,item:r});return t},[$,e]),Ut=u(`queue:reorder`)&&U===`position`&&!X?.queue_shortest_first,Wt=e=>e.kind===`item`?[e.item.id]:e.items.map(e=>e.id),Gt=(e,t,n)=>{let r=$.filter(t=>!e.includes(t.id)),i=r.findIndex(e=>e.id===t);if(i===-1)return;n&&(i+=1);let a=e.map(e=>$.find(t=>t.id===e)).filter(e=>!!e),o=[...r.slice(0,i),...a,...r.slice(i)];dt.mutate(o.map((e,t)=>({id:e.id,position:t+1})))},Kt=(e,t)=>{if(!Ut)return{};let n=Wt(e[t]);return{onMoveUp:t>0?()=>Gt(n,Wt(e[t-1])[0],!1):void 0,onMoveDown:t<e.length-1?()=>{let r=Wt(e[t+1]);Gt(n,r[r.length-1],!0)}:void 0}},qt=(0,q.useMemo)(()=>{let e=[];for(let t of Ht)if(t.kind===`item`)e.push(t.item.id);else if(e.push(`batch-${t.batchId}`),!(K[t.batchId]??!0))for(let n of t.items)e.push(n.id);return e},[Ht,K]),Jt=(0,q.useMemo)(()=>L.length<2?!1:L.every(e=>{let t=$.find(t=>t.id===e);return t&&t.batch_id==null}),[L,$]),Yt=e=>{Pe(t=>({...t,[e]:!(t[e]??!0)}))},Xt=(0,q.useMemo)(()=>{let t=new Map,n=t=>{if(t.printer_id)return{key:`printer:${t.printer_id}`,label:t.printer_name||`Printer #${t.printer_id}`,printerId:t.printer_id,targetModel:null,isUnassigned:!1};if((t.variants?.length??0)>1){let n=t.variants.map(e=>e.target_model).join(` / `);return{key:`models:${n}`,label:`${e(`queue.filter.any`)} ${n}`,printerId:null,targetModel:null,isUnassigned:!1}}return t.target_model?{key:`model:${t.target_model}`,label:`${e(`queue.filter.any`)} ${t.target_model}`,printerId:null,targetModel:t.target_model,isUnassigned:!1}:{key:`unassigned`,label:e(`queue.filter.unassigned`),printerId:null,targetModel:null,isUnassigned:!0}};for(let e of Ht){let r=e.kind===`item`?e.item:e.items[0];if(!r)continue;let i=n(r);t.has(i.key)||t.set(i.key,{...i,rows:[]}),t.get(i.key).rows.push(e)}return Array.from(t.values()).sort((e,t)=>e.isUnassigned&&!t.isUnassigned?1:!e.isUnassigned&&t.isUnassigned?-1:e.label.localeCompare(t.label))},[Ht,e]),Zt=(0,q.useMemo)(()=>{let e=new Map;return Z?.forEach(t=>{if(t.status===`skipped`&&t.error_message===`Previous print failed or was aborted`&&t.printer_id){let n=e.get(t.printer_id);n?n.count+=1:e.set(t.printer_id,{name:t.printer_name||`Printer #${t.printer_id}`,count:1})}}),Array.from(e.entries()).map(([e,{name:t,count:n}])=>({printerId:e,printerName:t,skippedCount:n})).sort((e,t)=>e.printerName.localeCompare(t.printerName))},[Z]),Qt=e=>{let t=0,n=0,r=0;for(let i of e){let e=i.kind===`item`?[i.item]:i.items;for(let i of e)t+=1,n+=i.print_time_seconds||0,r+=i.filament_used_grams||0}return{count:t,time:n,weight:r}};return(0,J.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-between mb-6`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,J.jsx)(Ne,{className:`w-7 h-7 text-bambu-green`}),e(`queue.title`)]}),(0,J.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`queue.subtitle`)})]})}),(0,J.jsx)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary mb-6 overflow-x-auto`,children:[{id:`queue`,label:e(`queue.tabs.queue`),icon:H,count:$.length+Ot.length},{id:`batches`,label:e(`queue.tabs.batches`),icon:N,count:Ye},{id:`history`,label:e(`queue.tabs.history`),icon:Ne,count:Lt.length},{id:`timeline`,label:e(`queue.tabs.timeline`),icon:Re,count:null},{id:`pipelines`,label:e(`queue.tabs.pipelines`),icon:se,count:null}].map(({id:e,label:t,icon:n,count:r})=>(0,J.jsxs)(`button`,{onClick:()=>Ae(e),className:`px-4 py-2.5 text-sm flex items-center gap-2 border-b-2 -mb-px transition-colors whitespace-nowrap ${G===e?`text-white border-bambu-green font-medium`:`text-bambu-gray border-transparent hover:text-white`}`,children:[(0,J.jsx)(n,{className:`w-4 h-4`}),t,r!==null&&r>0&&(0,J.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${G===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:r})]},e))}),G!==`pipelines`&&G!==`batches`&&(0,J.jsx)(Xe,{activeCount:Ot.length,pendingCount:$.length,totalTime:Rt,totalWeight:zt,historyCount:Lt.length,t:e}),G===`queue`&&Zt.length>0&&u(`queue:update_all`)&&(0,J.jsx)(`div`,{className:`mb-4 space-y-2`,children:Zt.map(({printerId:t,printerName:n,skippedCount:r})=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-orange-50 dark:bg-orange-500/10 border border-orange-300 dark:border-orange-500/30 rounded-lg`,children:[(0,J.jsx)(D,{className:`w-5 h-5 text-orange-600 dark:text-orange-400 flex-shrink-0`}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-sm text-orange-800 dark:text-orange-200`,children:e(`queue.resumeAfterFailure.banner`,{printer:n,count:r})}),(0,J.jsx)(`div`,{className:`text-xs text-orange-800/80 dark:text-orange-200/70 mt-0.5`,children:e(`queue.resumeAfterFailure.bannerHint`)})]}),(0,J.jsxs)(`button`,{onClick:()=>_e({printerId:t,printerName:n,skippedCount:r}),className:`flex items-center gap-1.5 px-3 py-1.5 bg-orange-100 dark:bg-orange-500/20 hover:bg-orange-200 dark:hover:bg-orange-500/30 text-orange-900 dark:text-orange-100 text-sm rounded-md border border-orange-300 dark:border-orange-500/40 transition-colors flex-shrink-0`,children:[(0,J.jsx)(ze,{className:`w-4 h-4`}),e(`queue.resumeAfterFailure.button`)]})]},t))}),G!==`pipelines`&&G!==`batches`&&(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-4 mb-6`,children:[(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:b===-1?`unassigned`:b||``,onChange:e=>{let t=e.target.value;ne(t===`unassigned`?-1:t===``?null:Number(t))},children:[(0,J.jsx)(`option`,{value:``,children:e(`queue.filter.allPrinters`)}),(0,J.jsx)(`option`,{value:`unassigned`,children:e(`queue.filter.unassigned`)}),Qe?.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:T,onChange:e=>re(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:e(`queue.filter.allStatus`)}),(0,J.jsx)(`option`,{value:`pending`,children:e(`queue.status.pending`)}),(0,J.jsx)(`option`,{value:`printing`,children:e(`queue.status.printing`)}),(0,J.jsx)(`option`,{value:`completed`,children:e(`queue.status.completed`)}),(0,J.jsx)(`option`,{value:`failed`,children:e(`queue.status.failed`)}),(0,J.jsx)(`option`,{value:`skipped`,children:e(`queue.status.skipped`)}),(0,J.jsx)(`option`,{value:`cancelled`,children:e(`queue.status.cancelled`)})]}),bt.length>0&&(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:E,onChange:e=>k(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:e(`queue.filter.allLocations`)}),bt.map(e=>(0,J.jsx)(`option`,{value:e,children:e},e))]}),(0,J.jsx)(`div`,{className:`hidden sm:block flex-1`}),G===`history`&&Lt.length>0&&(0,J.jsxs)(R,{className:`w-full sm:w-auto`,variant:`secondary`,size:`sm`,onClick:()=>j(!0),disabled:!u(`queue:delete_all`),title:u(`queue:delete_all`)?void 0:e(`queue.permissions.noClearHistory`),children:[(0,J.jsx)(he,{className:`w-4 h-4`}),e(`queue.clearHistory`)]})]}),G===`queue`&&(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mb-6`,children:[(0,J.jsxs)(`div`,{className:`inline-flex items-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,J.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${je===`position`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>Me(`position`),title:e(`queue.layout.flatList`),children:[(0,J.jsx)(ie,{className:`w-3.5 h-3.5`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.flatList`)})]}),(0,J.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${je===`printer`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>Me(`printer`),title:e(`queue.layout.groupByPrinter`),children:[(0,J.jsx)(ye,{className:`w-3.5 h-3.5`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.byPrinter`)})]})]}),(0,J.jsxs)(`button`,{onClick:()=>{let e=!(X?.queue_shortest_first??!1);$e.mutate(e)},className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded-lg border transition-colors ${X?.queue_shortest_first?`bg-bambu-green/20 border-bambu-green text-bambu-green`:`bg-bambu-dark-secondary border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,title:e(`queue.sjf.tooltip`,`Shortest Job First — scheduler prioritizes shorter prints`),children:[(0,J.jsx)(He,{className:`w-4 h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.sjf.label`,`SJF`)}),(0,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${X?.queue_shortest_first?`bg-bambu-green`:`bg-bambu-gray`}`})]})]}),G===`pipelines`?(0,J.jsx)(Ge,{}):G===`batches`?(0,J.jsx)(ut,{hasPermission:u,t:e,focusBatchId:ke}):Ze?(0,J.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):Z?.length===0?(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(w,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:e(`queue.empty.title`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:e(`queue.empty.description`)})]}):G===`timeline`?(0,J.jsx)(lt,{queueItems:Z||[],printers:Qe||[],printerStatuses:It,sjfEnabled:X?.queue_shortest_first??!1,onItemClick:e=>{[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status)?oe(e):e.status===`pending`?ae(e):e.status===`printing`&&I({type:`stop`,item:e})},t:e}):G===`history`?(0,J.jsx)(wt,{items:Lt,collapsed:!1,visibleCount:Se,onShowMore:()=>Ce(e=>e+Tt),sortBy:B,sortAsc:V,onSortByChange:ve,onSortAscToggle:()=>xe(!V),onRemove:e=>I({type:`remove`,item:e}),onRequeue:oe,timeFormat:qe,batchCollapsed:K,toggleBatchCollapsed:Yt,hasPermission:u,canModify:_,t:e}):(0,J.jsxs)(`div`,{className:`space-y-6 sm:space-y-8`,children:[Ot.length>0&&(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2`,children:[(0,J.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-400 animate-pulse`}),e(`queue.sections.currentlyPrinting`)]}),(0,J.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Ot.map(t=>(0,J.jsx)(xt,{item:t,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>I({type:`stop`,item:t}),onRequeue:()=>{},onStart:()=>{},timeFormat:qe,hasPermission:u,canModify:_,printerState:t.printer_id?Ft[t.printer_id]:null,t:e},t.id))})]}),$.length>0&&(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,J.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[(0,J.jsx)(H,{className:`w-4 h-4 sm:w-5 sm:h-5 text-yellow-600 dark:text-yellow-400`}),e(`queue.sections.queued`),(0,J.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,e(`queue.itemCount`,{count:$.length}),`)`]}),(0,J.jsx)(`span`,{className:`hidden sm:inline text-xs text-bambu-gray ml-2`,title:e(`queue.reorderHint`),children:e(`queue.dragToReorder`)})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:U,onChange:e=>W(e.target.value),children:[(0,J.jsx)(`option`,{value:`position`,children:e(`queue.sort.byPosition`)}),(0,J.jsx)(`option`,{value:`name`,children:e(`queue.sort.byName`)}),(0,J.jsx)(`option`,{value:`printer`,children:e(`queue.sort.byPrinter`)}),(0,J.jsx)(`option`,{value:`time`,children:e(`queue.sort.bySchedule`)})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>De(!Te),title:e(Te?`common.ascending`:`common.descending`),className:`px-2`,children:Te?(0,J.jsx)(f,{className:`w-4 h-4`}):(0,J.jsx)(d,{className:`w-4 h-4`})})]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg`,children:[(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:Dt,className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm`,children:[L.length===$.length&&$.length>0?(0,J.jsx)(we,{className:`w-4 h-4 text-bambu-green`}):(0,J.jsx)(be,{className:`w-4 h-4`}),L.length===$.length&&$.length>0?e(`queue.bulkEdit.deselectAll`):e(`queue.bulkEdit.selectAll`)]}),L.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e(`queue.bulkEdit.selected`,{count:L.length})}),(0,J.jsx)(`div`,{className:`hidden sm:block h-4 w-px bg-bambu-dark-tertiary`}),Jt&&(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>Ue(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200`,title:e(`queue.batch.groupAsBatch`),children:[(0,J.jsx)(N,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.batch.groupAsBatch`)})]}),(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>me(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light`,disabled:!p(`queue:update_own`,`queue:update_all`),title:p(`queue:update_own`,`queue:update_all`)?e(`queue.bulkEdit.editSelected`):e(`queue.permissions.noEditItems`),children:[(0,J.jsx)(pe,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.editSelected`)})]}),(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>mt.mutate(L),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,disabled:mt.isPending||!p(`queue:delete_own`,`queue:delete_all`),title:p(`queue:delete_own`,`queue:delete_all`)?e(`queue.bulkEdit.cancelSelected`):e(`queue.permissions.noCancelItems`),children:[(0,J.jsx)(ce,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.cancelSelected`)})]})]})]}),(0,J.jsxs)(ee,{sensors:Ke,collisionDetection:h,onDragStart:Bt,onDragEnd:Vt,children:[(0,J.jsx)(C,{items:qt,strategy:x,children:je===`position`?(0,J.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Ht.map((t,n)=>(0,J.jsx)(St,{row:t,collapsed:t.kind===`batch`?K[t.batchId]??!0:!1,onToggleBatch:t.kind===`batch`?()=>Yt(t.batchId):void 0,onUngroup:t.kind===`batch`?()=>Y(t.batchId):void 0,setEditItem:ae,setConfirmAction:I,startMutation:ct,selectedItems:L,handleToggleSelect:Q,timeFormat:qe,hasPermission:u,canModify:_,t:e,etaEligibleIds:kt,etaNow:At,aggregateForRows:Qt,...Kt(Ht,n),onMoveBlock:Ut?Gt:void 0},t.kind===`item`?`item-${t.item.id}`:`batch-${t.batchId}`))}):(0,J.jsx)(`div`,{className:`space-y-4`,children:Xt.map(t=>{let n=Qt(t.rows);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-t-lg`,children:[(0,J.jsx)(ye,{className:`w-4 h-4 ${t.isUnassigned?`text-orange-600 dark:text-orange-400`:t.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,J.jsx)(`span`,{className:`font-semibold text-white text-sm`,children:t.label}),(0,J.jsxs)(`span`,{className:`text-xs text-bambu-gray flex flex-wrap gap-x-3`,children:[(0,J.jsx)(`span`,{children:e(`queue.itemCount`,{count:n.count})}),n.time>0&&(0,J.jsx)(`span`,{children:de(n.time)}),n.weight>0&&(0,J.jsx)(`span`,{children:_t(n.weight)})]})]}),(0,J.jsx)(`div`,{className:`bg-bambu-dark/40 border border-t-0 border-bambu-dark-tertiary rounded-b-lg p-2 space-y-2`,children:t.rows.map((n,r)=>(0,J.jsx)(St,{row:n,collapsed:n.kind===`batch`?K[n.batchId]??!0:!1,onToggleBatch:n.kind===`batch`?()=>Yt(n.batchId):void 0,onUngroup:n.kind===`batch`?()=>Y(n.batchId):void 0,setEditItem:ae,setConfirmAction:I,startMutation:ct,selectedItems:L,handleToggleSelect:Q,timeFormat:qe,hasPermission:u,canModify:_,t:e,etaEligibleIds:kt,etaNow:At,aggregateForRows:Qt,...Kt(t.rows,r),onMoveBlock:Ut?Gt:void 0},n.kind===`item`?`item-${n.item.id}`:`batch-${n.batchId}`))})]},t.key)})})}),(0,J.jsx)(m,{children:(()=>{if(Fe===null)return null;if(typeof Fe==`string`&&Fe.startsWith(`batch-`)){let t=Number(Fe.slice(6)),n=$.filter(e=>e.batch_id===t);if(n.length===0)return null;let r=n[0].batch_name||e(`queue.batch.defaultName`);return(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,J.jsx)(N,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.batch`,{defaultValue:`{{name}} ({{count}} copies)`,name:r,count:n.length})})]})}return typeof Fe==`number`&&L.includes(Fe)&&L.length>1?(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,J.jsx)(N,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.multiCount`,{count:L.length})})]}):null})()})]})]})]}),M&&(0,J.jsx)(Oe,{mode:`edit-queue-item`,archiveId:M.archive_id??void 0,libraryFileId:M.library_file_id??void 0,archiveName:Le(M,t=>e(`common.plusNMore`,{count:t})),queueItem:M,onClose:()=>ae(null)}),P&&(0,J.jsx)(Oe,{mode:`create`,archiveId:P.archive_id??void 0,libraryFileId:P.library_file_id??void 0,archiveName:Le(P,t=>e(`common.plusNMore`,{count:t})),onClose:()=>oe(null)}),it&&(0,J.jsx)(Ee,{title:e(`queue.filamentShort.confirmTitle`),message:e(`queue.filamentShort.confirmIntro`)+`
`+it.deficit.map(t=>e(`queue.filamentShort.lineItem`,{slot:t.slot_id,required:Math.round(t.required_grams),remaining:t.remaining_grams==null?e(`queue.filamentShort.unknown`):Math.round(t.remaining_grams)})).join(`
`),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{ct.mutate({id:it.itemId,skipFilamentCheck:!0})},onCancel:()=>at(null)}),ot&&(0,J.jsx)(Ee,{title:e(`queue.filamentMissing.confirmTitle`),message:e(`queue.filamentMissing.confirmIntro`)+`
`+ot.missing.join(`
`),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{ct.mutate({id:ot.itemId,skipFilamentCheck:!0})},onCancel:()=>st(null)}),F&&(0,J.jsx)(Ee,{title:F.type===`cancel`?e(`queue.confirm.cancelTitle`):F.type===`stop`?e(`queue.confirm.stopTitle`):e(`queue.confirm.removeTitle`),message:F.type===`cancel`?e(`queue.confirm.cancelMessage`,{name:F.item.archive_name||F.item.library_file_name||e(`queue.confirm.thisPrint`)}):F.type===`stop`?e(`queue.confirm.stopMessage`,{name:F.item.archive_name||F.item.library_file_name||e(`queue.confirm.thisPrint`)}):e(`queue.confirm.removeMessage`,{name:F.item.archive_name||F.item.library_file_name||e(`queue.confirm.thisItem`)}),confirmText:F.type===`cancel`?e(`queue.confirm.cancelButton`):F.type===`stop`?e(`queue.confirm.stopButton`):e(`common.remove`),variant:`danger`,onConfirm:()=>{F.type===`cancel`?tt.mutate(F.item.id):F.type===`stop`?rt.mutate(F.item.id):nt.mutate(F.item.id),I(null)},onCancel:()=>I(null)}),ge&&(0,J.jsx)(Ee,{title:e(`queue.resumeAfterFailure.confirmTitle`),message:e(`queue.resumeAfterFailure.confirmMessage`,{printer:ge.printerName,count:ge.skippedCount}),confirmText:e(`queue.resumeAfterFailure.button`),variant:`warning`,onConfirm:()=>ht.mutate(ge.printerId),onCancel:()=>_e(null)}),A&&(0,J.jsx)(Ee,{title:e(`queue.confirm.clearHistoryTitle`),message:e(`queue.confirm.clearHistoryMessage`,{count:Lt.length}),confirmText:e(`queue.clearHistory`),variant:`danger`,onConfirm:()=>{ft.mutate(),j(!1)},onCancel:()=>j(!1)}),fe&&(0,J.jsx)(yt,{selectedCount:L.length,printers:Qe?.map(e=>({id:e.id,name:e.name,nozzle_count:e.nozzle_count}))||[],onSave:e=>{Object.keys(e).length>0&&pt.mutate({item_ids:L,...e})},onClose:()=>me(!1),isSaving:pt.isPending,canControlPrinter:u(`printers:control`),hasGcodeSnippets:!!X?.gcode_snippets,t:e}),Ve&&(0,J.jsx)(Et,{itemCount:L.length,isSaving:gt.isPending,defaultName:(()=>{let t=$.find(e=>L.includes(e.id)),n=(t?.archive_name||t?.library_file_name||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``);return n?`${n}`:e(`queue.batch.defaultName`)})(),onSave:e=>gt.mutate({name:e,item_ids:L}),onClose:()=>Ue(!1),t:e}),We!==null&&(0,J.jsx)(Ee,{title:e(`queue.batch.ungroupConfirmTitle`),message:e(`queue.batch.ungroupConfirmMessage`),confirmText:e(`queue.batch.ungroup`),variant:`warning`,onConfirm:()=>vt.mutate(We),onCancel:()=>Y(null)})]})}function Et({itemCount:e,defaultName:t,isSaving:n,onSave:r,onClose:i,t:a}){let[o,s]=(0,q.useState)(t);return(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 w-full max-w-md`,children:[(0,J.jsxs)(`h3`,{className:`text-lg font-semibold text-white mb-2 flex items-center gap-2`,children:[(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),a(`queue.batch.groupAsBatch`)]}),(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:a(`queue.batch.groupAsBatchDescription`,{count:e})}),(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`queue.batch.nameLabel`)}),(0,J.jsx)(`input`,{type:`text`,autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:a(`queue.batch.namePlaceholder`),maxLength:120,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 mb-5`}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:i,disabled:n,children:a(`common.cancel`)}),(0,J.jsx)(R,{variant:`primary`,size:`sm`,onClick:()=>{let e=o.trim();e&&r(e)},disabled:n||!o.trim(),children:a(n?`common.saving`:`queue.batch.create`)})]})]})})}export{$ as QueuePage};