| 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-DWQBE01c.js";import{n as o}from"./QueryClientProvider-CfzZA5MJ.js";import{t as s}from"./useQuery-Q4exvDrv.js";import{t as c}from"./useMutation-D7HomC3_.js";import{t as l}from"./camera-DCHvxNOs.js";import{n as u}from"./ToastContext-Bg6SLDR7.js";import{l as d,t as ee}from"./PrintModal-CdmO-e6y.js";import{t as f}from"./folder-kanban-D_DeGkF6.js";import{t as p}from"./link-Br4FFeYU.js";import{t as m}from"./loader-circle-QIogdiwG.js";import{t as te}from"./plus-D5MKJLpO.js";import{t as h}from"./rotate-ccw-iglXlH3a.js";import{t as ne}from"./save-fARYWQM6.js";import{t as g}from"./tag-Cug-rfRv.js";import{t as _}from"./trash-2-BeUbCuhB.js";import{t as v}from"./weight-Mr1U_eRW.js";import{t as y}from"./x-Ros7hs1-.js";import{n as b}from"./AuthContext-dqmb9nDE.js";import{t as x}from"./Button-CDViejCk.js";import{v as S}from"./date-G9KUauqz.js";import{t as C}from"./projectTree-C5LrJHZP.js";import{t as w}from"./NumberInput-Cf4OPY5C.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 ie(e){if(!e)return`—`;let t=S(e);return t?t.toLocaleString():`—`}function A({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||[];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`)}),(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:ie(e.started_at||e.created_at)}),(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 j=[[`projects`],[`project`],[`project-archives`],[`project-timeline`],[`project-file-progress`]];function M(e){return Promise.all(j.map(t=>e.invalidateQueries({queryKey:[...t]})))}function N(e){return Promise.all([e.invalidateQueries({queryKey:[`archives`]}),M(e)])}var P={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 F(e){return e?P[e]??null:null}var I=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`noStatusUpdate`,`killSwitch`,`other`],ae=[`completed`,`failed`,`aborted`,`cancelled`],oe=1e5;function L({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||``),[h,S]=(0,D.useState)(e.printer_id),[T,E]=(0,D.useState)(e.project_id??null),[k,ie]=(0,D.useState)(e.notes||``),[j,M]=(0,D.useState)(e.tags||``),[P,L]=(0,D.useState)(()=>{let t=e.failure_reason||``;return t?I.includes(t)?t:I.find(e=>a(`editArchive.failureReasons.${e}`)===t)||t:``}),R=P&&!I.includes(P)?P:null,[z,se]=(0,D.useState)(e.status),[B,ce]=(0,D.useState)(e.user_verdict??``),V=F(e.user_verdict_source),[H,le]=(0,D.useState)(e.quantity??1),[U,W]=(0,D.useState)(e.filament_used_grams==null?``:String(e.filament_used_grams)),{hasPermission:ue}=b(),G=!ue(`archives:update_all`)&&(e.filament_used_grams!=null||!!e.file_path),[de,K]=(0,D.useState)(e.photos||[]),[q,fe]=(0,D.useState)(e.external_url||``),[pe,me]=(0,D.useState)(!1),[he,ge]=(0,D.useState)(!1),_e=(0,D.useRef)(null),J=(0,D.useRef)(null),Y=(0,D.useRef)(null),{data:ve}=s({queryKey:[`printers`],queryFn:r.getPrinters}),{data:ye}=s({queryKey:[`projects`],queryFn:()=>r.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),be=(0,D.useMemo)(()=>C(ye??[],e.project_id),[ye,e.project_id]),{data:xe}=s({queryKey:[`tags`],queryFn:r.getTags,enabled:i.length===0}),X=i.length>0?i:xe?.map(e=>e.name)||[],Z=j.split(`,`).map(e=>e.trim()).filter(Boolean),Q=j.includes(`,`)?j.substring(j.lastIndexOf(`,`)+1).trim().toLowerCase():j.trim().toLowerCase(),Se=X.filter(e=>!Z.includes(e)&&(Q===``||e.toLowerCase().includes(Q))),Ce=e=>{let t;if(t=Q&&!X.includes(Q)?j.includes(`,`)?j.substring(0,j.lastIndexOf(`,`)).split(`,`).map(e=>e.trim()).filter(Boolean):[]:Z,!t.includes(e)){let n=[...t,e].join(`, `);M(n)}Y.current!==null&&clearTimeout(Y.current),_e.current?.focus()},we=e=>{let t=Z.filter(t=>t!==e).join(`, `);M(t)},$=c({mutationFn:t=>r.updateArchive(e.id,t),onSuccess:()=>{N(u),u.invalidateQueries({queryKey:[`archive-runs`,e.id]}),t()}}),Te=async t=>{let n=t.target.files?.[0];if(n){me(!0);try{let t=await r.uploadArchivePhoto(e.id,n);K(t.photos),u.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to upload photo:`,e)}finally{me(!1),J.current&&(J.current.value=``)}}},Ee=async t=>{try{let n=await r.deleteArchivePhoto(e.id,t);K(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:h,project_id:T,notes:k||void 0,tags:j||void 0,quantity:H,external_url:q||null};z!==e.status&&(n.status=z),B!==(e.user_verdict??``)&&(n.user_verdict=B===``?null:B,n.user_verdict_source=`dialog`);let r=U.trim(),i=r===``?null:Number(r),a=i!==null&&!Number.isFinite(i),o=i===null?null:Math.min(Math.max(i,0),oe),s=e.filament_used_grams??null;!a&&o!==s&&(n.filament_used_grams=o),z===`failed`||z===`aborted`||z===`completed`&&B===`reject`?n.failure_reason=P||void 0:z===`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)(A,{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:h??``,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`)}),ve?.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`)}),be.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:H,onChange:le,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:U,onChange:e=>{let t=e.target.value.replace(`,`,`.`);(t===``||/^\d*\.?\d*$/.test(t))&&W(t)},onBlur:()=>W(e=>{let t=Number(e);return e===``||!Number.isFinite(t)?``:String(Math.min(t,oe))}),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:G}),(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(G?`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=>ie(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:q,onChange:e=>fe(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)(g,{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:_e,type:`text`,value:j,onChange:e=>M(e.target.value),onFocus:()=>{Y.current!==null&&clearTimeout(Y.current),ge(!0)},onBlur:()=>{Y.current=window.setTimeout(()=>ge(!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`)}),he&&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:z,onChange:e=>{se(e.target.value),e.target.value===`completed`&&L(``)},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&&!ae.includes(e.status)&&(0,O.jsx)(`option`,{value:e.status,disabled:!0,children:a(`editArchive.statuses.${e.status}`,{defaultValue:e.status})}),ae.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`)})]}),z===`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:B,onChange:e=>ce(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`)})]}),V&&B===(e.user_verdict??``)&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,"data-testid":`verdict-source-hint`,children:a(V)})]}),(z===`failed`||z===`aborted`||z===`completed`&&B===`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:P,onChange:e=>L(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`)}),I.map(e=>(0,O.jsx)(`option`,{value:e,children:a(`editArchive.failureReasons.${e}`)},e)),R&&(0,O.jsx)(`option`,{value:R,children:R})]})]}),(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:[de.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:J,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:Te,className:`hidden`,disabled:pe}),pe?(0,O.jsx)(m,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,O.jsx)(te,{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)(ne,{className:`w-4 h-4`}),$.isPending?a(`common.saving`):a(`common.save`)]})]})]})]})})}function R({archiveId:e,onClose:t}){let{t:i}=n(),{showToast:a}=u(),l=o(),[f,p]=(0,D.useState)(!1),[m,te]=(0,D.useState)(``),[ne,g]=(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=F(_?.user_verdict_source),re=()=>v.mutate({user_verdict:`good`}),k=e=>{v.mutate({user_verdict:`reject`,...m?{failure_reason:m}:{}},{onSuccess:()=>{e?g(!0):t()}})};return ne&&_?(0,O.jsx)(ee,{mode:`create`,archiveId:e,archiveName:b,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=>te(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`)}),I.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)(h,{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{N as a,T as c,F as i,L as n,A as o,I as r,E as s,R as t};
|