ConfirmOutcomeDialog-DQcbXiuf.js 23 KB

1
  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-8XqSBxc-.js";import{n as o}from"./QueryClientProvider-Cx3hLxdK.js";import{t as s}from"./useQuery-DPwkC1fo.js";import{t as c}from"./useMutation-u7tZvPp7.js";import{t as l}from"./camera-BBw757Uc.js";import{n as u}from"./ToastContext-DS50Mad5.js";import{l as d,t as ee}from"./PrintModal-DLimPejf.js";import{t as f}from"./folder-kanban-BF95vW-2.js";import{t as p}from"./link-S-tWE_Cc.js";import{t as m}from"./loader-circle-CvUpGhXe.js";import{t as h}from"./plus-DKk2x0gz.js";import{t as g}from"./rotate-ccw-CurA1akI.js";import{t as te}from"./save-8T9QLcG8.js";import{t as ne}from"./tag-CbKCthhD.js";import{t as _}from"./trash-2-Cp6fGnE3.js";import{t as v}from"./weight-CLMgycu4.js";import{t as y}from"./x-Cx7zNncH.js";import{n as b}from"./AuthContext-CmTN4q4U.js";import{t as x}from"./Button-DZq9YkGs.js";import{v as S}from"./date-G9KUauqz.js";import{t as C}from"./projectTree-C5LrJHZP.js";import{t as w}from"./NumberInput-mKi1v1k8.js";var re=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`}]]),T=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`}]]),E=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`}]]),D=e(i(),1),O=a();function k(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 A(e){if(!e)return`—`;let t=S(e);return t?t.toLocaleString():`—`}function j({archiveId:e}){let{t}=n(),{data:i,isLoading:a}=s({queryKey:[`archive-runs`,e],queryFn:()=>r.getArchiveRuns(e)});if(a)return(0,O.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,O.jsx)(m,{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,O.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:t(`archives.runLog.empty`)}):(0,O.jsx)(`div`,{className:`overflow-x-auto`,children:(0,O.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,O.jsx)(`thead`,{children:(0,O.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,O.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.date`)}),c&&(0,O.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.plate`)}),(0,O.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.status`)}),(0,O.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.duration`)}),(0,O.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.filament`)}),(0,O.jsx)(`th`,{className:`text-right py-1.5 font-medium`,children:t(`archives.runLog.col.cost`)})]})}),(0,O.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,O.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/40 last:border-0`,children:[(0,O.jsx)(`td`,{className:`py-1.5 pr-2 text-bambu-gray-light`,children:A(e.started_at||e.created_at)}),c&&(0,O.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,O.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,O.jsx)(`span`,{className:`block text-[10px] text-bambu-gray font-normal`,children:t(`editArchive.failureReasons.${e.failure_reason}`,{defaultValue:e.failure_reason})})]}),(0,O.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:k(e.duration_seconds)}),(0,O.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,O.jsx)(`td`,{className:`py-1.5 text-right text-bambu-gray-light`,children:e.cost==null?`—`:e.cost.toFixed(2)})]},e.id)})})]})})}var M=[[`projects`],[`project`],[`project-archives`],[`project-timeline`],[`project-file-progress`]];function N(e){return Promise.all(M.map(t=>e.invalidateQueries({queryKey:[...t]})))}function P(e){return Promise.all([e.invalidateQueries({queryKey:[`archives`]}),N(e)])}var F={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 I(e){return e?F[e]??null:null}var L=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`noStatusUpdate`,`killSwitch`,`other`],ie=[`completed`,`failed`,`aborted`,`cancelled`],ae=1e5;function R({archive:e,onClose:t,existingTags:i=[]}){let{t:a}=n();(0,D.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let u=o(),[d,ee]=(0,D.useState)(e.print_name||``),[g,S]=(0,D.useState)(e.printer_id),[T,E]=(0,D.useState)(e.project_id??null),[k,A]=(0,D.useState)(e.notes||``),[M,N]=(0,D.useState)(e.tags||``),[F,R]=(0,D.useState)(()=>{let t=e.failure_reason||``;return t?L.includes(t)?t:L.find(e=>a(`editArchive.failureReasons.${e}`)===t)||t:``}),z=F&&!L.includes(F)?F:null,[B,oe]=(0,D.useState)(e.status),[V,se]=(0,D.useState)(e.user_verdict??``),H=I(e.user_verdict_source),[U,ce]=(0,D.useState)(e.quantity??1),[W,G]=(0,D.useState)(e.filament_used_grams==null?``:String(e.filament_used_grams)),{hasPermission:le}=b(),K=!le(`archives:update_all`)&&(e.filament_used_grams!=null||!!e.file_path),[ue,q]=(0,D.useState)(e.photos||[]),[J,de]=(0,D.useState)(e.external_url||``),[fe,pe]=(0,D.useState)(!1),[me,he]=(0,D.useState)(!1),ge=(0,D.useRef)(null),Y=(0,D.useRef)(null),X=(0,D.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,D.useMemo)(()=>C(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=M.split(`,`).map(e=>e.trim()).filter(Boolean),Q=M.includes(`,`)?M.substring(M.lastIndexOf(`,`)+1).trim().toLowerCase():M.trim().toLowerCase(),Se=xe.filter(e=>!Z.includes(e)&&(Q===``||e.toLowerCase().includes(Q))),Ce=e=>{let t;if(t=Q&&!xe.includes(Q)?M.includes(`,`)?M.substring(0,M.lastIndexOf(`,`)).split(`,`).map(e=>e.trim()).filter(Boolean):[]:Z,!t.includes(e)){let n=[...t,e].join(`, `);N(n)}X.current!==null&&clearTimeout(X.current),ge.current?.focus()},we=e=>{let t=Z.filter(t=>t!==e).join(`, `);N(t)},$=c({mutationFn:t=>r.updateArchive(e.id,t),onSuccess:()=>{P(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);q(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);q(n.photos||[]),u.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to delete photo:`,e)}};return(0,O.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,O.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,O.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,O.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(`editArchive.title`)}),(0,O.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,O.jsx)(y,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n={print_name:d||void 0,printer_id:g,project_id:T,notes:k||void 0,tags:M||void 0,quantity:U,external_url:J||null};B!==e.status&&(n.status=B),V!==(e.user_verdict??``)&&(n.user_verdict=V===``?null:V,n.user_verdict_source=`dialog`);let r=W.trim(),i=r===``?null:Number(r),a=i!==null&&!Number.isFinite(i),o=i===null?null:Math.min(Math.max(i,0),ae),s=e.filament_used_grams??null;!a&&o!==s&&(n.filament_used_grams=o),B===`failed`||B===`aborted`||B===`completed`&&V===`reject`?n.failure_reason=F||void 0:B===`completed`&&e.failure_reason&&(n.failure_reason=null),$.mutate(n)},className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`archives.runLog.title`)}),(0,O.jsx)(j,{archiveId:e.id})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.name`)}),(0,O.jsx)(`input`,{type:`text`,value:d,onChange:e=>ee(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,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.printer`)}),(0,O.jsxs)(`select`,{value:g??``,onChange:e=>S(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,O.jsx)(`option`,{value:``,children:a(`editArchive.noPrinter`)}),_e?.map(e=>(0,O.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,O.jsx)(f,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.project`)]}),(0,O.jsxs)(`select`,{value:T??``,onChange:e=>E(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,O.jsx)(`option`,{value:``,children:a(`editArchive.noProject`)}),ye.map(e=>(0,O.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`archive-items-printed`,children:[(0,O.jsx)(re,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.itemsPrinted`)]}),(0,O.jsx)(w,{id:`archive-items-printed`,min:0,value:U,onChange:ce,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,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`editArchive.itemsPrintedHelp`)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`archive-filament-grams`,children:[(0,O.jsx)(v,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.filamentUsed`)]}),(0,O.jsx)(`input`,{id:`archive-filament-grams`,type:`text`,inputMode:`decimal`,value:W,onChange:e=>{let t=e.target.value.replace(`,`,`.`);(t===``||/^\d*\.?\d*$/.test(t))&&G(t)},onBlur:()=>G(e=>{let t=Number(e);return e===``||!Number.isFinite(t)?``:String(Math.min(t,ae))}),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:K}),(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(K?`editArchive.filamentUsedLocked`:`editArchive.filamentUsedHelp`)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.notes`)}),(0,O.jsx)(`textarea`,{value:k,onChange:e=>A(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,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,O.jsx)(p,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.externalLink`)]}),(0,O.jsx)(`input`,{type:`url`,value:J,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,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`editArchive.externalLinkHelp`)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.tags`)}),Z.length>0&&(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:Z.map(e=>(0,O.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,O.jsx)(ne,{className:`w-3 h-3`}),e,(0,O.jsx)(`button`,{type:`button`,onClick:()=>we(e),className:`ml-0.5 text-bambu-gray hover:text-white`,children:(0,O.jsx)(y,{className:`w-3 h-3`})})]},e))}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(`input`,{ref:ge,type:`text`,value:M,onChange:e=>N(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,O.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,O.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,O.jsx)(`div`,{className:`p-2 flex flex-wrap gap-1.5`,children:Se.map(e=>(0,O.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,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.status`)}),(0,O.jsxs)(`select`,{value:B,onChange:e=>{oe(e.target.value),e.target.value===`completed`&&R(``)},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&&!ie.includes(e.status)&&(0,O.jsx)(`option`,{value:e.status,disabled:!0,children:a(`editArchive.statuses.${e.status}`,{defaultValue:e.status})}),ie.map(e=>(0,O.jsx)(`option`,{value:e,children:a(`editArchive.statuses.${e}`)},e))]}),(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`editArchive.statusHelp`)})]}),B===`completed`&&(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`user-verdict-select`,className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.userVerdict`)}),(0,O.jsxs)(`select`,{id:`user-verdict-select`,value:V,onChange:e=>se(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,O.jsx)(`option`,{value:``,children:a(`editArchive.verdicts.none`)}),(0,O.jsx)(`option`,{value:`good`,children:a(`editArchive.verdicts.good`)}),(0,O.jsx)(`option`,{value:`reject`,children:a(`editArchive.verdicts.reject`)})]}),H&&V===(e.user_verdict??``)&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,"data-testid":`verdict-source-hint`,children:a(H)})]}),(B===`failed`||B===`aborted`||B===`completed`&&V===`reject`)&&(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`failure-reason-select`,className:`block text-sm text-bambu-gray mb-1`,children:a(`editArchive.failureReason`)}),(0,O.jsxs)(`select`,{id:`failure-reason-select`,value:F,onChange:e=>R(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,O.jsx)(`option`,{value:``,children:a(`editArchive.selectReason`)}),L.map(e=>(0,O.jsx)(`option`,{value:e,children:a(`editArchive.failureReasons.${e}`)},e)),z&&(0,O.jsx)(`option`,{value:z,children:z})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,O.jsx)(l,{className:`w-4 h-4 inline mr-1`}),a(`editArchive.photos`)]}),(0,O.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-2`,children:[ue.map(t=>(0,O.jsxs)(`div`,{className:`relative group`,children:[(0,O.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,O.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,O.jsx)(_,{className:`w-3 h-3 text-white`})})]},t)),(0,O.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,O.jsx)(`input`,{ref:Y,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:Te,className:`hidden`,disabled:fe}),fe?(0,O.jsx)(m,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,O.jsx)(h,{className:`w-6 h-6 text-bambu-gray`})]})]}),(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:a(`editArchive.photosHelp`)})]}),(0,O.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,O.jsx)(x,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:a(`common.cancel`)}),(0,O.jsxs)(x,{type:`submit`,disabled:$.isPending,className:`flex-1`,children:[(0,O.jsx)(te,{className:`w-4 h-4`}),$.isPending?a(`common.saving`):a(`common.save`)]})]})]})]})})}function z({archiveId:e,onClose:t}){let{t:i}=n(),{showToast:a}=u(),l=o(),[f,p]=(0,D.useState)(!1),[m,h]=(0,D.useState)(``),[te,ne]=(0,D.useState)(!1),{data:_}=s({queryKey:[`archive`,e],queryFn:()=>r.getArchive(e)}),v=c({mutationFn:t=>r.updateArchive(e,{...t,user_verdict_source:`dialog`}),onSuccess:(n,r)=>{l.invalidateQueries({queryKey:[`archives`]}),l.invalidateQueries({queryKey:[`archive`,e]}),a(r.user_verdict===`good`?i(`confirmOutcome.savedGood`):i(`confirmOutcome.savedReject`),`success`),r.user_verdict===`good`&&t()},onError:()=>a(i(`confirmOutcome.saveFailed`),`error`)}),b=_?.print_name||_?.filename||``,x=_?.photos?.[0]??null,S=x?r.getArchivePhotoUrl(e,x):null,C=_?.user_verdict!=null,w=I(_?.user_verdict_source),re=()=>v.mutate({user_verdict:`good`}),k=e=>{v.mutate({user_verdict:`reject`,...m?{failure_reason:m}:{}},{onSuccess:()=>{e?ne(!0):t()}})};return te&&_?(0,O.jsx)(ee,{mode:`create`,archiveId:e,archiveName:b,preselectPlateId:_.plate_id,onClose:t}):(0,O.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,O.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md overflow-hidden`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,O.jsx)(`h3`,{className:`text-white font-semibold`,children:i(`confirmOutcome.title`)}),(0,O.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,title:i(`common.close`),children:(0,O.jsx)(y,{className:`w-5 h-5`})})]}),(0,O.jsx)(`div`,{className:`bg-bambu-dark aspect-video flex items-center justify-center overflow-hidden`,children:S?(0,O.jsx)(`img`,{src:S,alt:b,className:`w-full h-full object-contain`}):(0,O.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-bambu-gray/60`,children:[(0,O.jsx)(T,{className:`w-10 h-10`}),(0,O.jsx)(`span`,{className:`text-xs`,children:i(`confirmOutcome.noPhoto`)})]})}),(0,O.jsxs)(`div`,{className:`p-4`,children:[(0,O.jsx)(`p`,{className:`text-sm text-white text-center mb-1 truncate`,title:b,children:b}),C?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray text-center`,children:_?.user_verdict===`good`?i(`confirmOutcome.alreadyGood`):i(`confirmOutcome.alreadyRejected`)}),w&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray/70 text-center mt-1`,"data-testid":`verdict-source-hint`,children:i(w)})]}):f?(0,O.jsxs)(`div`,{className:`mt-3`,children:[(0,O.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`confirmOutcome.rejectReason`)}),(0,O.jsxs)(`select`,{value:m,onChange:e=>h(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,O.jsx)(`option`,{value:``,children:i(`confirmOutcome.noReason`)}),L.map(e=>(0,O.jsx)(`option`,{value:e,children:i(`editArchive.failureReasons.${e}`)},e))]}),(0,O.jsxs)(`div`,{className:`flex gap-2 mt-3`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:()=>k(!1),disabled:v.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:i(`confirmOutcome.saveReject`)}),(0,O.jsxs)(`button`,{type:`button`,onClick:()=>k(!0),disabled:v.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,O.jsx)(g,{className:`w-4 h-4`}),i(`confirmOutcome.rejectAndReprint`)]})]}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>p(!1),className:`w-full mt-2 text-xs text-bambu-gray hover:text-white transition-colors`,children:i(`common.back`)})]}):(0,O.jsxs)(`div`,{className:`flex items-center justify-center gap-6 mt-3`,children:[(0,O.jsxs)(`button`,{type:`button`,onClick:()=>p(!0),disabled:v.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,O.jsx)(E,{className:`w-7 h-7`}),(0,O.jsx)(`span`,{className:`text-xs`,children:i(`confirmOutcome.reject`)})]}),(0,O.jsxs)(`button`,{type:`button`,onClick:re,disabled:v.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,O.jsx)(d,{className:`w-7 h-7`}),(0,O.jsx)(`span`,{className:`text-xs`,children:i(`confirmOutcome.good`)})]})]}),!C&&!f&&(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`w-full mt-4 text-xs text-bambu-gray hover:text-white transition-colors`,children:i(`confirmOutcome.later`)})]})]})})}export{P as a,T as c,I as i,R as n,j as o,L as r,E as s,z as t};