| 1 |
- import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{n as c}from"./ToastContext-VFOrCCoA.js";import{t as l}from"./cog-pa-nvQzt.js";import{t as u}from"./loader-circle-CB4leTZa.js";import{t as d}from"./play-DROvjtg7.js";import{t as f}from"./triangle-alert-gIik0G2C.js";import{t as p}from"./x-Dctff5l9.js";import{t as m}from"./Button-pwVKPiYn.js";import{At as h,Jt as g,Mn as _,_t as v,jn as y,t as b,wn as x}from"./index-BoVbGTav.js";var S=e(n(),1),C=t();function w({source:e,onClose:t}){let{t:n}=i(),l=a(),{showToast:u}=c(),[f,m]=(0,S.useState)(null),[h,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(1),{trackJob:y}=b(),{data:x,isLoading:w}=o({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:D}=o({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),{data:O}=o({queryKey:[`app-settings`],queryFn:()=>r.getSettings()}),k=O?.pipeline_max_copies??50,A={kind:e.kind,id:e.id},j=s({mutationFn:e=>r.checkPipelineEligibility(e,A)}),M=s({mutationFn:({pipelineId:e,force:t})=>r.runPipeline(e,A,t,_),onSuccess:r=>{l.invalidateQueries({queryKey:[`slicer-pipelines`]}),l.invalidateQueries({queryKey:[`pipeline-runs`]}),r.slice_job_id&&y(r.slice_job_id,e.kind,e.filename),u(n(`library.runWithPipeline.toast.started`,`Pipeline run started`),`success`),t()},onError:e=>{u(e.message||n(`library.runWithPipeline.toast.failed`,`Could not start run`),`error`)}}),N=x?.pipelines??[],P=(D??[]).reduce((e,t)=>(e[t.id]=t,e),{});return(0,C.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:t,role:`dialog`,"aria-modal":`true`,"aria-label":n(`library.runWithPipeline.modalTitle`,`Run with pipeline`),children:(0,C.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,C.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,C.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,C.jsx)(d,{className:`w-4 h-4 text-bambu-green`}),f&&h?n(`library.runWithPipeline.confirmTitle`,`Confirm run`):n(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,C.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,C.jsx)(p,{className:`w-4 h-4`})})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:f&&h?(0,C.jsx)(E,{pipeline:f,report:h,source:e,onBack:()=>{m(null),g(null)},onConfirm:()=>{f&&M.mutate({pipelineId:f.id,force:!0})},running:M.isPending}):(0,C.jsx)(T,{source:e,pipelines:N,printerById:P,loading:w||j.isPending,onPick:async e=>{if(!(e.target_printer_id||e.target_kind===`printer_class`&&e.target_model_class)){u(n(`library.runWithPipeline.noTargetMessage`,`This pipeline has no target printer set. Open it in Settings to pick one.`),`error`);return}m(e);try{let t=await j.mutateAsync(e.id);g(t),t.ok&&M.mutate({pipelineId:e.id,force:!1})}catch{m(null)}},copies:_,maxCopies:k,onCopiesChange:v})})]})})}function T({source:e,pipelines:t,printerById:n,loading:r,onPick:a,copies:o,maxCopies:s,onCopiesChange:c}){let{t:d}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[d(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,C.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[d(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,C.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":d(`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,C.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:d(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:s})})]}),r&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,C.jsx)(u,{className:`w-4 h-4 animate-spin`}),d(`library.runWithPipeline.loading`,`Loading…`)]}),!r&&t.length===0&&(0,C.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d(`library.runWithPipeline.empty`,`No pipelines saved yet. Open the Slice dialog and click "Save as pipeline" to create one.`)}),!r&&t.length>0&&(0,C.jsx)(`ul`,{className:`space-y-1.5`,"aria-label":d(`library.runWithPipeline.pipelineListAria`,`Available pipelines`),children:t.map(e=>{let t=e.target_kind===`printer_class`,r=e.target_printer_id?n[e.target_printer_id]?.name:null,i=t&&e.target_model_class?d(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):null;return(0,C.jsx)(`li`,{children:(0,C.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,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(l,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,C.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,C.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,C.jsx)(g,{className:`w-3 h-3`}),i?(0,C.jsx)(`span`,{children:i}):r?(0,C.jsx)(`span`,{children:r}):(0,C.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:d(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function E({pipeline:e,report:t,source:n,onBack:r,onConfirm:a,running:o}){let{t:s}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,C.jsxs)(`p`,{children:[s(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,C.jsxs)(`p`,{className:`mt-1`,children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:n.filename})]}),(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:e.name})]}),t.target_printer_name&&(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:t.target_printer_name})]})]}),(0,C.jsx)(`ul`,{className:`space-y-1.5`,children:t.issues.map((e,t)=>(0,C.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,C.jsx)(f,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,C.jsx)(`span`,{className:`text-bambu-gray`,children:(0,C.jsx)(D,{issue:e})})]},t))}),(0,C.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:r,disabled:o,className:`px-3 py-1.5 text-xs text-bambu-gray hover:text-white`,children:s(`common.back`,`Back`)}),(0,C.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,C.jsx)(u,{className:`w-3 h-3 animate-spin`}):(0,C.jsx)(d,{className:`w-3 h-3`}),s(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function D({issue:e}){let{t}=i();switch(e.kind){case`printer_not_set`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,C.jsx)(C.Fragment,{children:t(`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,C.jsx)(C.Fragment,{children:t(`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,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.amsSlotMissing`,`AMS slot {{slot}} not available on this printer`,{slot:(e.slot_index??0)+1})});case`filament_unverified`:return(0,C.jsx)(C.Fragment,{children:t(`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,C.jsx)(C.Fragment,{children:e.kind})}}function O({onFiles:e,onRejected:t,extensions:n,disabled:r=!1}){let[i,a]=(0,S.useState)(!1),o=(0,S.useRef)(e),s=(0,S.useRef)(t),c=(0,S.useRef)(n);(0,S.useEffect)(()=>{o.current=e},[e]),(0,S.useEffect)(()=>{s.current=t},[t]),(0,S.useEffect)(()=>{c.current=n},[n]);let l=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),u=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),d=(0,S.useCallback)(e=>{if(r)return;e.preventDefault();let t=e.currentTarget,n=e.relatedTarget;(!n||!t.contains(n))&&a(!1)},[r]),f=(0,S.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,S.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 k(e){let{archiveName:t,photos:n,initialIndex:i,onClose:a,onDelete:o}=e,[s,c]=(0,S.useState)(()=>Math.min(Math.max(i??0,0),Math.max(n.length-1,0))),[l,u]=(0,S.useState)(!1);if((0,S.useEffect)(()=>{if(l)return;let e=e=>{e.key===`Escape`&&a(),e.key===`ArrowLeft`&&c(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&c(e=>Math.min(n.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a,n.length,l]),(0,S.useEffect)(()=>{s>=n.length&&c(Math.max(0,n.length-1))},[n.length,s]),n.length===0)return a(),null;let d=t=>e.getPhotoUrl?e.getPhotoUrl(t):r.getArchivePhotoUrl(e.archiveId,t),f=n[s],g=d(f);return(0,C.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:e=>{e.stopPropagation(),a()},children:[(0,C.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,C.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,s+1,` of `,n.length]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=g,e.download=`${t}_photo_${s+1}.jpg`,e.click()},children:[(0,C.jsx)(x,{className:`w-4 h-4`}),`Download`]}),o&&(0,C.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>{o&&u(!0)},className:`text-red-400 hover:text-red-300`,children:(0,C.jsx)(h,{className:`w-4 h-4`})}),(0,C.jsx)(`button`,{onClick:a,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,C.jsx)(p,{className:`w-6 h-6`})})]})]}),(0,C.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[s>0&&(0,C.jsx)(`button`,{onClick:()=>c(e=>e-1),className:`absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(y,{className:`w-8 h-8 text-white`})}),(0,C.jsx)(`img`,{src:g,alt:`Photo ${s+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),s<n.length-1&&(0,C.jsx)(`button`,{onClick:()=>c(e=>e+1),className:`absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(_,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,C.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((e,t)=>(0,C.jsx)(`button`,{onClick:()=>c(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,C.jsx)(`img`,{src:d(e),alt:`Thumbnail ${t+1}`,className:`w-full h-full object-cover`})},e))})]}),l&&(0,C.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,C.jsx)(v,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{o?.(f),u(!1)},onCancel:()=>u(!1)})})]})}export{O as n,w as r,k as t};
|