| 1 |
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{C as t,T as n,a as r,k as i,w as a}from"./client-uq_Z1wxL.js";import{n as o}from"./QueryClientProvider-BytsNH5G.js";import{t as s}from"./useQuery-Ri3Hizdr.js";import{t as c}from"./useMutation-Y5Gxe7vE.js";import{t as l}from"./camera-FLMbnnIS.js";import{n as u}from"./ToastContext-C1KWXcWl.js";import{l as d,t as f}from"./PrintModal-BN27coZJ.js";import{t as p}from"./folder-kanban-ZfZZU3Xr.js";import{t as m}from"./link-DNMsFJUo.js";import{t as h}from"./loader-circle-MxPMJ2b-.js";import{t as g}from"./plus-BSMV-kXW.js";import{t as _}from"./rotate-ccw-7xDFE8qP.js";import{t as v}from"./save-D7cxZCVB.js";import{t as ee}from"./tag-CH9wNIj-.js";import{t as y}from"./trash-2-CPDe2bds.js";import{t as b}from"./weight-Ct7d2Ld8.js";import{t as x}from"./x-DvWlm3CR.js";import{n as S}from"./AuthContext-BkJO3em_.js";import{t as C}from"./Button-DYYZvzLo.js";import{v as w}from"./date-G9KUauqz.js";import{t as T}from"./projectTree-C5LrJHZP.js";import{t as E}from"./NumberInput-BaT0XBfV.js";var D=t(`hash`,[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]),O=t(`image-off`,[[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}],[`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`,key:`1bzlo9`}],[`line`,{x1:`13.5`,x2:`6`,y1:`13.5`,y2:`21`,key:`1q0aeu`}],[`line`,{x1:`18`,x2:`21`,y1:`12`,y2:`15`,key:`5mozeu`}],[`path`,{d:`M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59`,key:`mmje98`}],[`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`,key:`43el77`}]]),k=t(`thumbs-down`,[[`path`,{d:`M17 14V2`,key:`8ymqnk`}],[`path`,{d:`M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z`,key:`m61m77`}]]),A=e(i(),1),j=a();function M(e){if(!e||e<=0)return`—`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return t>0?`${t}h ${n}m`:`${n}m`}function N(e){if(!e)return`—`;let t=w(e);return t?t.toLocaleString():`—`}function te({archiveId:e}){let{t}=n(),{data:i,isLoading:a}=s({queryKey:[`archive-runs`,e],queryFn:()=>r.getArchiveRuns(e)});if(a)return(0,j.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,j.jsx)(h,{className:`w-5 h-5 text-bambu-gray animate-spin`})});let o=i?.items||[],c=o.some(e=>e.plate_id!=null&&e.plate_id>1);return o.length===0?(0,j.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:t(`archives.runLog.empty`)}):(0,j.jsx)(`div`,{className:`overflow-x-auto`,children:(0,j.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,j.jsx)(`thead`,{children:(0,j.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,j.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.date`)}),c&&(0,j.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.plate`)}),(0,j.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.status`)}),(0,j.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.duration`)}),(0,j.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.filament`)}),(0,j.jsx)(`th`,{className:`text-right py-1.5 font-medium`,children:t(`archives.runLog.col.cost`)})]})}),(0,j.jsx)(`tbody`,{children:o.map(e=>{let n=e.status===`completed`?`text-bambu-green`:e.status===`failed`?`text-red-700 dark:text-red-400`:`text-bambu-gray`;return(0,j.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/40 last:border-0`,children:[(0,j.jsx)(`td`,{className:`py-1.5 pr-2 text-bambu-gray-light`,children:N(e.started_at||e.created_at)}),c&&(0,j.jsx)(`td`,{className:`py-1.5 pr-2 text-bambu-gray-light`,children:e.plate_id==null?`—`:t(`archives.card.plateNumber`,{index:e.plate_id})}),(0,j.jsxs)(`td`,{className:`py-1.5 pr-2 font-medium ${n}`,children:[t(`archives.runLog.status.${e.status}`,{defaultValue:e.status}),e.failure_reason&&(0,j.jsx)(`span`,{className:`block text-[10px] text-bambu-gray font-normal`,children:t(`editArchive.failureReasons.${e.failure_reason}`,{defaultValue:e.failure_reason})})]}),(0,j.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:M(e.duration_seconds)}),(0,j.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:e.filament_used_grams==null?`—`:`${e.filament_used_grams.toFixed(1)} g`}),(0,j.jsx)(`td`,{className:`py-1.5 text-right text-bambu-gray-light`,children:e.cost==null?`—`:e.cost.toFixed(2)})]},e.id)})})]})})}var P=[[`projects`],[`project`],[`project-archives`],[`project-timeline`],[`project-file-progress`]];function F(e){return Promise.all(P.map(t=>e.invalidateQueries({queryKey:[...t]})))}function ne(e){return Promise.all([e.invalidateQueries({queryKey:[`archives`]}),F(e)])}var I={dialog:`confirmOutcome.sources.dialog`,link:`confirmOutcome.sources.link`,plate_clear:`confirmOutcome.sources.plateClear`,printer_card:`confirmOutcome.sources.printerCard`,api:`confirmOutcome.sources.api`,reaction:`confirmOutcome.sources.reaction`};function L(e){return e?I[e]??null:null}var R=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`noStatusUpdate`,`killSwitch`,`other`],re=[`completed`,`failed`,`aborted`,`cancelled`],ie=1e5;function z({archive:e,onClose:t,existingTags:i=[]}){let{t:a}=n();(0,A.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let u=o(),[d,f]=(0,A.useState)(e.print_name||``),[_,w]=(0,A.useState)(e.printer_id),[O,k]=(0,A.useState)(e.project_id??null),[M,N]=(0,A.useState)(e.notes||``),[P,F]=(0,A.useState)(e.tags||``),[I,z]=(0,A.useState)(()=>{let t=e.failure_reason||``;return t?R.includes(t)?t:R.find(e=>a(`editArchive.failureReasons.${e}`)===t)||t:``}),B=I&&!R.includes(I)?I:null,[V,ae]=(0,A.useState)(e.status),[H,oe]=(0,A.useState)(e.user_verdict??``),U=L(e.user_verdict_source),[W,se]=(0,A.useState)(e.quantity??1),[G,K]=(0,A.useState)(e.filament_used_grams==null?``:String(e.filament_used_grams)),{hasPermission:ce}=S(),q=!ce(`archives:update_all`)&&(e.filament_used_grams!=null||!!e.file_path),[le,J]=(0,A.useState)(e.photos||[]),[ue,de]=(0,A.useState)(e.external_url||``),[fe,pe]=(0,A.useState)(!1),[me,he]=(0,A.useState)(!1),ge=(0,A.useRef)(null),Y=(0,A.useRef)(null),X=(0,A.useRef)(null),{data:_e}=s({queryKey:[`printers`],queryFn:r.getPrinters}),{data:ve}=s({queryKey:[`projects`],queryFn:()=>r.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),ye=(0,A.useMemo)(()=>T(ve??[],e.project_id),[ve,e.project_id]),{data:be}=s({queryKey:[`tags`],queryFn:r.getTags,enabled:i.length===0}),xe=i.length>0?i:be?.map(e=>e.name)||[],Z=P.split(`,`).map(e=>e.trim()).filter(Boolean),Q=P.includes(`,`)?P.substring(P.lastIndexOf(`,`)+1).trim().toLowerCase():P.trim().toLowerCase(),Se=xe.filter(e=>!Z.includes(e)&&(Q===``||e.toLowerCase().includes(Q))),Ce=e=>{let t;if(t=Q&&!xe.includes(Q)?P.includes(`,`)?P.substring(0,P.lastIndexOf(`,`)).split(`,`).map(e=>e.trim()).filter(Boolean):[]:Z,!t.includes(e)){let n=[...t,e].join(`, `);F(n)}X.current!==null&&clearTimeout(X.current),ge.current?.focus()},we=e=>{let t=Z.filter(t=>t!==e).join(`, `);F(t)},$=c({mutationFn:t=>r.updateArchive(e.id,t),onSuccess:()=>{ne(u),u.invalidateQueries({queryKey:[`archive-runs`,e.id]}),t()}}),Te=async t=>{let n=t.target.files?.[0];if(n){pe(!0);try{let t=await r.uploadArchivePhoto(e.id,n);J(t.photos),u.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to upload photo:`,e)}finally{pe(!1),Y.current&&(Y.current.value=``)}}},Ee=async t=>{try{let n=await r.deleteArchivePhoto(e.id,t);J(n.photos||[]),u.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to delete photo:`,e)}};return(0,j.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,j.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,j.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(`editArchive.title`)}),(0,j.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,j.jsx)(x,{className:`w-5 h-5`})})]}),(0,j.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n={print_name:d||void 0,printer_id:_,project_id:O,notes:M||void 0,tags:P||void 0,quantity:W,external_url:ue||null};V!==e.status&&(n.status=V),H!==(e.user_verdict??``)&&(n.user_verdict=H===``?null:H,n.user_verdict_source=`dialog`);let r=G.trim(),i=r===``?null:Number(r),a=i!==null&&!Number.isFinite(i),o=i===null?null:Math.min(Math.max(i,0),ie),s=e.filament_used_grams??null;!a&&o!==s&&(n.filament_used_grams=o),V===`failed`||V===`aborted`||V===`completed`&&H===`reject`?n.failure_reason=I||void 0:V===`completed`&&e.failure_reason&&(n.failure_reason=null),$.mutate(n)},className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`archives.runLog.title`)}),(0,j.jsx)(te,{archiveId:e.id})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.name`)}),(0,j.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:a(`editArchive.namePlaceholder`)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.printer`)}),(0,j.jsxs)(`select`,{value:_??``,onChange:e=>w(e.target.value?Number(e.target.value):null),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:``,children:a(`editArchive.noPrinter`)}),_e?.map(e=>(0,j.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,j.jsx)(p,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.project`)]}),(0,j.jsxs)(`select`,{value:O??``,onChange:e=>k(e.target.value?Number(e.target.value):null),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:``,children:a(`editArchive.noProject`)}),ye.map(e=>(0,j.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`archive-items-printed`,children:[(0,j.jsx)(D,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.itemsPrinted`)]}),(0,j.jsx)(E,{id:`archive-items-printed`,min:0,value:W,onChange:se,fallback:0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:`1`}),(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`editArchive.itemsPrintedHelp`)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`archive-filament-grams`,children:[(0,j.jsx)(b,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.filamentUsed`)]}),(0,j.jsx)(`input`,{id:`archive-filament-grams`,type:`text`,inputMode:`decimal`,value:G,onChange:e=>{let t=e.target.value.replace(`,`,`.`);(t===``||/^\d*\.?\d*$/.test(t))&&K(t)},onBlur:()=>K(e=>{let t=Number(e);return e===``||!Number.isFinite(t)?``:String(Math.min(t,ie))}),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 disabled:opacity-50 disabled:cursor-not-allowed`,placeholder:a(`editArchive.filamentUsedPlaceholder`),disabled:q}),(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(q?`editArchive.filamentUsedLocked`:`editArchive.filamentUsedHelp`)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.notes`)}),(0,j.jsx)(`textarea`,{value:M,onChange:e=>N(e.target.value),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none`,placeholder:a(`editArchive.notesPlaceholder`)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,j.jsx)(m,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.externalLink`)]}),(0,j.jsx)(`input`,{type:`url`,value:ue,onChange:e=>de(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:`https://printables.com/model/...`}),(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`editArchive.externalLinkHelp`)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.tags`)}),Z.length>0&&(0,j.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:Z.map(e=>(0,j.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 bg-bambu-dark-tertiary rounded text-sm text-white`,children:[(0,j.jsx)(ee,{className:`w-3 h-3`}),e,(0,j.jsx)(`button`,{type:`button`,onClick:()=>we(e),className:`ml-0.5 text-bambu-gray hover:text-white`,children:(0,j.jsx)(x,{className:`w-3 h-3`})})]},e))}),(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(`input`,{ref:ge,type:`text`,value:P,onChange:e=>F(e.target.value),onFocus:()=>{X.current!==null&&clearTimeout(X.current),he(!0)},onBlur:()=>{X.current=window.setTimeout(()=>he(!1),200)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:Z.length>0?a(`editArchive.addMoreTags`):a(`editArchive.tagsPlaceholder`)}),me&&Se.length>0&&(0,j.jsxs)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-10 max-h-40 overflow-y-auto`,children:[(0,j.jsxs)(`div`,{className:`p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[Q?a(`editArchive.matchingTags`,{query:Q}):a(`editArchive.existingTags`),` `,a(`editArchive.clickToAdd`)]}),(0,j.jsx)(`div`,{className:`p-2 flex flex-wrap gap-1.5`,children:Se.map(e=>(0,j.jsx)(`button`,{type:`button`,onClick:()=>Ce(e),className:`px-2 py-0.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded text-sm text-bambu-gray hover:text-white transition-colors`,children:e},e))})]})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.status`)}),(0,j.jsxs)(`select`,{value:V,onChange:e=>{ae(e.target.value),e.target.value===`completed`&&z(``)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[e.status&&!re.includes(e.status)&&(0,j.jsx)(`option`,{value:e.status,disabled:!0,children:a(`editArchive.statuses.${e.status}`,{defaultValue:e.status})}),re.map(e=>(0,j.jsx)(`option`,{value:e,children:a(`editArchive.statuses.${e}`)},e))]}),(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`editArchive.statusHelp`)})]}),V===`completed`&&(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`user-verdict-select`,className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.userVerdict`)}),(0,j.jsxs)(`select`,{id:`user-verdict-select`,value:H,onChange:e=>oe(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,j.jsx)(`option`,{value:``,children:a(`editArchive.verdicts.none`)}),(0,j.jsx)(`option`,{value:`good`,children:a(`editArchive.verdicts.good`)}),(0,j.jsx)(`option`,{value:`reject`,children:a(`editArchive.verdicts.reject`)})]}),U&&H===(e.user_verdict??``)&&(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,"data-testid":`verdict-source-hint`,children:a(U)})]}),(V===`failed`||V===`aborted`||V===`completed`&&H===`reject`)&&(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`failure-reason-select`,className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.failureReason`)}),(0,j.jsxs)(`select`,{id:`failure-reason-select`,value:I,onChange:e=>z(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,j.jsx)(`option`,{value:``,children:a(`editArchive.selectReason`)}),R.map(e=>(0,j.jsx)(`option`,{value:e,children:a(`editArchive.failureReasons.${e}`)},e)),B&&(0,j.jsx)(`option`,{value:B,children:B})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,j.jsx)(l,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.photos`)]}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-2`,children:[le.map(t=>(0,j.jsxs)(`div`,{className:`relative group`,children:[(0,j.jsx)(`img`,{src:r.getArchivePhotoUrl(e.id,t),alt:a(`editArchive.printResult`),className:`w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary`}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>Ee(t),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,children:(0,j.jsx)(y,{className:`w-3 h-3 text-white`})})]},t)),(0,j.jsxs)(`label`,{className:`w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors`,children:[(0,j.jsx)(`input`,{ref:Y,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:Te,className:`hidden`,disabled:fe}),fe?(0,j.jsx)(h,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,j.jsx)(g,{className:`w-6 h-6 text-bambu-gray`})]})]}),(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:a(`editArchive.photosHelp`)})]}),(0,j.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,j.jsx)(C,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:a(`common.cancel`)}),(0,j.jsxs)(C,{type:`submit`,disabled:$.isPending,className:`flex-1`,children:[(0,j.jsx)(v,{className:`w-4 h-4`}),$.isPending?a(`common.saving`):a(`common.save`)]})]})]})]})})}function B({archiveId:e,runId:t,onClose:i}){let{t:a}=n(),{showToast:l}=u(),p=o(),[m,h]=(0,A.useState)(!1),[g,v]=(0,A.useState)(``),[ee,y]=(0,A.useState)(!1),{data:b}=s({queryKey:[`archive`,e,t??null],queryFn:()=>r.getArchive(e,t)}),S=c({mutationFn:n=>r.updateArchive(e,{...n,user_verdict_source:`dialog`,...t==null?{}:{run_id:t}}),onSuccess:(t,n)=>{p.invalidateQueries({queryKey:[`archives`]}),p.invalidateQueries({queryKey:[`archive`,e]}),l(n.user_verdict===`good`?a(`confirmOutcome.savedGood`):a(`confirmOutcome.savedReject`),`success`),n.user_verdict===`good`&&i()},onError:()=>l(a(`confirmOutcome.saveFailed`),`error`)}),C=b?.print_name||b?.filename||``,w=b?.photos?.[0]??null,T=w?r.getArchivePhotoUrl(e,w):null,E=b?.user_verdict!=null,D=L(b?.user_verdict_source),M=()=>S.mutate({user_verdict:`good`}),N=e=>{S.mutate({user_verdict:`reject`,...g?{failure_reason:g}:{}},{onSuccess:()=>{e?y(!0):i()}})};return ee&&b?(0,j.jsx)(f,{mode:`create`,archiveId:e,archiveName:C,preselectPlateId:b.plate_id,onClose:i}):(0,j.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,"data-testid":`confirm-outcome-dialog`,children:(0,j.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md overflow-hidden`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,j.jsx)(`h3`,{className:`text-white font-semibold`,children:a(`confirmOutcome.title`)}),(0,j.jsx)(`button`,{onClick:i,className:`text-bambu-gray hover:text-white transition-colors`,title:a(`common.close`),children:(0,j.jsx)(x,{className:`w-5 h-5`})})]}),(0,j.jsx)(`div`,{className:`bg-bambu-dark aspect-video flex items-center justify-center overflow-hidden`,children:T?(0,j.jsx)(`img`,{src:T,alt:C,className:`w-full h-full object-contain`}):(0,j.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-bambu-gray/60`,children:[(0,j.jsx)(O,{className:`w-10 h-10`}),(0,j.jsx)(`span`,{className:`text-xs`,children:a(`confirmOutcome.noPhoto`)})]})}),(0,j.jsxs)(`div`,{className:`p-4`,children:[(0,j.jsx)(`p`,{className:`text-sm text-white text-center mb-1 truncate`,title:C,children:C}),E?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`p`,{className:`text-sm text-bambu-gray text-center`,children:b?.user_verdict===`good`?a(`confirmOutcome.alreadyGood`):a(`confirmOutcome.alreadyRejected`)}),D&&(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray/70 text-center mt-1`,"data-testid":`verdict-source-hint`,children:a(D)})]}):m?(0,j.jsxs)(`div`,{className:`mt-3`,children:[(0,j.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:a(`confirmOutcome.rejectReason`)}),(0,j.jsxs)(`select`,{value:g,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:[(0,j.jsx)(`option`,{value:``,children:a(`confirmOutcome.noReason`)}),R.map(e=>(0,j.jsx)(`option`,{value:e,children:a(`editArchive.failureReasons.${e}`)},e))]}),(0,j.jsxs)(`div`,{className:`flex gap-2 mt-3`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>N(!1),disabled:S.isPending,className:`flex-1 px-3 py-2 rounded-lg bg-red-500/80 hover:bg-red-500 text-white text-sm transition-colors`,children:a(`confirmOutcome.saveReject`)}),(0,j.jsxs)(`button`,{type:`button`,onClick:()=>N(!0),disabled:S.isPending,className:`flex-1 px-3 py-2 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green/60 text-white text-sm transition-colors flex items-center justify-center gap-1.5`,children:[(0,j.jsx)(_,{className:`w-4 h-4`}),a(`confirmOutcome.rejectAndReprint`)]})]}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>h(!1),className:`w-full mt-2 text-xs text-bambu-gray hover:text-white transition-colors`,children:a(`common.back`)})]}):(0,j.jsxs)(`div`,{className:`flex items-center justify-center gap-6 mt-3`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>h(!0),disabled:S.isPending,className:`flex flex-col items-center gap-1.5 px-6 py-3 rounded-xl border border-red-500/40 text-red-500 hover:bg-red-500/10 transition-colors`,children:[(0,j.jsx)(k,{className:`w-7 h-7`}),(0,j.jsx)(`span`,{className:`text-xs`,children:a(`confirmOutcome.reject`)})]}),(0,j.jsxs)(`button`,{type:`button`,onClick:M,disabled:S.isPending,className:`flex flex-col items-center gap-1.5 px-6 py-3 rounded-xl border border-bambu-green/50 text-bambu-green hover:bg-bambu-green/10 transition-colors`,children:[(0,j.jsx)(d,{className:`w-7 h-7`}),(0,j.jsx)(`span`,{className:`text-xs`,children:a(`confirmOutcome.good`)})]})]}),!E&&!m&&(0,j.jsx)(`button`,{type:`button`,onClick:i,className:`w-full mt-4 text-xs text-bambu-gray hover:text-white transition-colors`,children:a(`confirmOutcome.later`)})]})]})})}export{ne as a,O as c,L as i,z as n,te as o,R as r,k as s,B as t};
|