1import{u as B,r as p,t as j,j as e}from"./vendor-react-zwv87yMD.js";import{u as H,a as W,b as F}from"./vendor-query-DYq8g7OI.js";import{B as v}from"./button-DlBDuKbo.js";import{A as V,a as $,b as Z,c as ee,d as te,e as se,f as ae,g as ie}from"./alert-dialog-P2RRIvov.js";import{u as ne}from"./authStore-Bv6p2Ne2.js";import{u as ce}from"./useOrgTimezone-C1UagyKl.js";import{e as re}from"./timezoneFormatters-Lg56xFv0.js";import{m as b}from"./menu-intake-D-gbes2v.js";import{v as U,A as le}from"./vendor-icons-bLSWzydc.js";import{e as de,c as oe,L as ue}from"./vendor-router-DimZLiZb.js";import"./vendor-charts-CtrTLS4K.js";import"./vendor-i18n-BdYkS11p.js";import"./vendor-ui-CfDMlrKu.js";import"./vendor-pdf-DQuePnfN.js";import"./vendor-state-ByI9XJey.js";import"./vendor-editor-C_dhmuey.js";import"./utils-BXSzAfFa.js";import"./api-client-wl3SCNAO.js";import"./i18n-CwjSIy0a.js";import"./employeeAuthStore-lYSKMuhw.js";function me(s,l){const[x,m]=p.useState({}),D=l.join(",");return p.useEffect(()=>{if(!s||l.length===0)return;let g=!1;const I=[],N=[...l];let u=0;const d=()=>{for(;!g&&u<4&&N.length>0;){const f=N.shift();u+=1,b.photoBlob(s,f,!0).then(C=>{if(g)return;const A=URL.createObjectURL(C);I.push(A),m(E=>({...E,[f]:A}))}).catch(()=>{}).finally(()=>{u-=1,d()})}};return d(),()=>{g=!0,I.forEach(f=>URL.revokeObjectURL(f))}},[s,D]),x}function pe(s){return s<=1?1500:s===2?3e3:5e3}function qe(){var L,O,K,w,z;const{t:s}=B("menu"),{jobId:l}=de(),x=oe(),m=H(),{permissions:D,currentOrganizationId:g}=ne(),I=ce(),N=D.includes("MANAGE_MENU_ITEMS"),[u,d]=p.useState([]),[f,C]=p.useState(0),[A,E]=p.useState(!1),[G,y]=p.useState(!1),q=p.useMemo(()=>Date.now(),[l]),o=W({queryKey:["menuIntakeJob",l,g],queryFn:()=>b.get(l),enabled:!!l&&!!g&&N,refetchInterval:t=>{var n;const c=(n=t.state.data)==null?void 0:n.status;return c==="QUEUED"||c==="EXTRACTING"?pe(f):!1}});p.useEffect(()=>{var t,c;(((t=o.data)==null?void 0:t.status)==="QUEUED"||((c=o.data)==null?void 0:c.status)==="EXTRACTING")&&(C(n=>n+1),Date.now()-q>180*1e3&&E(!0))},[o.dataUpdatedAt,(L=o.data)==null?void 0:L.status,q]),p.useEffect(()=>{var t,c,n;((t=o.data)==null?void 0:t.status)==="READY"&&d(o.data.items.map(a=>({...a}))),(((c=o.data)==null?void 0:c.status)==="ACCEPTED"||((n=o.data)==null?void 0:n.status)==="DISCARDED")&&x("/dashboard/menu-items")},[o.data,x]);const P=F({mutationFn:t=>b.accept(l,t),onSuccess:t=>{m.invalidateQueries({queryKey:["menuItems"]}),m.invalidateQueries({queryKey:["menuItemSearch"]}),m.invalidateQueries({queryKey:["menuItemCategories"]}),m.invalidateQueries({queryKey:["catering-menu-items"]}),m.invalidateQueries({queryKey:["menuIntakeJobs"]});const c=t.data.photosAttached??0,n=t.data.photosFailed??0,a=t.data.updated??0;j.success(a>0?s("items.intake.acceptedCatering",{count:a}):n>0?s("items.intake.acceptedWithPhotos",{count:t.data.created,photos:c,failed:n}):c>0?s("items.intake.acceptedPhotos",{count:t.data.created,photos:c}):s("items.intake.accepted",{count:t.data.created})),x("/dashboard/menu-items")},onError:t=>{var c,n,a,r;j.error(((n=(c=t==null?void 0:t.response)==null?void 0:c.data)==null?void 0:n.errorCode)||((r=(a=t==null?void 0:t.response)==null?void 0:a.data)==null?void 0:r.message)||s("items.intake.errors.generic"))}}),M=F({mutationFn:()=>b.retry(l),onSuccess:()=>
1{E(!1),C(0),m.invalidateQueries({queryKey:["menuIntakeJob",l]})}}),T=F({mutationFn:()=>b.discard(l),onSuccess:t=>{y(!1),m.invalidateQueries({queryKey:["menuIntakeJobs"]}),m.invalidateQueries({queryKey:["menuIntakeJob",l]}),t.data.status==="DISCARDED"?(j.success(s("items.intake.discarded")),x("/dashboard/menu-items")):j.success(s("items.intake.statusCanceling"))},onError:t=>{var c,n,a,r;j.error(((n=(c=t==null?void 0:t.response)==null?void 0:c.data)==null?void 0:n.errorCode)||((r=(a=t==null?void 0:t.response)==null?void 0:a.data)==null?void 0:r.message)||s("items.intake.errors.generic"))}}),J=p.useMemo(()=>u.filter(t=>t.hasPhoto).map(t=>t.clientId),[u]),S=me(((O=o.data)==null?void 0:O.status)==="READY"?l:void 0,J);if(!N)return e.jsx("p",{className:"p-6 text-muted-foreground",children:s("bulk.noPermission")});const i=o.data,k=u.filter(t=>t.include),Y=u.filter(t=>t.match.status==="existing").length,h=(i==null?void 0:i.purpose)==="catering",X=u.filter(t=>t.match.status==="new").length,R=!!l&&((i==null?void 0:i.status)==="QUEUED"||(i==null?void 0:i.status)==="EXTRACTING"||(i==null?void 0:i.status)==="READY"||(i==null?void 0:i.status)==="FAILED")&&!i.cancelRequested,_=()=>P.mutate(u.map(t=>({clientId:t.clientId,include:t.include,englishName:t.englishName,chineseName:t.chineseName,category:t.category,price:t.price,portion:t.portion,cateringPrice:t.cateringPrice,cateringPortion:t.cateringPortion,description:t.description,includePhoto:t.includePhoto}))),Q=e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(v,{disabled:k.length===0||P.isPending,onClick:()=>_(),children:[P.isPending&&e.jsx(U,{className:"h-4 w-4 mr-2 animate-spin"}),h?s("items.intake.saveCateringN",{count:k.length}):s("items.intake.addN",{count:k.length})]}),R&&e.jsx(v,{type:"button",variant:"outline",className:"text-destructive border-destructive/50 hover:bg-destructive/10",onClick:()=>y(!0),children:s("items.intake.discard")})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(ue,{to:"/dashboard/menu-items",className:"inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(le,{className:"h-4 w-4"}),s("items.title")]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3 sticky top-16 z-20 bg-background py-2 -mx-1 px-1 border-b",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:s(h?"items.intake.reviewTitleCatering":"items.intake.reviewTitle")}),(i==null?void 0:i.createdAt)&&e.jsx("p",{className:"text-sm text-muted-foreground",children:re(i.createdAt,I)})]}),(i==null?void 0:i.status)==="READY"&&Q]}),o.isLoading&&e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground py-12 justify-center",children:[e.jsx(U,{className:"h-5 w-5 animate-spin"}),s("items.intake.loading")]}),((i==null?void 0:i.status)==="QUEUED"||(i==null?void 0:i.status)==="EXTRACTING")&&e.jsxs("div",{className:"border rounded-lg p-6 text-center space-y-3",children:[i.cancelRequested?e.jsx("p",{children:s("items.intake.statusCanceling")}):e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"h-6 w-6 animate-spin mx-auto"}),e.jsx("p",{children:s("items.intake.extracting")}),A&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s("items.intake.stillWorking")})]}),R&&e.jsx(v,{type:"button",variant:"outline",className:"text-destructive border-destructive/50 hover:bg-destructive/10",onClick:()=>y(!0),children:s("items.intake.discard")})]}),(i==null?void 0:i.status)==="FAILED"&&e.jsxs("div",{className:"border border-destructive rounded-lg p-6 space-y-3",children:[e.jsx("p",{className:"font-medium",children:s(`items.intake.errors.${i.errorCode}`,{defaultValue:i.errorMessage||i.errorCode})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{onClick:()=>M.mutate(),disabled:M.isPending,children:s("items.intake.retry")}),R&&e.jsx(v,{type:"button",variant:"outline",className:"text-destructive border-destructive/50 hover:bg-destructive/10",onClick:()=>y(!0),children:s("items.intake.discard")})]})]}),(i==null?void 0:i.status)==="READY"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:h?s("items.intake.footerCatering",{n:k.length,m:X}):s("items.intake.footer",{n:k.length,m:Y})}),((K=i.warnings)==null?void 0:K.includes("PHOTOS_PARTIAL"))&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s("items.intake.photosPartial")}),((w=i.warnings)==null?void 0:w.includes("PHOTOS_TRUNCATED"))&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s("items.intake.photosTruncated",{count:((z=i.dishPhotos)==null?void 0:z.stored)??0})}),e.jsx("div",{className:"border rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm min-w-[56rem]",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"px-3 py-2",children:s("items.intake.col.include")}),!h&&e.jsx("th",{className:"px-3 py-2",children:s("items.intake.col.photo")}),e.jsx("th",{className:"px-3 py-2",children:s("items.intake.col.match")}),e.jsx("th",{className:"px-3 py-2",children:s("bulk.col.item")}),e.jsx("th",{className:"px-3 py-2",children:s("bulk.col.category")}),h?e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"px-3 py-2",children:s("bulk.col.cateringPrice")}),e.jsx("th",{className:"px-3 py-2",children:s("bulk.col.cateringPortion")})]}):e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"px-3 py-2",children:s("bulk.col.price")}),e.jsx("th",{className:"px-3 py-2",children:s("bulk.col.portion")}),e.jsx("th",{className:"px-3 py-2",children:s("items.form.description")})]})]})}),e.jsx("tbody",{children:u.map(t=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"px-3 py-2",children:e.jsx("input",{type:"checkbox",checked:t.include,disabled:h?t.match.status!=="existing"||t.cateringPrice==null:t.match.status==="existing"||t.price==null&&t.match.status==="new",onChange:c=>d(n=>n.map(a=>a.clientId===t.clientId?{...a,include:c.target.checked}:a))})}),!h&&e.jsx("td",{className:"px-3 py-2",children:t.hasPhoto?e.jsxs("label",{className:"flex items-center gap-2",children:[S[t.clientId]?e.jsx("img",{src:S[t.clientId],alt:"",className:"h-12 w-12 rounded object-cover"}):e.jsx("span",{className:"h-12 w-12 rounded bg-muted inline-block"}),e.jsx("input",{type:"checkbox",checked:t.includePhoto!==!1,onChange:c=>d(n=>n.map(a=>a.clientId===t.clientId?{...a,includePhoto:c.target.checked}:a))}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s("items.intake.keepPhoto")})]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"})}),e.jsx("td",{className:"px-3 py-2",children:t.match.status==="existing"?s("items.intake.existing"):s(h?"items.intake.unmatched":"items.intake.new")}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("input",{className:"w-full px-2 py-1 border rounded mb-1",value:t.englishName,onChange:c=>d(n=>n.map(a=>a.clientId===t.clientId?{...a,englishName:c.target.value}:a))}),e.jsx("input",{className:"w-full px-2 py-1 border rounded text-muted-foreground",value:t.chineseName||"",onChange:c=>d(n=>n.map(a=>a.clientId===t.clientId?{...a,chineseName:c.target.value}:a))})]}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("input",{className:"w-full px-2 py-1 border rounded",value:t.category||"",onChange:c=>d(n=>n.map(a=>a.clientId===t.clientId?{...a,category:c.target.value}:a))})}),h?e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-3 py-2",children:e.jsx("input",{className:"w-24 px-2 py-1 border rounded",inputMode:"decimal",value:t.cateringPrice??"",onChange:c=>{const n=c.target.value.trim()===""?null:Number(c.target.value);d(a=>a.map(r=>r.clientId===t.clientId?{...r,cateringPrice:n,include:r.match.status==="existing"&&n!=null&&Number.isFinite(n)}:r))}})}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("input",{className:"w-28 px-2 py-1 border rounded",value:t.cateringPortion||"",onChange:c=>d(n=>n.map(a=>a.clientId===t.clientId?{...a,cateringPortion:c.target.value}:a))})})]}):e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-3 py-2",children:e.jsx("input",{className:"w-24 px-2 py-1 border rounded",inputMode:"decimal",value:t.price??"",onChange:c=>{const n=c.target.value.trim()===""?null:Number(c.target.value);d(a=>a.map(r=>r.clientId===t.clientId?{...r,price:n,include:r.match.status==="new"&&n!=null&&Number.isFinite(n)?!0:r.include&&n!=null}:r))}})}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("input",{className:"w-28 px-2 py-1 border rounded",value:t.portion||"",onChange:c=>d(n=>n.map(a=>a.clientId===t.clientId?{...a,portion:c.target.value}:a))})}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("input",{className:"w-full px-2 py-1 border rounded",value:t.description||"",onChange:c=>d(n=>n.map(a=>a.clientId===t.clientId?{...a,description:c.target.value}:a))})})]})]},t.clientId))})]})}),Q]}),e.jsx(V,{open:G,onOpenChange:y,children:e.jsxs($,{children:[e.jsxs(Z,{children:[e.jsx(ee,{children:s("items.intake.discardConfirmTitle")}),e.jsx(te,{children:s("items.intake.discardConfirmDescription")})]}),e.jsxs(se,{children:[e.jsx(ae,{children:s("items.intake.discardCancel")}),e.jsx(ie,{onClick:()=>T.mutate(),disabled:T.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:T.isPending?s("items.intake.discarding"):s("items.intake.discardConfirm")})]})]})})]})}export{qe as default};
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.