import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{T as t,a as n,k as r,w as i}from"./client-DWQBE01c.js";import{n as a}from"./QueryClientProvider-CfzZA5MJ.js";import{t as o}from"./useQuery-Q4exvDrv.js";import{t as s}from"./useMutation-D7HomC3_.js";import{t as c}from"./chevron-right-CposVUhM.js";import{t as l}from"./chevron-left-bnx2dB0Q.js";import{n as u}from"./ToastContext-Bg6SLDR7.js";import{t as d}from"./cog-CzVm_nY6.js";import{t as f}from"./download-8MUb8xIU.js";import{t as p}from"./loader-circle-QIogdiwG.js";import{t as m}from"./play-D5SXD38Y.js";import{t as h}from"./printer-B0-V64ms.js";import{t as g}from"./trash-2-BeUbCuhB.js";import{t as _}from"./triangle-alert-C-5b4OJS.js";import{t as v}from"./x-Ros7hs1-.js";import{t as y}from"./Button-CDViejCk.js";import{t as b}from"./ConfirmModal-FHGIQVx7.js";import{n as x}from"./useUiSettings-DNDF6KSU.js";import{t as S}from"./index-OinXTHRj.js";var C=e(r(),1),w=i();function T({source:e,onClose:r}){let{t:i}=t(),c=a(),{showToast:l}=u(),[d,f]=(0,C.useState)(null),[p,h]=(0,C.useState)(null),[g,_]=(0,C.useState)(1),{trackJob:y}=S(),{data:b,isLoading:T}=o({queryKey:[`slicer-pipelines`],queryFn:()=>n.listSlicerPipelines()}),{data:O}=o({queryKey:[`printers`],queryFn:()=>n.getPrinters()}),{data:k}=x(),A=k?.pipeline_max_copies??50,j={kind:e.kind,id:e.id},M=s({mutationFn:e=>n.checkPipelineEligibility(e,j)}),N=s({mutationFn:({pipelineId:e,force:t})=>n.runPipeline(e,j,t,g),onSuccess:t=>{c.invalidateQueries({queryKey:[`slicer-pipelines`]}),c.invalidateQueries({queryKey:[`pipeline-runs`]}),t.slice_job_id&&y(t.slice_job_id,e.kind,e.filename),l(i(`library.runWithPipeline.toast.started`,`Pipeline run started`),`success`),r()},onError:e=>{l(e.message||i(`library.runWithPipeline.toast.failed`,`Could not start run`),`error`)}}),P=b?.pipelines??[],F=(O??[]).reduce((e,t)=>(e[t.id]=t,e),{});return(0,w.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:r,role:`dialog`,"aria-modal":`true`,"aria-label":i(`library.runWithPipeline.modalTitle`,`Run with pipeline`),children:(0,w.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md max-h-[80vh] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,w.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,w.jsx)(m,{className:`w-4 h-4 text-bambu-green`}),d&&p?i(`library.runWithPipeline.confirmTitle`,`Confirm run`):i(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,w.jsx)(`button`,{type:`button`,onClick:r,"aria-label":i(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,w.jsx)(v,{className:`w-4 h-4`})})]}),(0,w.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:d&&p?(0,w.jsx)(D,{pipeline:d,report:p,source:e,onBack:()=>{f(null),h(null)},onConfirm:()=>{d&&N.mutate({pipelineId:d.id,force:!0})},running:N.isPending}):(0,w.jsx)(E,{source:e,pipelines:P,printerById:F,loading:T||M.isPending,onPick:async e=>{if(!(e.target_printer_id||e.target_kind===`printer_class`&&e.target_model_class)){l(i(`library.runWithPipeline.noTargetMessage`,`This pipeline has no target printer set. Open it in Settings to pick one.`),`error`);return}f(e);try{let t=await M.mutateAsync(e.id);h(t),t.ok&&N.mutate({pipelineId:e.id,force:!1})}catch(e){l(e instanceof Error&&e.message||i(`library.runWithPipeline.toast.failed`,`Could not start run`),`error`),f(null)}},copies:g,maxCopies:A,onCopiesChange:_})})]})})}function E({source:e,pipelines:n,printerById:r,loading:i,onPick:a,copies:o,maxCopies:s,onCopiesChange:c}){let{t:l}=t();return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[l(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,w.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[l(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,w.jsx)(`input`,{id:`run-pipeline-copies`,type:`number`,min:1,max:s,value:o,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||c(Math.max(1,Math.min(s,t)))},"aria-label":l(`library.runWithPipeline.copies`,`Copies`),className:`w-20 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,w.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:l(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:s})})]}),i&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,w.jsx)(p,{className:`w-4 h-4 animate-spin`}),l(`library.runWithPipeline.loading`,`Loading…`)]}),!i&&n.length===0&&(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`library.runWithPipeline.empty`,`No pipelines saved yet. Open the Slice dialog and click "Save as pipeline" to create one.`)}),!i&&n.length>0&&(0,w.jsx)(`ul`,{className:`space-y-1.5`,"aria-label":l(`library.runWithPipeline.pipelineListAria`,`Available pipelines`),children:n.map(e=>{let t=e.target_kind===`printer_class`,n=e.target_printer_id?r[e.target_printer_id]?.name:null,i=t&&e.target_model_class?l(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):null;return(0,w.jsx)(`li`,{children:(0,w.jsxs)(`button`,{type:`button`,onClick:()=>a(e),disabled:!(e.target_printer_id||t&&e.target_model_class),className:`w-full text-left px-3 py-2 rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(d,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,w.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,w.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,w.jsx)(h,{className:`w-3 h-3`}),i?(0,w.jsx)(`span`,{children:i}):n?(0,w.jsx)(`span`,{children:n}):(0,w.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:l(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function D({pipeline:e,report:n,source:r,onBack:i,onConfirm:a,running:o}){let{t:s}=t();return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,w.jsxs)(`p`,{children:[s(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,w.jsxs)(`p`,{className:`mt-1`,children:[(0,w.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,w.jsx)(`span`,{className:`text-white`,children:r.filename})]}),(0,w.jsxs)(`p`,{children:[(0,w.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,w.jsx)(`span`,{className:`text-white`,children:e.name})]}),n.target_printer_name&&(0,w.jsxs)(`p`,{children:[(0,w.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,w.jsx)(`span`,{className:`text-white`,children:n.target_printer_name})]})]}),(0,w.jsx)(`ul`,{className:`space-y-1.5`,children:n.issues.map((e,t)=>(0,w.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,w.jsx)(_,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,w.jsx)(`span`,{className:`text-bambu-gray`,children:(0,w.jsx)(O,{issue:e})})]},t))}),(0,w.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,w.jsx)(`button`,{type:`button`,onClick:i,disabled:o,className:`px-3 py-1.5 text-xs text-bambu-gray hover:text-white`,children:s(`common.back`,`Back`)}),(0,w.jsxs)(`button`,{type:`button`,onClick:a,disabled:o,className:`px-3 py-1.5 text-xs bg-amber-500 hover:bg-amber-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[o?(0,w.jsx)(p,{className:`w-3 h-3 animate-spin`}):(0,w.jsx)(m,{className:`w-3 h-3`}),s(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function O({issue:e}){let{t:n}=t();switch(e.kind){case`printer_not_set`:return(0,w.jsx)(w.Fragment,{children:n(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,w.jsx)(w.Fragment,{children:n(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,w.jsx)(w.Fragment,{children:n(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,w.jsx)(w.Fragment,{children:n(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,w.jsx)(w.Fragment,{children:n(`library.runWithPipeline.issue.filamentType`,`Filament slot {{slot}}: expected {{expected}}, AMS has {{actual}}`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`filament_color_mismatch`:return(0,w.jsx)(w.Fragment,{children:n(`library.runWithPipeline.issue.filamentColor`,`Filament slot {{slot}}: colour differs (expected {{expected}}, AMS has {{actual}})`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`ams_slot_missing`:return(0,w.jsx)(w.Fragment,{children:n(`library.runWithPipeline.issue.amsSlotMissing`,`AMS slot {{slot}} not available on this printer`,{slot:(e.slot_index??0)+1})});case`filament_unverified`:return(0,w.jsx)(w.Fragment,{children:n(`library.runWithPipeline.issue.filamentUnverified`,`Filament slot {{slot}} comes from a cloud / standard preset and could not be statically verified.`,{slot:(e.slot_index??0)+1})});default:return(0,w.jsx)(w.Fragment,{children:e.kind})}}function k({onFiles:e,onRejected:t,extensions:n,disabled:r=!1}){let[i,a]=(0,C.useState)(!1),o=(0,C.useRef)(e),s=(0,C.useRef)(t),c=(0,C.useRef)(n);(0,C.useEffect)(()=>{o.current=e},[e]),(0,C.useEffect)(()=>{s.current=t},[t]),(0,C.useEffect)(()=>{c.current=n},[n]);let l=(0,C.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),u=(0,C.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),d=(0,C.useCallback)(e=>{if(r)return;e.preventDefault();let t=e.currentTarget,n=e.relatedTarget;(!n||!t.contains(n))&&a(!1)},[r]),f=(0,C.useCallback)(e=>{if(r)return;e.preventDefault(),a(!1);let t=Array.from(e.dataTransfer.files);if(t.length===0)return;let n=c.current,i=n&&n.length>0?t.filter(e=>n.some(t=>e.name.toLowerCase().endsWith(t))):t;i.length>0?o.current(i):s.current?.()},[r]);return(0,C.useEffect)(()=>{if(!i)return;let e=()=>a(!1),t=t=>{t.key===`Escape`&&e()};return document.addEventListener(`drop`,e),document.addEventListener(`dragend`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`drop`,e),document.removeEventListener(`dragend`,e),document.removeEventListener(`keydown`,t)}},[i]),{isDraggingOver:i,dragHandlers:{onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f}}}function A(e){let{archiveName:t,photos:r,initialIndex:i,onClose:a,onDelete:o}=e,[s,u]=(0,C.useState)(()=>Math.min(Math.max(i??0,0),Math.max(r.length-1,0))),[d,p]=(0,C.useState)(!1);if((0,C.useEffect)(()=>{if(d)return;let e=e=>{e.key===`Escape`&&a(),e.key===`ArrowLeft`&&u(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&u(e=>Math.min(r.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a,r.length,d]),(0,C.useEffect)(()=>{s>=r.length&&u(Math.max(0,r.length-1))},[r.length,s]),r.length===0)return a(),null;let m=t=>e.getPhotoUrl?e.getPhotoUrl(t):n.getArchivePhotoUrl(e.archiveId,t),h=r[s],_=m(h);return(0,w.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:e=>{e.stopPropagation(),a()},children:[(0,w.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,w.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,s+1,` of `,r.length]})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsxs)(y,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=_,e.download=`${t}_photo_${s+1}.jpg`,e.click()},children:[(0,w.jsx)(f,{className:`w-4 h-4`}),`Download`]}),o&&(0,w.jsx)(y,{variant:`secondary`,size:`sm`,onClick:()=>{o&&p(!0)},className:`text-red-400 hover:text-red-300`,children:(0,w.jsx)(g,{className:`w-4 h-4`})}),(0,w.jsx)(`button`,{onClick:a,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,w.jsx)(v,{className:`w-6 h-6`})})]})]}),(0,w.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[s>0&&(0,w.jsx)(`button`,{onClick:()=>u(e=>e-1),className:`absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,w.jsx)(l,{className:`w-8 h-8 text-white`})}),(0,w.jsx)(`img`,{src:_,alt:`Photo ${s+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),su(e=>e+1),className:`absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,w.jsx)(c,{className:`w-8 h-8 text-white`})})]}),r.length>1&&(0,w.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:r.map((e,t)=>(0,w.jsx)(`button`,{onClick:()=>u(t),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${t===s?`border-bambu-green`:`border-transparent hover:border-bambu-gray`}`,children:(0,w.jsx)(`img`,{src:m(e),alt:`Thumbnail ${t+1}`,className:`w-full h-full object-cover`})},e))})]}),d&&(0,w.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,w.jsx)(b,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{o?.(h),p(!1)},onCancel:()=>p(!1)})})]})}export{k as n,T as r,A as t};