1!function(){try{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{}).SENTRY_RELEASE={id:"snapfy-frontend@1790655446049"}}catch(e){}}();try{e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},(t=(new e.Error).stack)&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="1534f8ee-534a-4771-b25d-d425bdfff553",e._sentryDebugIdIdentifier="sentry-dbid-1534f8ee-534a-4771-b25d-d425bdfff553")}catch(e){}var e,t;import{a7 as s,p as a,j as n,a3 as r,B as i,J as l,a8 as o,M as d,T as c,f as p,C as x,a5 as u}from"./index.DuJZvJ7M.js";import{b as m,u as f,h as y}from"./vendor.B7-ms4FH.js";import{u as h}from"./useOrderStore.DUKIgnpA.js";import{C as g,D as v,O as b}from"./OrderTracking.D45_REB4.js";import{A as j}from"./arrow-left.BU7OIFmW.js"; 2/** 3 * @license lucide-react v0.555.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const w=s("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"}]]),N=s("layout-grid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]),k=s("map-pin",[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]]),C=s("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]),S=s("rotate-ccw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]),P=s("send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]),I={scale:1,tx:0,ty:0};function M(){const[e,t]=m.useState(I),[s,a]=m.useState(!1),n=m.useRef(null),r=m.useCallback(()=>t(I),[]),i=m.useCallback(e=>{e.preventDefault(),t(t=>{const s=(a=t.scale-.0015*e.deltaY,n=1,r=4,Math.max(n,Math.min(r,a)));var a,n,r;return 1===s?I:{...t,scale:s}})},[]),l=m.useCallback(t=>{var s,r;e.scale<=1||(n.current={x:t.clientX,y:t.clientY,tx:e.tx,ty:e.ty},a(!0),null==(r=(s=t.currentTarget).setPointerCapture)||r.call(s,t.pointerId))},[e.scale,e.tx,e.ty]),o=m.useCallback(e=>{if(!n.current)return;const s=e.clientX-n.current.x,a=e.clientY-n.current.y;t(e=>({...e,tx:n.current.tx+s,ty:n.current.ty+a}))},[]),d=m.useCallback(e=>{var t,s;n.current&&(n.current=null,a(!1),null==(s=(t=e.currentTarget).releasePointerCapture)||s.call(t,e.pointerId))},[]),c=m.useCallback(()=>r(),[r]),p=m.useMemo(()=>`translate(${e.tx}px, ${e.ty}px) scale(${e.scale})`,[e.tx,e.ty,e.scale]);return{scale:e.scale,tx:e.tx,ty:e.ty,isPanning:s,transform:p,isZoomed:e.scale>1,reducedMotion:"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,reset:r,onWheel:i,onPointerDown:l,onPointerMove:o,onPointerUp:d,onDoubleClick:c}}let z=0;const $=e=>{if(!e)return"";const t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString("pt-BR")},D=({imageUrl:e,annotations:t,onChange:s,readonly:d=!1,label:c,onOpenFullscreen:p})=>{const{t:x}=a("orders"),u=m.useRef(null),f=M(),[y,h]=m.useState(!1),[v,b]=m.useState(null),[j,w]=m.useState(""),[N,I]=m.useState(null),[D,E]=m.useState(""),L=t.find(e=>e.id===N)??null,T=m.useCallback(e=>{if(!y||d||!u.current)return;const t=u.current.getBoundingClientRect(),s=Math.max(0,Math.min(100,(e.clientX-t.left)/t.width*100)),a=Math.max(0,Math.min(100,(e.clientY-t.top)/t.height*100));b({x:s,y:a}),h(!1)},[y,d]),U=m.useCallback(()=>
7{if(!v||!j.trim())return b(null),void w("");s([...t,{id:`pin_${Date.now()}_${z++}`,x:v.x,y:v.y,text:j.trim(),status:"open",replies:[]}]),b(null),w("")},[v,j,t,s]),_=m.useCallback((e,a)=>s(t.map(t=>t.id===e?{...t,...a}:t)),[t,s]),O=m.useCallback(()=>{L&&D.trim()&&(_(L.id,{replies:[...L.replies??[],{text:D.trim()}]}),E(""))},[L,D,_]),A=m.useCallback(()=>{L&&_(L.id,{status:"resolved"===L.status?"open":"resolved"})},[L,_]),R=m.useCallback(e=>{s(t.filter(t=>t.id!==e)),N===e&&I(null)},[t,s,N]),Z=e=>"resolved"===e.status?"bg-snapfy-success":"bg-snapfy-error";return n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"relative overflow-hidden rounded-card border border-snapfy-border bg-snapfy-inner",style:{cursor:y?"crosshair":f.isZoomed?f.isPanning?"grabbing":"grab":"default"},onWheel:f.onWheel,onPointerDown:y?void 0:f.onPointerDown,onPointerMove:y?void 0:f.onPointerMove,onPointerUp:y?void 0:f.onPointerUp,onClick:T,children:[n.jsxs("div",{ref:u,className:"relative origin-center",style:{transform:f.transform,transition:f.reducedMotion||f.isPanning?"none":"transform 200ms"},children:[n.jsx("img",{src:e,alt:"",className:"block h-auto w-full select-none",draggable:!1}),t.map((e,t)=>n.jsxs("button",{type:"button",onClick:t=>{t.stopPropagation(),I(t=>t===e.id?null:e.id)},className:"group absolute -translate-x-1/2 -translate-y-1/2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-full focus-visible:outline focus-visible:outline-2 focus-visible:outline-snapfy-primary focus-visible:outline-offset-2 "+(N===e.id?"z-20":""),style:{left:`${e.x}%`,top:`${e.y}%`},"aria-label":e.text?`${t+1}. ${e.text}`:`pin ${t+1}`,children:[n.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-pill text-xs font-bold text-white shadow-[0_1px_4px_rgba(0,0,0,0.6)] ring-2 ring-white transition-transform duration-150 group-hover:scale-[1.15] ${Z(e)} ${N===e.id?"scale-[1.15] outline outline-2 outline-offset-2 outline-snapfy-primary":""}`,children:t+1}),e.text&&n.jsx("span",{className:"pointer-events-none absolute bottom-full left-1/2 z-30 mb-2 hidden w-max max-w-[220px] -translate-x-1/2 whitespace-normal rounded-card border border-snapfy-border bg-snapfy-surface px-3 py-2 text-left text-xs text-snapfy-text-primary shadow-modal group-hover:block",children:e.text.length>60?`${e.text.slice(0,60)}â¦`:e.text})]},e.id)),v&&n.jsx("div",{className:"absolute -translate-x-1/2 -translate-y-1/2",style:{left:`${v.x}%`,top:`${v.y}%`},children:n.jsx("span",{className:"flex h-6 w-6 items-center justify-center rounded-pill bg-snapfy-error text-xs font-bold text-white shadow-[0_1px_4px_rgba(0,0,0,0.6)] ring-2 ring-white",children:"?"})})]}),n.jsxs("div",{className:"absolute top-2 left-2 flex items-center gap-1.5",children:[c&&n.jsx("span",{className:"rounded-button bg-snapfy-surface/80 px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-snapfy-text-secondary backdrop-blur",children:c}),t.length>0&&n.jsx("span",{className:"rounded-pill bg-snapfy-surface/80 px-2 py-1 text-[10px] font-bold text-snapfy-primary backdrop-blur",children:x("annotation.count",{count:t.length})})]}),n.jsxs("div",{className:"absolute top-2 right-2 flex gap-1",children:[!d&&n.jsx(r,{"aria-label":x(y?"annotation.clickToPlace":"annotation.addPin"),"aria-pressed":y,onImagery:!0,onClick:()=>{h(e=>!e),b(null)},className:y?"ring-2 ring-white":"",children:n.jsx(k,{size:16})}),f.isZoomed&&n.jsx(r,{"aria-label":x("review.resetZoom"),onImagery:!0,onClick:f.reset,children:n.jsx(S,{size:16})}),p&&n.jsx(r,{"aria-label":x("review.fullscreen"),onImagery:!0,onClick:p,children:n.jsx(C,{size:16})})]})]}),v&&!d&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{autoFocus:!0,t
7ype:"text",value:j,onChange:e=>w(e.target.value),onKeyDown:e=>{"Enter"===e.key&&U(),"Escape"===e.key&&(b(null),w(""))},placeholder:x("annotation.describeIssue"),className:"flex-1 rounded-input border border-snapfy-border bg-snapfy-inner px-3 py-2 text-sm text-snapfy-text-primary"}),n.jsx(i,{variant:"primary",onClick:U,children:x("annotation.save")})]}),L&&n.jsxs("div",{className:"rounded-card border border-snapfy-border bg-snapfy-surface p-3 shadow-modal",children:[n.jsxs("div",{className:"mb-2 flex items-start justify-between gap-2",children:[n.jsxs("div",{children:[n.jsx("p",{className:"text-sm text-snapfy-text-primary",children:L.text}),n.jsxs("p",{className:"text-xs text-snapfy-text-secondary",children:[L.authorName?x("annotation.by",{name:L.authorName}):"",L.createdAt?` · ${$(L.createdAt)}`:""]})]}),"resolved"===L.status&&n.jsx(l,{variant:"success",children:x("annotation.resolved")})]}),(L.replies??[]).length>0&&n.jsx("ul",{className:"mb-2 space-y-1 border-l-2 border-snapfy-border pl-3",children:(L.replies??[]).map((e,t)=>n.jsxs("li",{className:"text-xs",children:[n.jsx("span",{className:"text-snapfy-text-primary",children:e.text}),n.jsxs("span",{className:"text-snapfy-text-secondary",children:[e.authorName?` â ${e.authorName}`:"",e.createdAt?` · ${$(e.createdAt)}`:""]})]},t))}),!d&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"text",value:D,onChange:e=>E(e.target.value),onKeyDown:e=>"Enter"===e.key&&O(),placeholder:x("annotation.reply"),className:"flex-1 rounded-input border border-snapfy-border bg-snapfy-inner px-3 py-1.5 text-xs text-snapfy-text-primary"}),n.jsx(r,{"aria-label":x("annotation.reply"),onClick:O,children:n.jsx(P,{size:14})}),n.jsx(i,{variant:"ghost",leadingIcon:n.jsx(g,{size:14}),onClick:A,children:"resolved"===L.status?x("annotation.reopen"):x("annotation.resolve")})]})]}),t.length>0&&n.jsx("ul",{className:"space-y-1",children:t.map((e,t)=>n.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-input border border-snapfy-border bg-snapfy-inner p-2 text-sm",children:[n.jsxs("button",{type:"button",onClick:()=>I(e.id),className:"flex flex-1 items-center gap-2 text-left",children:[n.jsxs("span",{className:"font-bold text-snapfy-primary",children:[t+1,"."]}),n.jsx("span",{className:"text-snapfy-text-secondary",children:e.text}),"resolved"===e.status&&n.jsx(l,{variant:"success",children:x("annotation.resolved")})]}),!d&&n.jsx("button",{type:"button",onClick:()=>R(e.id),className:"rounded p-1 text-snapfy-error hover:bg-snapfy-surface","aria-label":x("annotation.remove"),children:n.jsx(o,{size:16})})]},e.id))})]})},E=({imageUrl:e,title:t,annotations:s=[],onClose:i})=>{const{t:l}=a("orders"),d=M();return m.useEffect(()=>{const e=e=>"Escape"===e.key&&i();return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i]),n.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-snapfy-scrim backdrop-blur-sm",role:"dialog","aria-modal":"true","aria-label":t,children:[n.jsxs("div",{className:"absolute top-4 right-4 z-10 flex gap-2",children:[d.isZoomed&&n.jsx(r,{"aria-label":l("review.resetZoom"),onImagery:!0,onClick:d.reset,children:n.jsx(S,{size:18})}),n.jsx(r,{"aria-label":l("close"),onImagery:!0,onClick:i,children:n.jsx(o,{size:18})})]}),t&&n.jsx("span",{className:"absolute top-5 left-4 z-10 rounded-button bg-white/15 px-3 py-1 text-[11px] font-bold uppercase tracking-widest text-white backdrop-blur",children:t}),n.jsx("div",{className:"relative max-h-[92vh] max-w-[92vw] overflow-hidden",style:{cursor:d.isZoomed?d.isPanning?"grabbing":"grab":"default"},onWheel:d.onWheel,onPointerDown:d.onPointerDown,onPointerMove:d.onPointerMove,onPointerUp:d.onPointerUp,onDoubleClick:d.onDoubleClick,children:n.jsxs("div",{className:"relative origin-center",style:{transform:d.transform,transition:d.reducedMotion||d.isPanning?"none":"transform 200ms"},children:[n.jsx("img",{src:e,alt:t||"",className:"block max-h-[92vh] max-w-[92vw] object-contain select-none",draggable:!1}),s.map((e,t)=>n.jsx("span",{className:"absolute flex h-6 w-6 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-pill border-2 border-white text-xs font-bold text-white shadow-lg "+("resolved"===e.status?"bg-snapfy-success":"bg-snapfy-primary"),style:{left:`${e.x}%`,top:`${e.y}%`},children:t+1},e.id))]})})]})},L=({image:e,label:t,onFullscreen:s})=>{const{t:i}=a("orders"),l=M();return n.jsxs("div",{className:"relative overflow-hidden rounded-card border border-snapfy-border bg-snapfy-inner",style:{cursor:l.isZoomed?l.isPanning?"grabbing":"grab":"default"},onWheel:l.onWheel,onPointerDown:l.onPointerDown,onPointerMove:l.onPointerMove,onPointerUp:l.onPointerUp,onDoubleClick:l.onDoubleClick,children:[n.jsx("div",{className:"relative origin-center",style:{transform:l.transform,transition:l.reducedMotion||l.isPanning?"n
7one":"transform 200ms"},children:n.jsx("img",{src:e.url,alt:"",className:"block h-auto w-full select-none",draggable:!1})}),n.jsx("span",{className:"absolute top-2 left-2 rounded-button bg-snapfy-surface/80 px-2 py-1 text-[10px] font-bold uppercase tracking-widest text-snapfy-text-secondary backdrop-blur",children:t}),n.jsxs("div",{className:"absolute top-2 right-2 flex gap-1",children:[l.isZoomed&&n.jsx(r,{"aria-label":i("review.resetZoom"),onClick:l.reset,children:n.jsx(S,{size:16})}),n.jsx(r,{"aria-label":i("review.fullscreen"),onClick:s,children:n.jsx(C,{size:16})})]})]})},T=({before:e,after:t,annotations:s,onAnnotationsChange:r,readonly:i=!1})=>{const{t:l}=a("orders"),[o,d]=m.useState(null),c=`${l("delivery.after")} · ${l("delivery.version",{n:t.version})}`;return n.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-2",children:[n.jsx("div",{children:e?n.jsx(L,{image:e,label:l("delivery.before"),onFullscreen:()=>d({url:e.url,title:l("delivery.before")})}):n.jsx("div",{className:"rounded-card border border-snapfy-border bg-snapfy-inner p-8 text-center text-xs text-snapfy-text-secondary",children:l("noImages")})}),n.jsx(D,{imageUrl:t.url,annotations:s,onChange:r,readonly:i,label:c,onOpenFullscreen:()=>d({url:t.url,title:c,annotations:s})}),o&&n.jsx(E,{imageUrl:o.url,title:o.title,annotations:o.annotations,onClose:()=>d(null)})]})},U={approved:"bg-snapfy-success",rejected:"bg-snapfy-error",pending:"bg-snapfy-warning"},_=({images:e,selectedId:t,onSelect:s})=>{const{t:r}=a("orders");if(e.length<=1)return null;const i=[...e].sort((e,t)=>t.version-e.version);return n.jsxs("div",{children:[n.jsx("p",{className:"mb-1.5 text-[10px] font-bold uppercase tracking-widest text-snapfy-text-secondary",children:r("delivery.version",{n:""}).trim()}),n.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:i.map(e=>{const a=e.id===t;return n.jsxs("button",{type:"button",onClick:()=>s(e),className:"relative shrink-0 rounded-input border "+(a?"border-snapfy-primary ring-2 ring-snapfy-primary":"border-snapfy-border"),"aria-label":`v${e.version}`,"aria-pressed":a,children:[n.jsx("img",{src:e.thumbnailUrl||e.url,alt:"",loading:"lazy",className:"h-16 w-16 rounded-input object-cover"}),n.jsxs("span",{className:"absolute bottom-0 right-0 rounded-tl bg-snapfy-surface px-1 text-[9px] text-snapfy-text-secondary",children:["v",e.version]}),n.jsx("span",{className:`absolute top-1 left-1 h-2 w-2 rounded-pill ${U[e.approvalStatus]}`})]},e.id)})})]})};let O=0;const A=({isOpen:e,onClose:t,itemName:s,image:r,submitting:l,onConfirm:o})=>{var p;const{t:x}=a("orders"),[u,f]=m.useState(r.annotations??[]),[y,h]=m.useState(""),g=(null==(p=r.annotations)?void 0:p.length)??0,v=u.length>g||y.trim().length>0,b=()=>{l||(f(r.annotations??[]),h(""),t())};return n.jsx(d,{isOpen:e,onClose:b,title:x("review.rejectModalTitle",{name:s}),footer:n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(i,{variant:"ghost",onClick:b,disabled:l,children:x("cancel")}),n.jsx(i,{variant:"danger",onClick:async()=>{if(!v||l)return;const e=u.length>0?u:[{id:`pin_general_${Date.now()}_${O++}`,x:50,y:50,text:y.trim(),status:"open",replies:[]}];await o(e),h("")},isLoading:l,disabled:!v,children:x("delivery.reject")})]}),children:n.jsxs("div",{className:"space-y-4",children:[n.jsx("p",{className:"text-sm text-snapfy-text-secondary",children:x("review.rejectModalHint")}),n.jsx(D,{imageUrl:r.url,annotations:u,onChange:f,label:x("delivery.version",{n:r.version})}),n.jsx(c,{label:x("review.rejectReasonLabel"),value:y,onChange:e=>h(e.target.value),placeholder:x("review.rejectReasonPlaceholder")})]})})},R=({orderId:e,item:t,initialImageId:s})=>{const{t:r}=a("orders"),{addAnnotations:d,approveImage:c,rejectImage:x}=h(),u=(t.inputImages??[])[0],f=m.useMemo(()=>[...t.outputImages??[]].sort((e,t)=>t.version-e.version),[t.outputImages]),y=f[0],[v,b]=m.useState(s??(null==y?void 0:y.id)),j=f.find(e=>e.id===v)??y,[w,N]=m.useState(null),[k,C]=m.useState({}),[S,P]=m.useState(!1);if(!j)return n.jsxs(p,{className:"p-4",children:[n.jsx("div",{className:"mb-2 flex items-center justify-between gap-3",children:n.jsx("h3",{className:"text-lg font-semibold text-snapfy-text-primary",children:t.name})}),n.jsx("p",{className:"text-sm text-snapfy-text-secondary",children:r("noImages")})]});const I=e=>k[e.id]??e.annotations??[],M="approved"===j.approvalStatus;return n.jsxs(p,{className:"overflow-hidden p-0",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 p-4",children:[n.jsx("h3",{className:"text-lg font-semibold text-snapfy-text-primary",children:t.name}),n.jsx(l,{variant:(z=j.approvalStatus,"approved"===z?"success":"rejected"===z?"error":"warning"),children:r(j.approvalStatus)})]}),n.jsx("div",{className:"px-4",children:n.jsx(T,{before:u,after:j,annotations:I(j),onAnnotationsChange:s=>((s,a)=>{const n=a.length<I(s).length;C(e=>({...e,[s.id]:a})),n||d(e,t.id,s.id,a).then(()=>C(e=>{const t={...e};return delete t[s.id],t})).catch(()=>{})})(j,s),readonly:M})}),n.jsxs("div",{className:"p-4",children:[n.jsx(_,{images:f,selectedId:j.id,onSelect:e=>b(e.id)}),!M&&n.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[n.jsx(i,{variant:"solid",size:"sm",leadingIcon:n.jsx(g,{size:14}),isLoading:w===j.id,onClick:()=>(async s=>{N(s.id);try{const a=I(s);a.length>0&&await d(e,t.id,s.id,a),await c(e,t.id,s.id),C(e=>{const t={...e};return delete t[s.id],t})}finally{N(null)}})(j),children:r("delivery.approve")}),n.jsx(i,{variant:"danger",size:"sm",leadingIcon:n.jsx(o,{size:14}),isLoading:w===j.id,onClick:()=>P(!0),children:r("delivery.reject")})]})]}),n.jsx(A,{isOpen:S,onClose:()=>P(!1),itemName:t.name,image:{...j,annotations:I(j)},submitting:w===j.id,onConfirm:s=>(async(s,a)=>{N(s.id);try{await x(e,t.id,s.id,a),C(e=>{const t={...e};return delete t[s.id],t}),P(!1)}finally{N(null)}})(j,s)})]});var z};function Z(e){const t=[];for(const s of e){const e=s.outputImages??[];if(0===e.length)continue;const a=Math.max(...e.map(e=>e.version));e.filter(e=>
7e.version===a).forEach((e,a)=>t.push({item:s,image:e,index:a+1}))}return t}const F={low:1,medium:2,high:3},W={approved:"border-snapfy-success/40",rejected:"border-snapfy-error/40",pending:"border-snapfy-border"},q=({orderId:e,entry:t,onSelect:s})=>{var r;const{t:o}=a("orders"),{approveImage:d,rejectImage:c}=h(),{item:x,image:u,index:f}=t,y=(e=>{let t;for(const s of e.inputImages??[])s.riskLevel&&(!t||F[s.riskLevel]>F[t])&&(t=s.riskLevel);return t})(x),g=(null==(r=u.annotations)?void 0:r.length)??0,[v,b]=m.useState(!1),[j,N]=m.useState(!1),[C,S]=m.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsxs(p,{interactive:!0,onClick:s,role:"button",tabIndex:0,onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),s())},"aria-label":o("review.openItem",{name:x.name}),className:`flex flex-col gap-2 p-2 ${W[u.approvalStatus]}`,children:[n.jsxs("div",{className:"relative aspect-square overflow-hidden rounded-chip bg-snapfy-inner",children:[u.thumbnailUrl||u.url?n.jsx("img",{src:u.thumbnailUrl||u.url,alt:"",loading:"lazy",className:"h-full w-full object-cover"}):n.jsx("div",{className:"flex h-full w-full items-center justify-center text-snapfy-text-secondary",children:n.jsx(w,{size:24})}),n.jsx("span",{className:"absolute left-1 top-1 rounded-pill bg-snapfy-surface/80 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wide text-snapfy-text-primary backdrop-blur",children:o("review.versionPhoto",{version:u.version,n:f})}),g>0&&n.jsxs("span",{className:"absolute right-1 top-1 inline-flex items-center gap-1 rounded-pill bg-snapfy-error px-2 py-0.5 text-[10px] font-bold text-white",children:[n.jsx(k,{size:11})," ",g]})]}),n.jsx("p",{className:"truncate text-sm font-semibold text-snapfy-text-primary",title:x.name,children:x.name}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsx(l,{variant:(P=u.approvalStatus,"approved"===P?"success":"rejected"===P?"error":"warning"),children:o(u.approvalStatus)}),y&&"low"!==y&&n.jsx(l,{variant:"high"===y?"error":"warning",children:o(`review.risk.${y}`)})]}),"pending"===u.approvalStatus&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(i,{variant:"solid",size:"sm",isLoading:v,onClick:async t=>{t.stopPropagation(),b(!0);try{await d(e,x.id,u.id)}finally{b(!1)}},className:"flex-1",children:o("delivery.approve")}),n.jsx(i,{variant:"danger",size:"sm",isLoading:j,onClick:e=>{e.stopPropagation(),S(!0)},className:"flex-1",children:o("review.rejectAction")})]}),"rejected"===u.approvalStatus&&n.jsx("p",{className:"text-xs leading-relaxed text-snapfy-text-secondary",children:o("review.rejectedNote")})]}),n.jsx(A,{isOpen:C,onClose:()=>S(!1),itemName:x.name,image:u,submitting:j,onConfirm:async t=>{N(!0);try{await c(e,x.id,u.id,t),S(!1)}finally{N(!1)}}})]});var P},B=({items:e,orderId:t,onSelect:s})=>{const{t:r}=a("orders"),[i,l]=m.useState("all"),o=m.useMemo(()=>Z(e),[e]),d=m.useMemo(()=>{let e=0,t=0;for(const s of o)"pending"===s.image.approvalStatus&&(e+=1),"rejected"===s.image.approvalStatus&&(t+=1);return{all:o.length,pending:e,rejected:t}},[o]),c=m.useMemo(()=>"pending"===i?o.filter(e=>"pending"===e.image.approvalStatus):"rejected"===i?o.filter(e=>"rejected"===e.image.approvalStatus):o,[o,i]);return n.jsxs("div",{children:[n.jsxs("div",{className:"mb-4 flex flex-wrap gap-2",children:[n.jsx(x,{appearance:"flat",selected:"all"===i,onClick:()=>l("all"),children:r("review.filter.all",{count:d.all})}),n.jsx(x,{appearance:"flat",selected:"pending"===i,onClick:()=>l("pending"),children:r("review.filter.pending",{count:d.pending})}),n.jsx(x,{appearance:"flat",selected:"rejected"===i,onClick:()=>l("rejected"),children:r("review.filter.rejected",{count:d.rejected})})]}),0===c.length?n.jsx("p",{className:"py-12 text-center text-sm text-snapfy-text-secondary",children:r("review.noItemsForFilter")}):n.jsx("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5",children:c.map(e=>n.jsx(q,{orderId:t,entry:e,onSelect:()=>s(e.item,e.image.id)},e.image.id))})]})};const Y=()=>{const{t:e}=a("orders"),t=f(),{id:s}=y(),{selectedOrder:r,error:o,saving:c,fetchOrder:p,approveAll:x}=h(),[w,k]=m.useState(!1),[C,S]=m.useState(!1),[P,I]=m.useState(null),[M,z]=m.useState(!1),[$,D]=m.useState(null),[E,L]=m.useState(void 0);m.useEffect(()=>{s&&p(s)},[s,p]),m.useEffect(()=>{D(null),L(void 0)},[s]);const T=r&&String(r.id)===String(s)?r:null,U=(null==T?void 0:T.items)??[],_=$?U.find(e=>e.id===$)??null:null,O=m.useMemo(()=>Z(U),[U]),A=m.useMemo(()=>{const e=O.filter(e=>"approved"===e.image.approvalStatus).length,t=O.filter(e=>"rejected"===e.image.approvalStatus).length;return{approved:e,rejected:t,total:O.length}},[O]),F=m.useMemo(()=>O.filter(e=>"pending"===e.image.approvalStatus),[O]);return n.jsx("div",{className:"mx-auto max-w-6xl p-4 md:p-8",children:T?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"sticky top-0 z-20 -mx-4 border-b border-snapfy-border bg-snapfy-bg/80 px-4 py-4 backdrop-blur-md md:-mx-8 md:px-8",children:[n.jsxs("button",{type:"button",onClick:()=>t("/orders"),className:"mb-2 inline-flex items-center gap-1 text-sm text-snapfy-text-secondary hover:text-snapfy-primary",children:[n.jsx(j,{size:16})," ",e("backToOrders")]}),n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[n.jsx("h1",{className:"text-3xl font-extrabold text-snapfy-text-primary",children:T.titulo||e("deliveryTitle",{number:T.numeroPedido})}),n.jsx(l,{variant:(W=T.status,"completed"===W?"success":"in_approval"===W||"in_adjustments"===W?"warning":"info"),children:e(`status.${T.status}`)})]}),n.jsx("p",{className:"mt-1 font-mono text-xs text-snapfy-text-secondary",children:e("deliveryTitle",{number:T.numeroPedido})})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(i,{variant:"cta",size:"sm",leadingIcon:n.jsx(g,{size:16}),disabled:0===F.length,onClick:()=>z(!0),children:e("review.approvePendingBtn",{count:F.length})}),n.jsx(i,{variant:"ghost",size:"sm",leadingIcon:n.jsx(v,{size:16}),isLoading:C,disabled:0===A.approved,onClick:async()=>
7{if(s&&!C){S(!0),I(null);try{const e=await u.downloadZip(s),t=URL.createObjectURL(e),a=document.createElement("a");a.href=t,a.download=`pedido-${(null==T?void 0:T.numeroPedido)??s}.zip`,document.body.appendChild(a),a.click(),a.remove(),setTimeout(()=>URL.revokeObjectURL(t),1e3)}catch(t){I(function(e){return e instanceof Error?e.message:String(e)}(t)||e("review.downloadError"))}finally{S(!1)}}},children:e("delivery.downloadZip")})]})]}),n.jsx("div",{className:"mt-4",children:n.jsx(b,{status:T.status,variant:"horizontal",className:"max-w-3xl"})}),A.total>0&&n.jsxs("div",{className:"mt-3",children:[n.jsxs("div",{className:"mb-1 flex flex-wrap items-center justify-between gap-2",children:[n.jsx("p",{className:"text-xs text-snapfy-text-secondary",children:e("review.approvedProgress",{done:A.approved,total:A.total})}),A.rejected>0&&n.jsx("p",{className:"text-xs text-snapfy-text-secondary",children:e("review.rejectedAwaitingAdjustment",{count:A.rejected})})]}),n.jsxs("div",{className:"flex h-2 gap-0.5 overflow-hidden rounded-pill bg-snapfy-inner",children:[n.jsx("div",{className:"h-full bg-snapfy-success transition-all duration-300",style:{width:A.approved/A.total*100+"%"}}),n.jsx("div",{className:"h-full bg-snapfy-error transition-all duration-300",style:{width:A.rejected/A.total*100+"%"}})]})]}),P&&n.jsx("p",{className:"mt-2 text-xs text-snapfy-error",children:P})]}),o&&n.jsx("p",{className:"mt-4 text-sm text-snapfy-error",children:o}),_?n.jsxs("div",{className:"mt-6 space-y-4",children:[n.jsxs("button",{type:"button",onClick:()=>{D(null),L(void 0)},className:"inline-flex items-center gap-1 text-sm text-snapfy-text-secondary hover:text-snapfy-primary",children:[n.jsx(N,{size:16})," ",e("review.backToGrid")]}),n.jsx(R,{orderId:T.id,item:_,initialImageId:E},`${_.id}:${E??""}`)]}):n.jsx("div",{className:"mt-6",children:n.jsx(B,{items:U,orderId:T.id,onSelect:(e,t)=>{D(e.id),L(t)}})}),n.jsx(d,{isOpen:M,onClose:()=>w?void 0:z(!1),title:e("review.approvePendingModalTitle"),footer:n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(i,{variant:"ghost",onClick:()=>z(!1),disabled:w,children:e("cancel")}),n.jsx(i,{variant:"cta",onClick:async()=>{if(s){k(!0);try{await x(s),z(!1)}finally{k(!1)}}},isLoading:w||c,disabled:0===F.length,children:e("review.approvePendingConfirm",{count:F.length})})]}),children:n.jsxs("div",{className:"space-y-3",children:[n.jsx("p",{className:"text-sm text-snapfy-text-secondary",children:e("review.approvePendingModalBody")}),n.jsx("ul",{className:"max-h-64 space-y-1.5 overflow-y-auto",children:F.map(t=>n.jsxs("li",{className:"rounded-input border border-snapfy-border bg-snapfy-inner px-3 py-2 text-sm text-snapfy-text-primary",children:[t.item.name," ·"," ",n.jsx("span",{className:"text-snapfy-text-secondary",children:e("review.versionPhoto",{version:t.image.version,n:t.index})})]},t.image.id))})]})})]}):n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",onClick:()=>t("/orders"),className:"mb-4 inline-flex items-center gap-1 text-sm text-snapfy-text-secondary hover:text-snapfy-primary",children:[n.jsx(j,{size:16})," ",e("backToOrders")]}),n.jsx("p",{className:"text-sm text-snapfy-text-secondary",children:o??e("loading")})]})});var W};export{Y as default}; 8//# sourceMappingURL=OrderDeliveryPage.DnAk6yNn.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.