PageSourceSearch

https://bizvanguard.ai/assets/DocumentReview-BfNqQLFp.js

js bizvanguard.ai collected 2026-10-05 13:48:18 UTC 64,996 bytes, 1 lines download raw bytes

1import{r as c,j as e,u as Pe,t as te}from"./vendor-react-zwv87yMD.js";import{u as ot,a as ct,b as ve}from"./vendor-query-DYq8g7OI.js";import{d as Q}from"./document-ai-CL0R1wiL.js";import{u as dt,C as ut}from"./useCheckAnalysis-DahXp-SP.js";import{u as xt}from"./authStore-Bv6p2Ne2.js";import{a as mt}from"./timezoneFormatters-Lg56xFv0.js";import{B as se}from"./button-DlBDuKbo.js";import{T as ht}from"./textarea-CfTUtQow.js";import{c as J}from"./utils-BXSzAfFa.js";import{u as ft}from"./usePermissions-CBDKNj1w.js";import{a as Te}from"./apiError-3JmRUUhQ.js";import{e as pt,i as gt,d as bt,g as Qe,f as Ve,r as vt}from"./effectivePlatformTake-DBYFemwW.js";import{U as yt,a as jt}from"./UseForMatchingButton-D8Lxsqw3.js";import"./pdfWorker-El_8qpqi.js";import{aq as Nt,e as wt,b as kt}from"./vendor-icons-bLSWzydc.js";import{g as St}from"./vendor-pdf-DQuePnfN.js";import{D as Ae,a as De,b as Ie,c as Le,d as Oe}from"./dialog-CCoQRIQ_.js";import{e as Ct,b as Tt,L as Pt}from"./vendor-router-DimZLiZb.js";import"./vendor-charts-CtrTLS4K.js";import"./vendor-i18n-BdYkS11p.js";import"./vendor-ui-CfDMlrKu.js";import"./vendor-state-ByI9XJey.js";import"./vendor-editor-C_dhmuey.js";import"./api-client-wl3SCNAO.js";import"./i18n-CwjSIy0a.js";import"./credit-cards-BnCVDKkT.js";import"./monthKeyFromPeriod-tJ6EjOLJ.js";import"./input-C9cRIRX4.js";import"./select-D2pLZtG9.js";function Ge(t){return t.toLowerCase().replace(/[$,]/g,"").trim()}function Et(t,d){const i=Ge(d).split(/\s+/).filter(Boolean);if(i.length===0)return!0;const x=Math.abs(t.amount)/100,o=Ge([t.date,t.description,t.checkPayee,t.checkNumber,t.category,t.type,x.toFixed(2),x.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})].filter(Boolean).join(" "));return i.every(h=>o.includes(h))}function Rt(t){return t.amount<0&&t.type!=="FEE"}function Mt(t,d){if(d.transactionId){const h=t.find(f=>f.id===d.transactionId);if(h)return h}const i=d.checkNumber.trim();if(!i)return;const x=new RegExp(`check\\s*#?\\s*${i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`,"i"),o=t.filter(Rt);return o.find(h=>h.checkNumber===i)||o.find(h=>x.test(h.description))}function At(t){return/\s/.test(t)?"":t.toLowerCase()}function Dt(t){return t.replace(/\s+/g,"").toLowerCase()}function It(t,d){const i=[];for(let x=d;x<t.runs.length&&i.join(" ").length<48;x++){const o=t.runs[x].str.trim();o&&i.push(o)}return i.join(" ")}function Lt(t,d){const i=[],x=Math.max(0,d-3),o=Math.min(t.runs.length,d+5);for(let f=x;f<o;f++){const p=t.runs[f].str.trim();p&&i.push(p)}const h=i.join(" ");return h.length>80?`${h.slice(0,77)}…`:h}function Ft(t){return t.some(d=>d.runs.some(i=>i.str.trim().length>0))}function $t(t,d){const i=Dt(d);if(!i)return[];const x=[];for(const o of t){let h="";const f=[];o.runs.forEach((y,w)=>{for(const k of y.str){const M=At(k);M&&(h+=M,f.push({run:w}))}});let p=0;for(;p<=h.length-i.length;){const y=h.indexOf(i,p);if(y<0)break;const w=o.runs[f[y].run];x.push({pageNumber:o.pageNumber,top:Math.max(0,Math.round(o.height-w.y)),snippet:Lt(o,f[y].run),highlight:It(o,f[y].run)}),p=y+i.length}}return x}function Ot(t){return encodeURIComponent(t.trim().replace(/\s+/g," ")).replace(/-/g,"%2D")}function Kt(t){const d=t.highlight||t.snippet;return`page=${t.pageNumber}&view=FitH,${t.top}&navpanes=0:~:text=${Ot(d)}`}function Ut(t,d){return t.includes("pdf")||d.toLowerCase().endsWith(".pdf")}function Bt(t,d){return t.startsWith("image/")?!0:/\.(png|jpe?g|gif|webp|heic)$/i.test(d)}function Ht(t,d){return t.startsWith("text/")&&!t.includes("csv")?!0:/\.txt$/i.test(d)}function Wt(t,d){const i=t.toLowerCase();return i.includes("spreadsheet")||i.includes("excel")||i.includes("csv")?!0:/\.(csv|xlsx?)$/i.test(d)}function _t({url:t,title:d}){const{t:i}=Pe("salesTaxPeriod"),[x,o]=c.useState(""),[h,f]=c.useState(""),[p,y]=c.useState(null),[w,k]=c.useState(!1),[M,S]=c.useState(!1),[T,P]=c.useState(0),A=c.useRef(!1),I=c.useRef(t);I.current=t,c.useEffect(()=>{o(""),f(""),y(null),S(!1),P(0),A.current=!1},[t]);const u=c.useMemo(()=>p&&h?$t(p,h):[],[p,h]),m=u.length>0?u[Math.min(T,u.length-1)]:null,b=m?Kt(m):"view=FitH&navpanes=0";async function O(E){const F=E.trim();if(h===F&&u.length>0){P(ee=>(ee+1)%u.length);return}if(f(F),P(0),!F||p||A.current)return;const V=t;A.current=!0,k(!0),S(!1);try{const ne=await St({url:V}).promise,re=[];for(let K=1;K<=ne.numPages;K++){const G=await ne.getPage(K),ae=G.getViewport({scale:1}),z=(await G.getTextContent()).items.flatMap(B=>!("str"in B)||!B.str?[]:[{str:B.str,y:B.transform[5]??0}]);re.push({pageNumber:K,height:ae.height,runs:z})}await ne.destroy(),I.current===V&&y(re)}catch{I.current===V&&S(!0)}finally{A.current=!1,k(!1)}}let C="";return w?C=i("review.pdfSearchSearching"):M?C=i("review.pdfSearchFailed"):h&&p&&!Ft(p)?C=i("review.pdfSearchEmpty"):h&&p&&u.length===0?C=i("review.pdfSearchNone"):m&&(C=`${i("review.pdfSearchCount",{current:Math.min(T,u.length-1)+1,total:u.length})} · ${i("review.pdfSearchPage",{page:m.pageNumber})}`),e.jsxs("div",{className:"flex h-full min-h-[16rem] flex-col",children:[e.jsxs("form",{className:"flex shrink-0 items-center gap-1 border-b bg-background px-2 py-1",onSubmit:E=>{E.preventDefault(),O(x)},children:[e.jsx(Nt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground","aria-hidden":!0}),e.jsx("input",{value:x,onChange:E=>o(E.target.value),onKeyDown:E=>
1{E.key==="Enter"&&E.shiftKey&&u.length>0&&x.trim()===h&&(E.preventDefault(),P(F=>(F-1+u.length)%u.length))},placeholder:i("review.pdfSearchPlaceholder"),"aria-label":i("review.pdfSearch"),className:"h-7 min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"}),C?e.jsx("span",{className:"max-w-[9rem] shrink-0 truncate text-xs text-muted-foreground sm:max-w-[14rem]",title:(m==null?void 0:m.snippet)||C,"aria-live":"polite",children:C}):null,e.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded hover:bg-muted disabled:opacity-40","aria-label":i("review.pdfSearchPrev"),disabled:u.length===0,onClick:()=>P(E=>(E-1+u.length)%u.length),children:e.jsx(wt,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded hover:bg-muted disabled:opacity-40","aria-label":i("review.pdfSearchNext"),disabled:u.length===0,onClick:()=>P(E=>(E+1)%u.length),children:e.jsx(kt,{className:"h-4 w-4"})})]}),m!=null&&m.snippet?e.jsx("p",{className:"shrink-0 truncate border-b px-2 py-0.5 text-[11px] text-muted-foreground",children:m.snippet}):null,e.jsx("iframe",{title:d,src:`${t}#${b}`,className:"min-h-0 w-full flex-1 border-0 bg-muted"},b)]})}function zt({sheets:t,fileName:d}){const[i,x]=c.useState(0),o=t[Math.min(i,t.length-1)];if(!o)return null;const h=Math.max(1,...o.rows.map(f=>f.length));return e.jsxs("div",{className:"flex h-full min-h-[16rem] flex-col bg-background",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1 border-b px-2 py-1.5 shrink-0",children:[t.map((f,p)=>e.jsx("button",{type:"button",className:`rounded px-2 py-0.5 text-xs ${p===i?"bg-muted font-medium":"text-muted-foreground hover:bg-muted/60"}`,onClick:()=>x(p),children:f.name},f.name)),o.truncated&&e.jsxs("span",{className:"ml-auto text-[11px] text-muted-foreground",children:["First ",o.rows.length.toLocaleString()," of ",o.totalRows.toLocaleString()," rows"]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("table",{className:"w-max min-w-full text-xs",children:e.jsx("tbody",{children:o.rows.map((f,p)=>e.jsx("tr",{className:p===0?"sticky top-0 bg-muted z-10":"border-b",children:Array.from({length:h},(y,w)=>e.jsx("td",{className:`px-2 py-1 whitespace-nowrap max-w-[14rem] truncate ${p===0?"font-medium":"tabular-nums"}`,title:f[w]||"",children:f[w]||""},w))},p))})})}),e.jsx("p",{className:"shrink-0 border-t px-2 py-1 text-[11px] text-muted-foreground",children:d})]})}function qt({documentId:t,mimeType:d,fileName:i}){const x=d||"",o=i||"",[h,f]=c.useState(null),[p,y]=c.useState(null),[w,k]=c.useState(null),[M,S]=c.useState(null),[T,P]=c.useState(!0);return c.useEffect(()=>{let A=!1,I=null;return P(!0),S(null),y(null),f(null),k(null),(async()=>{try{if(Wt(x,o)){const b=await Q.getSpreadsheetPreview(t);A||k(b.sheets);return}const u=await Q.downloadDocumentBlob(t,!0);if(A)return;const m=new Blob([u],{type:x||u.type||"application/octet-stream"});Ht(x,o)?y(await m.text()):(I=URL.createObjectURL(m),f(I))}catch{A||S("Could not load this file")}finally{A||P(!1)}})(),()=>{A=!0,I&&URL.revokeObjectURL(I)}},[t,x,o]),T?e.jsx("div",{className:"flex h-full min-h-[16rem] items-center justify-center text-sm text-muted-foreground",children:"Loading original file…"}):M?e.jsx("div",{className:"flex h-full min-h-[16rem] items-center justify-center text-sm text-destructive",children:M}):w&&w.length>0?e.jsx(zt,{sheets:w,fileName:o}):p!=null?e.jsx("pre",{className:"h-full overflow-auto p-3 text-xs leading-5 whitespace-pre-wrap font-mono",children:p}):h&&Ut(x,o)?e.jsx(_t,{url:h,title:o||"Original statement"}):h&&Bt(x,o)?e.jsx("div",{className:"h-full overflow-auto bg-muted",children:e.jsx("img",{src:h,alt:o||"Original statement",className:"mx-auto max-w-full"})}):h?e.jsxs("div",{className:"flex h-full min-h-[16rem] flex-col items-center justify-center gap-2 p-4 text-sm",children:[e.jsx("p",{className:"text-muted-foreground text-center",children:"Preview isn’t available for this file type. Open the original instead."}),e.jsxs("a",{href:h,download:o||"statement",className:"underline",children:["Download ",o||"file"]})]}):null}const et="sales-tax-review-split",tt=.28,st=.72,de=.52;function Ke(t){return Math.min(st,Math.max(tt,t))}function Qt(){try{const t=window.localStorage.getItem(et),d=t?Number(t):de;return Number.isFinite(d)?Ke(d):de}catch{return de}}function Vt(){const[t,d]=c.useState(()=>typeof window<"u"?window.matchMedia("(min-width: 1024px)").matches:!0);return c.useEffect(()=>{const i=window.matchMedia("(min-width: 1024px)"),x=()=>d(i.matches);return i.addEventListener("change",x),()=>i.removeEventListener("change",x)},[]),t}function Gt({enabled:t,showLeft:d,showRight:i,left:x,right:o}){const h=Vt(),f=c.useRef(null),p=c.useRef(de),[y,w]=c.useState(de),[k,M]=c.useState(!1);c.useEffect(()=>{const m=Qt();p.current=m,w(m)},[]);const S=c.useCallback(m=>{try{window.localStorage.setItem(et,String(m))}catch{}},[]),T=c.useCallback(m=>{const b=f.current;if(!b)return;const O=b.getBoundingClientRect();if(O.width<1)return;const C=Ke((m-O.left)/O.width);p.current=C,w(C)},[]),P=m=>{m.preventDefault(),m.currentTarget.setPointerCapture(m.pointerId),M(!0),T(m.clientX)},A=m=>{k&&T(m.clientX)},I=m=>{if(k){M(!1);try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}S(p.current)}},u=m=>{if(m.key==="ArrowLeft"||m.key==="ArrowRight"){m.preventDefault();const b=Ke(p.current+(m.key==="ArrowLeft"?-.03:.03));p.current=b,w(b),S(b)}(m.key==="Enter"||m.key==="Home")&&(m.preventDefault(),p.current=de,w(de),S(de))};return t?e.jsxs("div",{ref:f,className:J("flex-1 min-h-0 flex flex-col lg:flex-row",k&&"select-none"),children:[e.jsx("div",{className:J("min-h-0 min-w-0 flex-col overflow-hidden border-b lg:border-b-0 bg-card",d?"flex flex-1":"hidden","lg:flex"),style:h?{flex:`0 0 ${y*100}%`}:void 0,children:e.jsx("div",{className:J("h-full min-h-0 flex flex-col",k&&"pointer-events-none"),children:x})}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize original and extracted panels","aria-valuemin":Math.round(tt*100),"aria-valuemax":Math.round(st*100),"aria-valuenow":Math.round(y*100),tabIndex:0,onPointerDown:P,onPointerMove:A,onPointerUp:I,onPointerCancel:I,onDoubleClick:()=>{p.current=de,w(de),S(de)},onKeyDown:u,className:J("hidden lg:flex w-2 shrink-0 cursor-col-resize items-center justify-center bg-border hover:bg-primary/40 focu
1s-visible:bg-primary/40 focus-visible:outline-none",k&&"bg-primary/50"),title:"Drag to resize. Double-click to reset.",children:e.jsx("span",{className:"h-8 w-0.5 rounded-full bg-muted-foreground/50"})}),e.jsx("div",{className:J("min-h-0 min-w-0 space-y-4 overflow-y-auto p-3 md:p-4",i?"block flex-1":"hidden","lg:block lg:flex-1",k&&"pointer-events-none"),children:o})]}):e.jsx("div",{className:"space-y-6",children:o})}function ye(t){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(t/100)}function Xe(t){return((t??0)/100).toFixed(2)}function Xt(t){const d=Number.parseFloat(t);return Number.isFinite(d)?Math.max(0,Math.round(d*100)):0}function Yt(t,d,i,x){const o=x>0&&x<=t;return Math.max(0,t-d-i-(o?x:0))}function Zt(t,d){return t<=0||d<=0?null:t/d*100}function Jt(t){const d=(t||"").toLowerCase();return d.includes("chowbus")?"chowbus":d.includes("grubhub")||d.includes("seamless")?"grubhub":d.includes("fantuan")?"fantuan":d.includes("uber")?"ubereats":"other"}const es={discounts:["discounts","refundsAndAdjustments"],refunds:["refunds","refundsAndAdjustments"],loyaltyCredits:["loyaltyCredits","refundsAndAdjustments"],refundsAndAdjustments:["refundsAndAdjustments"],taxableWithTax:["taxableWithTax","netTaxableSales"],grossSalesWithTax:["grossSalesWithTax","grossSales"],netTaxDue:["netTaxDue","taxCollected"]};function Ye(t,d){if(d)for(const i of[t,...es[t]||[]]){const x=d[i];if(typeof x=="number"&&Number.isFinite(x))return x}}function Fe(t){return t>=.9?"high":t>=.7?"mid":"low"}const ts=[{key:"grossSales",label:"Gross sales (pretax)",always:!0},{key:"grossSalesWithTax",label:"Gross with tax"},{key:"discounts",label:"Discounts",negative:!0},{key:"refunds",label:"Refunds",negative:!0},{key:"loyaltyCredits",label:"Loyalty credits",negative:!0},{key:"refundsAndAdjustments",label:"Refunds / adjustments",negative:!0},{key:"nontaxableSales",label:"Nontaxable sales",always:!0},{key:"excludedPlatformSales",label:"Marketplace sales on POS"},{key:"netTaxableSales",label:"Taxable sales (pretax)",always:!0,strong:!0},{key:"taxableWithTax",label:"Taxable with tax",always:!0},{key:"taxCollected",label:"Tax collected",always:!0},{key:"taxRefunded",label:"Tax refunded",negative:!0},{key:"netTaxDue",label:"Net tax due",always:!0,strong:!0},{key:"tips",label:"Tips"},{key:"platformFees",label:"Platform fees",negative:!0},{key:"netPayout",label:"Net payout"}];function Ze({mathKey:t,math:d,openKey:i,onToggle:x,t:o}){if(!d)return null;const h=i===t;return e.jsxs("div",{className:"mt-0.5",children:[e.jsx("button",{type:"button",className:"text-[11px] underline text-muted-foreground hover:text-foreground",onClick:()=>x(h?null:t),children:o(h?"review.hideMath":"review.showMath")}),h?e.jsx("div",{className:"text-[11px] leading-4 mt-0.5 tabular-nums",children:d.captionKey==="mathManual"?o("review.mathManual"):`${o(`review.${d.captionKey}`)} ${d.expression} = ${d.result}`}):null]})}function ss({value:t,onCommit:d,onCancel:i,disabled:x}){const[o,h]=c.useState(Xe(t));c.useEffect(()=>{h(Xe(t))},[t]);const f=()=>{const p=Xt(o);if(p===t){i();return}d(p)};return e.jsxs("span",{className:"inline-flex items-center gap-1 justify-end",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"$"}),e.jsx("input",{type:"number",inputMode:"decimal",step:"0.01",min:"0",value:o,disabled:x,autoFocus:!0,"aria-label":"Corrected amount in dollars",className:"w-[7.5rem] rounded-md border bg-background px-1.5 py-1 text-right text-sm tabular-nums",onChange:p=>h(p.target.value),onBlur:f,onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),p.target.blur()),p.key==="Escape"&&(p.preventDefault(),i())}})]})}function ns({summary:t,original:d,canEdit:i,isSaving:x,lockedReason:o,districtRatePercent:h,platformRemits:f,isPlatformStatement:p,taxDueHint:y,channelName:w,fieldConfidence:k,overallConfidence:M,restaurantName:S,identityFlags:T,onSave:P,onConfirmIdentity:A,confirmIdentityPending:I}){const{t:u}=Pe("salesTaxPeriod"),m=Jt(w),b=r=>{var g;return r==="grossSales"?u(m==="fantuan"?"review.grossHintFantuan":m==="chowbus"?"review.grossHintChowbus":m==="grubhub"?"review.grossHintGrubhub":"review.grossHint"):r==="grossSalesWithTax"&&m==="grubhub"?u("review.grossWithTaxHintGrubhub"):r==="nontaxableSales"?u(m==="chowbus"?"review.nontaxableHintChowbus":"review.nontaxableHint"):r==="excludedPlatformSales"?u("review.excludedHint"):r==="taxableWithTax"?u("review.taxableWithTaxHint"):r==="netTaxableSales"&&((g=t.manualFields)!=null&&g.includes("netTaxableSales"))?u("review.taxableManualHint"):r==="netTaxableSales"&&m==="fantuan"?u("review.taxableHintFantuan"):r==="netTaxableSales"&&m==="grubhub"?u("review.taxableHintGrubhub"):null},[O,C]=c.useState(null),[E,F]=c.useState(null),V={districtRatePercent:h??null,platformRemits:f},ee=(r,g)=>
1{const N={[r]:g},j=r==="discounts"?g:t.discounts||0,ue=r==="refunds"?g:t.refunds||0,s=r==="loyaltyCredits"?g:t.loyaltyCredits||0;if((r==="discounts"||r==="refunds"||r==="loyaltyCredits")&&(N.refundsAndAdjustments=j+ue+s),["grossSales","discounts","refunds","loyaltyCredits","refundsAndAdjustments","nontaxableSales","excludedPlatformSales"].includes(r)){const U=r==="grossSales"?g:t.grossSales||0;if(m==="grubhub"&&t.grossIncludesTax)N.netTaxableSales=U,N.taxableWithTax=U+(t.taxCollected||0);else{const q=N.refundsAndAdjustments??t.refundsAndAdjustments??j+ue+s,he=r==="nontaxableSales"?g:t.nontaxableSales||0,ie=r==="excludedPlatformSales"?g:t.excludedPlatformSales||0,pe=Yt(U,q,he,ie);N.netTaxableSales=pe,N.taxableWithTax=pe+(t.taxCollected||0)}}else r==="taxCollected"?(N.netTaxDue=Math.max(0,g-(t.taxRefunded||0)),N.taxableWithTax=(t.netTaxableSales||0)+g):r==="taxRefunded"?N.netTaxDue=Math.max(0,(t.taxCollected||0)-g):r==="netTaxableSales"&&(N.taxableWithTax=g+(t.taxCollected||0));C(null),P(N)},ne=r=>{r<=0||ee("nontaxableSales",(t.nontaxableSales||0)+r)},re=(t.discounts||0)+(t.refunds||0)+(t.loyaltyCredits||0),K=ts.filter(r=>{if(r.key==="refundsAndAdjustments"&&re>0)return!1;if(r.key==="grossSalesWithTax"){const g=t.grossSalesWithTax||0;return t.grossIncludesTax===!0&&g>0&&g!==(t.grossSales||0)}return r.always||t[r.key]!=null&&t[r.key]!==0}),G=(t.revenueLines||[]).filter(r=>r.collected),ae=(t.categoryLines||[]).filter(r=>r.sales),le=ae.find(r=>/frozen\s*dumpling/i.test(r.name)),z=p||(t.platformFees||0)>0?pt({pretaxSalesCents:t.grossSales||0,netPayoutCents:t.netPayout||0,taxCents:t.netTaxDue||t.taxCollected||0,tipsCents:t.tips||0,platformRemits:f===!0}):null,B=K.map(r=>{const g=Ye(r.key,k);return g==null||Fe(g)==="high"?null:{key:r.key,label:r.label,conf:g}}).filter(r=>r!=null).sort((r,g)=>r.conf-g.conf),me=T||[];return e.jsxs("div",{className:"space-y-3",children:[me.map(r=>{const g=gt(r,u),N=g.tone==="flag"?"border-red-200 bg-red-50 text-red-950 dark:border-red-900 dark:bg-red-950/40 dark:text-red-100":"border-amber-200 bg-amber-50 text-amber-950 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-100";return e.jsxs("div",{className:`rounded-lg border px-3 py-2 text-sm ${N}`,children:[e.jsx("p",{className:"font-medium",children:g.title}),g.body?e.jsx("p",{className:"text-xs mt-0.5 leading-4",children:g.body}):null,A&&(r.code==="RESTAURANT_NAME_MISMATCH"||r.code==="WRONG_LOCATION")?e.jsx("button",{type:"button",className:"mt-2 rounded-md border border-current/20 bg-white/70 px-2.5 py-1 text-xs font-medium hover:bg-white disabled:opacity-60 dark:bg-black/20 dark:hover:bg-black/40",disabled:I||!i,onClick:A,children:u(I?"review.confirmingRestaurant":"review.confirmThisRestaurant")}):null]},r.code)}),S&&!me.some(r=>r.code==="RESTAURANT_NAME_MISMATCH"||r.code==="WRONG_LOCATION")?e.jsx("p",{className:"text-xs text-muted-foreground",children:u("review.restaurantOnStatement",{name:S})}):null,e.jsx(bt,{taxableCents:t.netTaxableSales||0,collectedTaxCents:t.netTaxDue||t.taxCollected||0,districtRatePercent:h,platformRemits:f}),(t.excludedPlatformSales||0)>0&&e.jsxs("div",{className:"rounded-lg border border-sky-200 bg-sky-50 px-3 py-2 text-sm text-sky-950 dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-100",children:[e.jsx("p",{className:"font-medium",children:u("review.marketplacePassThroughTitle")}),e.jsx("p",{className:"text-xs mt-0.5 leading-4",children:(t.grossSales||0)<=0?u("review.marketplacePassThroughZero"):u("review.marketplacePassThrough")})]}),e.jsxs("div",{className:"rounded-lg border bg-card overflow-hidden",children:[e.jsxs("div",{className:"border-b px-3 py-2 bg-muted/30",children:[e.jsx("h2",{className:"font-semibold text-sm",children:u("review.extractedTitle")}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[h?`${u("review.districtRate",{rate:h.toFixed(3).replace(/\.?0+$/,"")})} · `:t.taxRate?`Extracted rate ${(t.taxRate*100).toFixed(4).replace(/\.?0+$/,"")}% · `:"",M!=null?`${u("review.aiConfidence",{pct:Math.round(M*100)})} · `:"",i?u("review.clickToCorrect"):o||"Compare each figure with the original file",t.grossIncludesTax?" · Printed sales total included tax; pretax is stored separately.":""]})]}),B.length>0&&e.jsxs("div",{className:J("px-3 py-2 text-xs border-b",B.some(r=>
1Fe(r.conf)==="low")?"bg-rose-50 text-rose-950 dark:bg-rose-950/40 dark:text-rose-100":"bg-amber-50 text-amber-950 dark:bg-amber-950/40 dark:text-amber-100"),children:[e.jsx("p",{className:"font-medium",children:u("review.aiLookAt")}),e.jsx("ul",{className:"mt-1 flex flex-wrap gap-x-3 gap-y-0.5",children:B.map(r=>e.jsx("li",{children:u("review.aiFieldPct",{label:r.label,pct:Math.round(r.conf*100)})},r.key))})]}),e.jsx("table",{className:"w-full text-sm",children:e.jsxs("tbody",{children:[K.map(r=>{const g=t[r.key]??0,N=d==null?void 0:d[r.key],j=N!=null&&N!==g&&d!=null,ue=O===r.key,s=r.key==="platformFees"?Zt(g,t.grossSales||0):null,X=b(r.key),U=Ye(r.key,k),q=U!=null?Fe(U):null;return e.jsxs("tr",{className:J("border-b last:border-0",r.strong&&"bg-indigo-50 dark:bg-indigo-950"),children:[e.jsxs("td",{className:"px-3 py-1.5 text-muted-foreground",children:[r.label,X?e.jsx("div",{className:"text-[11px] leading-4 mt-0.5",children:X}):null,e.jsx(Ze,{mathKey:r.key,math:Qe(r.key,t,V),openKey:E,onToggle:F,t:u}),j?e.jsx("div",{className:"text-[11px] text-amber-800 mt-0.5",children:u("review.was",{amount:ye(N??0)})}):null]}),e.jsxs("td",{className:J("px-3 py-1.5 text-right tabular-nums whitespace-nowrap",r.strong?"font-bold text-indigo-800 dark:text-indigo-300":"font-medium",r.negative&&!ue&&"text-red-600"),children:[ue?e.jsx(ss,{value:g,disabled:x,onCommit:he=>ee(r.key,he),onCancel:()=>C(null)}):i?e.jsxs("button",{type:"button",className:"rounded px-1 -mx-1 hover:bg-muted/80 hover:ring-1 hover:ring-border",title:"Click to correct this figure",onClick:()=>C(r.key),children:[r.negative&&g>0?"−":"",ye(g)]}):e.jsxs(e.Fragment,{children:[r.negative&&g>0?"−":"",ye(g)]}),s!=null&&e.jsx("div",{className:"text-[11px] font-normal text-muted-foreground mt-0.5",children:u("review.platformFeePct",{pct:s.toFixed(1)})}),r.key==="nontaxableSales"&&le&&le.sales===g&&e.jsx("div",{className:"text-[11px] font-normal text-muted-foreground mt-0.5",children:u("review.nontaxableFromFrozen")}),r.key==="netTaxDue"&&y?e.jsx("div",{className:"text-[11px] font-normal text-muted-foreground mt-0.5",children:y}):null,q&&q!=="high"&&U!=null&&e.jsx("div",{className:J("text-[11px] font-medium mt-0.5",q==="low"?"text-rose-700 dark:text-rose-300":"text-amber-800 dark:text-amber-300"),children:u("review.aiFieldNeedsCheck",{pct:Math.round(U*100)})})]})]},r.key)}),z&&e.jsxs("tr",{className:"bg-amber-50 dark:bg-amber-950/40",children:[e.jsxs("td",{className:"px-3 py-1.5 text-muted-foreground",children:[u("review.effectiveTake"),e.jsx("div",{className:"text-[11px] leading-4 mt-0.5",children:u(f?"review.effectiveTakeHintPlatformRemits":"review.effectiveTakeHint")}),e.jsx(Ze,{mathKey:"effectiveTake",math:Qe("effectiveTake",t,V),openKey:E,onToggle:F,t:u})]}),e.jsxs("td",{className:"px-3 py-1.5 text-right tabular-nums font-bold text-amber-900 dark:text-amber-200",children:[e.jsx("div",{className:"whitespace-nowrap",children:u("review.effectiveTakeValue",{pct:Ve(z.takePercent)})}),e.jsx("div",{className:"text-[11px] font-normal text-muted-foreground mt-0.5 leading-4",children:u("review.effectiveKeep",{amount:ye(z.keepCents),pct:Ve(z.keepPercent)})})]})]})]})}),G.length>0&&e.jsxs("div",{className:"border-t px-3 py-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"How customers paid"}),e.jsx("dl",{className:"grid grid-cols-2 gap-x-3 gap-y-0.5 text-sm",children:G.map(r=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:r.name}),e.jsx("dd",{className:"tabular-nums text-right",children:ye(r.collected)})]},r.name))})]}),ae.length>0&&e.jsxs("div",{className:"border-t px-3 py-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Sales by category"}),m==="chowbus"?e.jsx("p",{className:"text-[11px] text-muted-foreground mb-1",children:u("review.nontaxableHintChowbus")}):null,e.jsx("ul",{className:"space-y-0.5 text-sm",children:ae.map(r=>{const g=/frozen\s*dumpling/i.test(r.name),N=g&&r.sales===(t.nontaxableSales||0);return e.jsxs("li",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-muted-foreground min-w-0 truncate",children:[r.name,g?" · tax-exempt":""]}),e.jsxs("span",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"tabular-nums",children:ye(r.sales)}),i&&g&&N&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Used as nontaxable"}),i&&!(g&&N)&&e.jsx("button",{type:"button",className:"text-[11px] underline text-muted-foreground hover:text-foreground",onClick:()=>g?ee("nontaxableSales",r.sales):ne(r.sales),children:g?"Use as nontaxable":"Add to nontaxable"})]})]},r.name)})})]})]})]})}const rs=["Revenue / Sales Deposit","Payroll & Wages","Rent & Lease","Utilities","Insurance","Cost of Goods Sold","Equipment & Tools","Vehicle & Transportation","Professional Services","Marketing & Advertising","Office Supplies","Repairs & Maintenance","Subscriptions & Software","Bank Fees & Interest","Merchant Processing Fees","Taxes & Licenses","Meals & Entertainment","Travel","Loan Payment","Owner Draw / Distribution","Transfer","Other"],nt={INCOME:"Income",EXPENSE:"Expense",TAX_COLLECTED:"Tax Collected",TAX_PAID:"Tax Paid",REFUND:"Refund",TRANSFER:"Transfer",FEE:"Fee"},as={INCOME:"text-green-600",EXPENSE:"text-red-600",TAX_COLLECTED:"text-blue-600",TAX_PAID:"text-orange-600",REFUND:"text-purple-600",TRANSFER:"text-gray-600",FEE:"text-yellow-600"};function _(t){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(t/100)}function Je(t){const d=t.resolvedRemittanceMode??t.confirmedRemittanceMode;return d==="PLATFORM"||d==="MERCHANT"?d:t.confirmedPlatformRemitsTax===!0?"PLATFORM":t.confirmedPlatformRemitsTax===!1?"MERCHANT":""}function $e(t){return t.type==="POS_REPORT"||t.type==="DELIVERY_PLATFORM"||!!t.salesChannelId}function je(t,d="UTC"){return mt(t,d)}function Os(){var He,We,_e,ze,qe;const{t}=Pe("salesTaxPeriod"),{t:d}=Pe("financialDocuments"),{id:i}=Ct(),[x]=Tt(),o=ot(),{currentOrganizationId:h}=xt(),{hasPermission:f}=ft(),p=f("APPROVE_FINANCIAL_DOCUMENTS"),y=x.get("from")==="sales-tax",w=x.get("from")==="books",k=x.get("from")==="statements",M=x.get("year"),S=x.get("month"),[T,P]=c.useState(null),[A,I]=c.useState(""),[u,m]=c.useState(!1),[b,O]=c.useState(!1),[C,E]=c.useState(""),[F,V]=c.useState(""),[ee,ne]=c.useState(null),[re,K]=c.useState("extracted"),[G,ae]=c.useState(""),[le,z]=c.useState(null),[B,me]=c.useState(null),[r,g]=c.useState(0),N=c.useRef(!1),j=c.useRef(null),ue=c.useRef(""),{data:s,isLoading:X}=ct({queryKey:["financial-document",h,i],queryFn:()=>Q.getDocument(i),enabled:!!i,refetchInterval:n=>{var L;const v=(L=n.state.data)==null?void 0:L.status;return v==="PENDING"||v==="PROCESSING"?2e3:!1}}),U=ve({mutationFn:n=>Q.updateTransaction(n.id,n.updates),onSuccess:()=>{o.resetQueries({queryKey:["financial-document",h,i]}),P(null)}}),q=ve({mutationFn:async()=>
1{if(!!s&&$e(s)){if(F!=="PLATFORM"&&F!=="MERCHANT")throw new Error(t("review.chooseRemit"));await Q.confirmRemittance(i,{remittanceMode:F,platformRemitsTax:F==="PLATFORM",applyToChannel:!!(s!=null&&s.salesChannelId)})}return Q.approveDocument(i,A)},onSuccess:()=>{o.resetQueries({queryKey:["financial-document",h,i]}),o.invalidateQueries({queryKey:["financial-documents"]}),o.invalidateQueries({queryKey:["books-statements"]}),o.invalidateQueries({queryKey:["sales-tax-period"]}),o.invalidateQueries({queryKey:["month-close"]}),m(!1),te.success(t("review.approved"))},onError:n=>{te.error(Te(n,t("review.couldNotApprove")))}}),he=ve({mutationFn:()=>Q.bulkVerifyTransactions(i),onSuccess:()=>{o.resetQueries({queryKey:["financial-document",h,i]})}}),ie=ve({mutationFn:n=>Q.reprocessDocument(i,n),onSuccess:()=>{N.current=!0,o.resetQueries({queryKey:["financial-document",h,i]}),o.invalidateQueries({queryKey:["financial-documents"]}),o.invalidateQueries({queryKey:["books-statements"]}),o.invalidateQueries({queryKey:["sales-tax-period"]}),o.invalidateQueries({queryKey:["month-close"]}),O(!1),E(""),te.message(t("review.reprocessStarted"))},onError:n=>{N.current=!1,te.error(Te(n,t("review.reprocessFailed")))}});c.useEffect(()=>{!N.current||!s||(s.status==="NEEDS_REVIEW"?(N.current=!1,o.invalidateQueries({queryKey:["sales-tax-period"]}),o.invalidateQueries({queryKey:["month-close"]}),o.invalidateQueries({queryKey:["financial-documents"]}),o.invalidateQueries({queryKey:["books-statements"]}),te.success(t("review.reprocessed"))):s.status==="FAILED"&&(N.current=!1,te.error(s.processingError||t("review.reprocessFailed"))))},[s,o,t]);const pe=ve({mutationFn:()=>Q.confirmStatementIdentity(i),onSuccess:()=>{o.invalidateQueries({queryKey:["financial-document",h,i]}),o.invalidateQueries({queryKey:["sales-tax-period"]}),o.invalidateQueries({queryKey:["month-close"]}),te.success(t("review.restaurantConfirmed"))},onError:n=>{te.error(Te(n,t("review.couldNotConfirmRestaurant")))}}),Se=ve({mutationFn:n=>Q.updateExtractedData(i,{summary:n}),onSuccess:()=>{o.invalidateQueries({queryKey:["financial-document",h,i]}),o.invalidateQueries({queryKey:["sales-tax-period"]}),o.invalidateQueries({queryKey:["month-close"]}),o.invalidateQueries({queryKey:["financial-documents"]}),o.invalidateQueries({queryKey:["books-statements"]}),te.success(t("review.savedCorrection"))},onError:n=>{te.error(Te(n,t("review.couldNotSaveCorrection")))}}),H=dt();c.useEffect(()=>{if(!i||(s==null?void 0:s.type)!=="BANK_STATEMENT"||s.status==="PENDING"||s.status==="PROCESSING")return;const n=s.processedAt?new Date(s.processedAt).getTime():0,v=Date.now()-n<120*1e3?8e3:0;H.watch(i,v)},[i,s==null?void 0:s.type,s==null?void 0:s.status,s==null?void 0:s.processedAt,H.watch]);const $=(s==null?void 0:s.transactions)||[],Ne=c.useMemo(()=>$.filter(n=>Et(n,G)),[$,G]),be=c.useCallback(n=>{K("extracted"),g(L=>L+1);const v=Mt($,n);if(!v){ae(n.checkNumber),z(null),me(n.checkNumber);return}ae(""),me(null),z(v.id)},[$]),Ee=$.map(n=>`${n.id}:${n.checkNumber??""}`).join("|"),we=`${i||""}:${x.get("txn")||""}:${x.get("check")||""}:${Ee}`;c.useEffect(()=>{const n=x.get("check"),v=x.get("txn");!s||!n&&!v||ue.current===we||(ue.current=we,be({checkNumber:n||"",transactionId:v||void 0}))},[s,be,we,x]),c.useEffect(()=>{var n,v;if(r!==0){if(B){(n=j.current)==null||n.scrollIntoView({behavior:"smooth",block:"start"});return}le&&((v=window.document.getElementById(`extracted-txn-${le}`))==null||v.scrollIntoView({behavior:"smooth",block:"center"}))}},[r,le,B]);const Ce=$.reduce((n,v)=>n+v.amount,0),a=s==null?void 0:s.extractedData,l=(a==null?void 0:a.summary)||(s==null?void 0:s.extractedData),D=a==null?void 0:a.fieldConfidence,W=s==null?void 0:s.originalExtraction,R=(W==null?void 0:W.summary)||(s==null?void 0:s.originalExtraction),Y=l&&(l.grossSales||l.netTaxableSales||l.taxCollected||l.excludedPlatformSales||l.netPayout),oe=!!s&&p&&!s.isLocked&&(s.status==="NEEDS_REVIEW"||s.status==="APPROVED"),fe=s!=null&&s.isLocked?"This statement is locked. Unlock it to correct figures.":null,ge=(s==null?void 0:s.type)==="BANK_STATEMENT"||(s==null?void 0:s.type)==="CREDIT_CARD_STATE
1MENT",Re=(s==null?void 0:s.type)==="BANK_STATEMENT",rt=y&&M&&S?`/dashboard/sales-tax/${M}/${S}`:w||k||ge?"/dashboard/statements?tab=bank":"/dashboard/financial-documents",at=ge&&l&&(l.beginningBalance!=null||l.totalDeposits!=null||l.previousBalance!=null),Ue=$.filter(n=>!n.verified).length,lt=/check\s*#?\s*\d+/i,Me=$.filter(n=>lt.test(n.description)),Be=Me.filter(n=>!n.checkPayee),it=Re&&Me.length>0,Z=(s==null?void 0:s.type)==="POS_REPORT"||(s==null?void 0:s.type)==="DELIVERY_PLATFORM"||y||ge,ke=c.useMemo(()=>{if(!ge||$.length===0)return[];const n=new Map;for(const v of $){const L=v.category||"Other",ce=n.get(L)||{amount:0,count:0};ce.amount+=Math.abs(v.amount),ce.count++,n.set(L,ce)}return Array.from(n.entries()).map(([v,L])=>({category:v,...L})).sort((v,L)=>L.amount-v.amount)},[ge,$]);return X?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading document..."})}):s?e.jsxs("div",{className:Z?"flex flex-col -mx-4 md:-mx-8 -my-3 md:-my-8 h-[calc(100dvh-4rem)] min-h-0":"space-y-4 -mx-4 md:-mx-8 px-3 md:px-4",children:[e.jsxs("div",{className:Z?"shrink-0 border-b bg-background px-3 md:px-4 py-2 space-y-2":"contents",children:[e.jsxs(Pt,{to:rt,className:"inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m15 18-6-6 6-6"})}),t(y?"review.backSalesTax":w||k||ge?"review.backBooks":"review.backDocuments")]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:J("font-bold truncate",Z?"text-lg":"text-2xl"),children:s.displayTitle||s.originalName}),e.jsxs("p",{className:"text-sm text-muted-foreground truncate",children:[s.vendor&&e.jsx("span",{className:"mr-2",children:s.vendor}),s.status==="NEEDS_REVIEW"?`· ${t("review.reviewAndApprove")}`:s.status==="PENDING"||s.status==="PROCESSING"?`· ${t("review.reading")}`:`· ${s.status}`,s.periodStart&&s.periodEnd?` · ${je(s.periodStart)} – ${je(s.periodEnd)}`:"",s.confidenceScore!=null?` · ${t("review.aiConfidence",{pct:Math.round(s.confidenceScore*100)})}`:""]})]}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2 shrink-0",children:[s.type==="CREDIT_CARD_STATEMENT"&&s.promotedCreditCardStatement==null&&e.jsx(yt,{documentId:s.id,size:Z?"sm":"default"}),s.type==="BANK_STATEMENT"&&s.status==="APPROVED"&&s.promotedBankStatement==null&&e.jsx(jt,{documentId:s.id,size:Z?"sm":"default"}),Z&&e.jsxs("div",{className:"flex lg:hidden rounded-md border p-0.5 text-xs",children:[e.jsx("button",{type:"button",className:J("rounded px-2.5 py-1",re==="original"?"bg-muted font-medium":"text-muted-foreground"),onClick:()=>K("original"),children:t("review.original")}),e.jsx("button",{type:"button",className:J("rounded px-2.5 py-1",re==="extracted"?"bg-muted font-medium":"text-muted-foreground"),onClick:()=>K("extracted"),children:t("review.extracted")})]}),e.jsx(se,{variant:"outline",size:Z?"sm":"default",onClick:async()=>{const n=window.open("about:blank","_blank");try{const v=await Q.downloadDocumentBlob(s.id,!0),L=new Blob([v],{type:s.mimeType||v.type||"application/octet-stream"}),ce=URL.createObjectURL(L);if(n)n.location.replace(ce);else{const xe=window.document.createElement("a");xe.href=ce,xe.target="_blank",xe.rel="noopener",window.document.body.appendChild(xe),xe.click(),window.document.body.removeChild(xe)}setTimeout(()=>URL.revokeObjectURL(ce),6e4)}catch(v){n==null||n.close(),console.error("Failed to open file:",v),te.error(t("review.couldNotOpen"))}},children:t(Z?"review.openTab":"review.viewFile")}),(s.status==="FAILED"||s.status==="NEEDS_REVIEW"||s.status==="APPROVED"||s.status==="PENDING"||s.status==="PROCESSING")&&e.jsx(se,{variant:"outline",size:Z?"sm":"default",onClick:()=>{if(s.isLocked){te.error(t("review.unlockToReprocess"));return}s.status==="PENDING"||s.status==="PROCESSING"||O(!0)},disabled:ie.isPending||s.isLocked||s.status==="PENDING"||s.status==="PROCESSING",title:s.isLocked?t("review.unlockToReprocess"):void 0,children:ie.isPending||s.status==="PENDING"||s.status==="PROCESSING"?t("review.reprocessing"):t("review.reprocess")}),it&&e.jsx(se,{variant:"outline",size:Z?"sm":"default",onClick:()=>i&&void H.start(i),disabled:H.running,children:H.running?t("review.analyzingChecks"):Be.length>0?t("review.analyzeChecksCount",{count:Be.length}):t("review.reanalyzeChecks")}),s.status==="NEEDS_REVIEW"&&e.jsx(se,{size:Z?"sm":"default",onClick:()=>{V(Je(s)),m(!0)},children:t("review.approve")})]})]})]}),(s.status==="PENDING"||s.status==="PROCESSING")&&e.jsx("div",{className:"rounded-lg border bg-blue-50 border-blue-200 px-3 py-2 shrink-0 mx-3 md:mx-4 mt-2 text-sm text-blue-900",children:t("review.readingBanner")}),(H.running||H.error||H.result)&&e.jsx("div",{className:"shrink-0 mx-3 md:mx-4 mt-2",children:e.jsx(ut,{running:H.running,progress:H.progress,result:H.result,error:H.error,elapsed:H.elapsed,onSelectCheck:be})}),e.jsx(Gt,{enabled:Z,showLeft:re==="original",showRight:re==="extracted",left:e.jsxs("div",{className:"h-full min-h-0 flex flex-col",children:[e.jsx("div",{className:"border-b px-3 py-1.5 text-xs font-medium uppercase tracking-wide text-muted-foreground bg-muted/30 shrink-0",children:t("review.original")}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(qt,{documentId:s.id,mimeType:s.mimeType,fileName:s.originalName})})]}),right:e.jsxs("div",{className:"space-y-4 min-w-0",children:[!Z&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Status"}),e.jsx("p",{className:"font-semibold",children:s.status})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Period"}),e.jsx("p",{className:"font-semibold",children:s.periodStart&&s.periodEnd?`${je(s.peri
1odStart)} - ${je(s.periodEnd)}`:"Not detected"})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Document Type"}),e.jsx("p",{className:"font-semibold",children:s.type.replace(/_/g," ")})]})]}),Y&&l&&e.jsx(ns,{summary:l,original:R,canEdit:oe,isSaving:Se.isPending,lockedReason:fe,districtRatePercent:(He=s.districtRate)==null?void 0:He.ratePercent,platformRemits:Je(s)==="PLATFORM",isPlatformStatement:s.type==="DELIVERY_PLATFORM"||!!s.salesChannelId&&s.type!=="POS_REPORT",taxDueHint:/uber\s*eats/i.test(((We=s.salesChannel)==null?void 0:We.name)||s.vendor||"")?t("review.uberFacilitatorTax"):void 0,channelName:((_e=s.salesChannel)==null?void 0:_e.name)||s.vendor,fieldConfidence:D,overallConfidence:s.confidenceScore,restaurantName:(ze=s.extractedData)==null?void 0:ze.restaurantName,identityFlags:s.identityFlags,onSave:n=>Se.mutate(n),onConfirmIdentity:()=>pe.mutate(),confirmIdentityPending:pe.isPending}),!Y&&$.length>0&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Transactions"}),e.jsx("p",{className:"font-semibold",children:$.length})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Net Amount"}),e.jsx("p",{className:`font-semibold ${Ce>=0?"text-green-600":"text-red-600"}`,children:_(Ce)})]})]}),s.processingError&&e.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4",children:[e.jsx("p",{className:"text-sm font-medium text-red-800",children:"Processing Error"}),e.jsx("p",{className:"text-sm text-red-600",children:s.processingError})]}),at&&e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"border-b px-4 py-3 bg-muted/30",children:e.jsx("h2",{className:"font-semibold",children:Re?"Account Summary":"Card Summary"})}),e.jsx("div",{className:"p-4",children:Re?e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-gray-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Beginning Balance"}),e.jsx("p",{className:"text-lg font-bold",children:_((l==null?void 0:l.beginningBalance)||0)})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-green-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Deposits"}),e.jsxs("p",{className:"text-lg font-bold text-green-600",children:["+",_((l==null?void 0:l.totalDeposits)||0)]})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-red-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Withdrawals"}),e.jsxs("p",{className:"text-lg font-bold text-red-600",children:["-",_((l==null?void 0:l.totalWithdrawals)||0)]})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-blue-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ending Balance"}),e.jsx("p",{className:"text-lg font-bold",children:_((l==null?void 0:l.endingBalance)||0)})]})]}):e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-gray-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Previous Balance"}),e.jsx("p",{className:"text-lg font-bold",children:_((l==null?void 0:l.previousBalance)||0)})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-red-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"New Charges"}),e.jsxs("p",{className:"text-lg font-bold text-red-600",children:["+",_((l==null?void 0:l.newCharges)||0)]})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-green-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Payments"}),e.jsxs("p",{className:"text-lg font-bold text-green-600",children:["-",_((l==null?void 0:l.payments)||0)]})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-blue-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"New Balance"}),e.jsx("p",{className:"text-lg font-bold",children:_((l==null?void 0:l.newBalance)||0)})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-green-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Credits"}),e.jsx("p",{className:"text-lg font-bold text-green-600",children:_((l==null?void 0:l.credits)||0)})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-red-50",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fees"}),e.jsx("p",{className:"text-lg font-bold text-red-600",children:_((l==null?void 0:l.fees)||0)})]})]})})]}),$.length>0&&e.jsxs("div",{ref:j,className:"rounded-lg border bg-card",children:[e.jsxs("div",{className:"border-b px-4 py-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"font-semibold",children:["Extracted Transactions (",$.length,")"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Individual line items from this document"})]}),Ue>0&&e.jsx(se,{variant:"outline",size:"sm",onClick:()=>he.mutate(),disabled:he.isPending,children:he.isPending?"Verifying...":`Verify All (${Ue})`})]}),e.jsx("input",{type:"search",value:G,onChange:n=>{ae(n.target.value),me(null)},placeholder:d("checkAnalysis.searchPlaceholder"),"aria-label":d("checkAnalysis.searchPlaceholder"),className:"w-full rounded-md border px-3 py-2 text-sm"}),G.trim()&&e.jsx("p",{className:"text-xs text-muted-foreground",children:d("checkAnalysis.searchCount",{shown:Ne.length,total:$.length})}),B&&e.jsx("p",{className:"text-sm text-amber-800",children:d("checkAnalysis.notOnStatement",{number:B})})]}),e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium",children:"Date"}),e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium",children:"Description"}),e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium",children:"Type"}),e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium",children:"Category"}),e.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium",children:"Amount"}),e.jsx("th",{className:"px-4 py-3 text-center text-sm font-medium",children:"Confidence"}),e.jsx("th",{className:"px-4 py-3 text-center text-sm font-medium",children:"Verified"}),e.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium",children:"Actions"})]})}),e.jsxs("tbody",{children:[Ne.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"px-4 py-6 text-sm text-muted-foreground",children:d("checkAnalysis.searchEmpty",{query:G.trim()})})}),Ne.map(n=>e.jsxs("tr",{id:`extracted-txn-${n.id}`,className:`border-b last:border-0 ${(T==null?void 0:T.id)===n.id?"bg-amber-50":le===n.id?"bg-blue-50":""}`,children:[e.jsx("td",{className:"px-4 py-3 text-sm",children:je(n.date)}),e.jsx("td",{className:"px-4 py-3 text-sm",children:e.jsxs("div",{children:[n.description,n.checkPayee&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:["Payee: ",n.checkPayee]}
1),n.checkNumber&&(()=>{const v=!!n.checkImageStorageKey,L=n.confidence,ce=n.checkPayee?L>=.8?"bg-green-100 text-green-700":L>=.5?"bg-yellow-100 text-yellow-700":"bg-red-100 text-red-700":"bg-gray-100 text-gray-600",xe=n.checkPayee?`Confidence: ${Math.round(L*100)}% — ${n.checkPayee}${v?" (click to view)":""}`:v?"Check image is too faint to read the payee":"Check not yet analyzed";return e.jsxs("button",{type:"button",onClick:()=>v?ne(n.id):void 0,className:`inline-block mt-0.5 text-xs rounded px-1.5 py-0.5 ${ce} ${v?"cursor-pointer hover:opacity-80":"cursor-default"}`,title:xe,children:["Check #",n.checkNumber,n.checkPayee&&L<.8&&e.jsx("span",{className:"ml-1 opacity-75",children:L<.5?"!":"?"})]})})()]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`text-sm font-medium ${as[n.type]}`,children:nt[n.type]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-muted-foreground",children:n.category||"-"}),e.jsx("td",{className:`px-4 py-3 text-right text-sm font-medium ${n.amount>=0?"text-green-600":"text-red-600"}`,children:_(n.amount)}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx("div",{className:"h-2 w-16 rounded-full bg-muted",children:e.jsx("div",{className:`h-full rounded-full ${n.confidence>=.8?"bg-green-500":n.confidence>=.5?"bg-yellow-500":"bg-red-500"}`,style:{width:`${n.confidence*100}%`}})}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[Math.round(n.confidence*100),"%"]})]})}),e.jsx("td",{className:"px-4 py-3 text-center",children:n.verified?e.jsx("span",{className:"text-green-600",children:"Yes"}):e.jsx("span",{className:"text-muted-foreground",children:"No"})}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx(se,{variant:"outline",size:"sm",onClick:()=>P(n),children:"Edit"})})]},n.id))]})]})]}),ge&&ke.length>0&&e.jsxs("div",{className:"rounded-lg border bg-card overflow-hidden",children:[e.jsx("div",{className:"border-b px-4 py-3 bg-muted/30",children:e.jsx("h2",{className:"font-semibold",children:"Category Breakdown"})}),e.jsx("div",{className:"p-4",children:e.jsxs("div",{className:"space-y-2",children:[ke.slice(0,10).map(n=>{const v=ke.reduce((ce,xe)=>ce+xe.amount,0),L=v>0?n.amount/v*100:0;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm w-48 truncate",title:n.category,children:n.category}),e.jsx("div",{className:"flex-1 h-4 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-blue-400",style:{width:`${Math.min(L,100)}%`}})}),e.jsx("span",{className:"text-sm font-medium w-24 text-right",children:_(n.amount)}),e.jsxs("span",{className:"text-xs text-muted-foreground w-12 text-right",children:[n.count,"x"]})]},n.category)}),ke.length>10&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["+ ",ke.length-10," more categories"]})]})})]})]})}),e.jsx(Ae,{open:!!T,onOpenChange:n=>{n||P(null)},children:e.jsxs(De,{children:[e.jsx(Ie,{children:e.jsx(Le,{children:"Edit Transaction"})}),T&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-muted-foreground -mt-2 mb-4",children:[je(T.date)," · ",T.description]}),e.jsx(is,{transaction:T,onSave:n=>{U.mutate({id:T.id,updates:n})},onCancel:()=>P(null),isLoading:U.isPending},T.id)]})]})}),ee&&e.jsx(ls,{documentId:i,initialTransactionId:ee,checkTransactions:Me,onClose:()=>ne(null)}),e.jsx(Ae,{open:b,onOpenChange:O,draggable:!0,children:e.jsxs(De,{children:[e.jsx(Ie,{children:e.jsx(Le,{children:t("review.reprocessTitle")})}),e.jsxs("div",{className:"py-4 space-y-3 text-sm text-muted-foreground",children:[e.jsx("p",{children:t("review.reprocessBody1")}),e.jsx("p",{children:t("review.reprocessBody2")}),e.jsxs("label",{className:"block space-y-1.5",children:[e.jsx("span",{className:"text-foreground font-medium",children:t("review.reprocessHintLabel")}),e.jsx(ht,{value:C,onChange:n=>E(n.target.value),placeholder:t("review.reprocessHintPlaceholder"),rows:4,maxLength:1e3,disabled:ie.isPending}),e.jsx("span",{className:"text-xs",children:t("review.reprocessHintHelp")})]})]}),e.jsxs(Oe,{children:[e.jsx(se,{variant:"outline",type:"button",onClick:()=>O(!1),disabled:ie.isPending,children:t("review.cancel")}),e.jsx(se,{type:"button",onClick:()=>ie.mutate(C.trim()||void 0),disabled:ie.isPending,children:ie.isPending?t("review.reprocessing"):t("review.reprocess")})]})]})}),e.jsx(Ae,{open:u,onOpenChange:m,children:e.jsxs(De,{children:[e.jsx(Ie,{children:e.jsx(Le,{children:t("review.approveTitle")})}),e.jsxs("div",{className:"py-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:Y?e.jsxs(e.Fragment,{children:[t("review.approveSales"),e.jsx("br",{}),e.jsx("strong",{children:t("review.netTaxable")})," ",_((l==null?void 0:l.netTaxableSales)||(l==null?void 0:l.grossSales)||0),e.jsx("br",{}),e.jsx("strong",{children:t("review.netTaxDue")}
1)," ",_((l==null?void 0:l.netTaxDue)||(l==null?void 0:l.taxCollected)||0)]}):$.length>0?`This will mark all ${$.length} transactions as verified and approve the document.`:"This will approve the document."}),s&&$e(s)&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:t("review.whoRemits")}),e.jsxs("select",{className:J("h-9 w-full rounded-md border px-2 text-sm font-medium",vt(F||null)),value:F,onChange:n=>{const v=n.target.value;V(v==="PLATFORM"||v==="MERCHANT"?v:"")},"aria-label":t("review.whoRemits"),children:[e.jsx("option",{value:"",children:t("review.choose")}),e.jsx("option",{value:"PLATFORM",children:t("review.platform")}),e.jsx("option",{value:"MERCHANT",children:t("review.restaurant")})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:(qe=s==null?void 0:s.salesChannel)!=null&&qe.name?t("review.whoRemitsHintChannel",{channel:s.salesChannel.name}):t("review.whoRemitsHintSolo")})]}),e.jsx("label",{className:"block text-sm font-medium mb-1",children:t("review.notes")}),e.jsx("textarea",{value:A,onChange:n=>I(n.target.value),className:"w-full rounded-md border px-3 py-2",rows:3,placeholder:t("review.notesPlaceholder")})]}),e.jsxs(Oe,{children:[e.jsx(se,{variant:"outline",type:"button",onClick:()=>m(!1),children:t("review.cancel")}),e.jsx(se,{type:"button",onClick:()=>q.mutate(),disabled:q.isPending||!!s&&$e(s)&&!F,children:q.isPending?t("review.approving"):t("review.approve")})]})]})})]}):e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"Document not found"})})}function ls({documentId:t,initialTransactionId:d,checkTransactions:i,onClose:x}){const[o,h]=c.useState(d),[f,p]=c.useState(!1),[y,w]=c.useState(""),[k,M]=c.useState(null),[S,T]=c.useState(new Map),[P,A]=c.useState([]),[I,u]=c.useState(!0),[m,b]=c.useState(!1),[O,C]=c.useState(1),[E,F]=c.useState({x:0,y:0}),[V,ee]=c.useState(!1),[ne,re]=c.useState({x:0,y:0}),[K,G]=c.useState({width:900,height:700}),[ae,le]=c.useState(!1),[z,B]=c.useState(()=>({x:Math.max(0,(window.innerWidth-900)/2),y:Math.max(0,(window.innerHeight-700)/2)})),[me,r]=c.useState(!1),g=c.useRef(null),N=c.useRef(new Map),j=i.find(a=>a.id===o),ue=c.useMemo(()=>{const a=new Map;for(const l of i){if(!l.checkImageStorageKey)continue;const D=a.get(l.checkImageStorageKey)||[];D.push(l),a.set(l.checkImageStorageKey,D)}return a},[i]),s=c.useMemo(()=>i.filter(a=>a.checkImageStorageKey&&a.checkNumber).sort((a,l)=>(a.checkNumber||"").localeCompare(l.checkNumber||"",void 0,{numeric:!0})),[i]),X=s.findIndex(a=>a.id===o),U=c.useMemo(()=>{if(!y.trim())return s;const a=y.trim().toLowerCase();return s.filter(l=>(l.checkNumber||"").toLowerCase().includes(a)||(l.checkPayee||"").toLowerCase().includes(a)||(l.description||"").toLowerCase().includes(a))},[s,y]);c.useEffect(()=>{if(f)return;const a=i.find(D=>D.id===o);if(!(a!=null&&a.checkImageStorageKey)){M(null),u(!1);return}let l=!1;return u(!0),Q.getCheckImage(o).then(D=>{l||M(W=>(W&&URL.revokeObjectURL(W),URL.createObjectURL(D)))}).catch(()=>{l||M(null)}).finally(()=>{l||u(!1)}),()=>{l=!0}},[o,f,i]),c.useEffect(()=>{if(!f||S.size>0)return;let a=!1;return b(!0),Q.getCheckImagePages(t).then(async l=>{if(a)return;A(l);const D=await Promise.allSettled(l.map(async R=>{const Y=await Q.getCheckImagePage(t,R);return{key:R,url:URL.createObjectURL(Y)}}));if(a)return;const W=new Map;for(const R of D)R.status==="fulfilled"&&W.set(R.value.key,R.value.url);T(W)}).catch(()=>{}).finally(()=>{a||b(!1)}),()=>{a=!0}},[f,t,S.size]),c.useEffect(()=>{if(!f||m||S.size===0)return;const a=i.find(l=>l.id===o);if(a!=null&&a.checkImageStorageKey){const l=N.current.get(a.checkImageStorageKey);l&&l.scrollIntoView({behavior:"smooth",block:"start"})}},[f,m,S.size,o,i]),c.useEffect(()=>()=>{k&&URL.revokeObjectURL(k),S.forEach(a=>URL.revokeObjectURL(a))},[]);const q=a=>{if(a!==o&&(h(a),C(1),F({x:0,y:0}),f)){const l=i.find(D=>D.id===a);l!=null&&l.checkImageStorageKey&&setTimeout(()=>{const D=N.current.get(l.checkImageStorageKey);D&&D.scrollIntoView({behavior:"smooth",block:"start"})},50)}},he=()=>{X>0&&q(s[X-1].id)},ie=()=>{X<s.length-1&&q(s[X+1].id)},pe=()=>C(a=>Math.min(a*1.5,5)),Se=()=>C(a=>Math.max(a/1.5,.3)),H=()=>{C(1),F({x:0,y:0})},$=a=>{a.button!==0||f||(ee(!0),re({x:a.clientX-E.x,y:a.clientY-E.y}))},Ne=a=>{V&&F({x:a.clientX-ne.x,y:a.clientY-ne.y})},be=()=>ee(!1),Ee=a=>{f||(a.preventDefault(),a.deltaY<0?C(l=>Math.min(l*1.15,5)):C(l=>Math.max(l/1.15,.3)))},we=a=>{if(a.button!==0)return;a.preventDefault(),r(!0);const l=a.clientX,D=a.clientY,W=z.x,R=z.y,Y=fe=>{B({x:W+(fe.clientX-l),y:R+(fe.clientY-D)})},oe=()=>{r(!1),window.removeEventListener("mousemove",Y),window.removeEventListener("mouseup",oe)};window.addEventListener("mousemove",Y),window.addEventListener("mouseup",oe)},Ce=a=>{a.preventDefault(),a.stopPropagation(),le(!0);const l=a.clientX,D=a.clientY,W=K.width,R=K.height,Y=fe=>{G({width:Math.max(400,W+(fe.clientX-l)),height:Math.max(300,R+(fe.clientY-D))})},oe=()=>{le(!1),window.removeEventListener("mousemove",Y),window.removeEventListener("mouseup",oe)};window.addEventListener("mousemove",Y),window.addEventListener("mouseup",oe)};return e.jsx("div",{className:"fixed inset-0 z-50 bg-black/50",children:e.jsxs("div",{className:"absolute bg-white rounded-lg shadow-xl flex flex-col overflow-hidden",style:{width:K.width,height:K.height,left:z.x,top:z.y},children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b bg-gray-50 shrink-0",style:{cursor:me?"grabbing":"grab"},onMouseDown:we,children:[e.jsxs("div",{className:"flex items-center gap-3",onMouseDown:a=>a.stopPropagation(),children:[e.jsxs("h3",{className:"font-semibold text-sm whitespace-nowrap",children:["Check #",(j==null?void 0:j.checkNumber)||""]}),(j==null?void 0:j.checkPayee)&&e.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[200px]",children:j.checkPayee}),j&&(()=>{const a=j.confidence,l=a>=.8?"bg-green-100 text-green-700":a>=.5?"bg-yellow-100 text-yellow-700":"bg-red-100 text-red-700";return e.jsxs("span",{className:`text-xs rounded px-1.5 py-0.5 ${l}`,title:`AI confidence: ${Math.round(a*100)}%`,children:[Math.round(a*100),"%"]})})(),s.length>1&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:he,disabled:X<=0,className:"px-1.5 py-0.5 text-xs rounded hover:bg-gray-200 disabled:opacity-30 disabled:cursor-not-allowed",title:"Previous check",children:"‹"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[X+1,"/",s.length]}),e.jsx("button",{onClick:ie,disabled:X>=s.length-1,className:"px-1.5 py-0.5 text-xs rounded hover:bg-gray-200 disabled:opacity-30 disabled:cursor-not-allowed",title:"Next check",children:"›"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",onMouseDown:a=>a.stopPropagation(),children:[e.jsx("button",{onClick:()=>p(a=>!a),className:`px-2 py-1 text-xs rounded ${f?"bg-blue-100 text-blue-700 hover:bg-blue-200":"hover:bg-gray-200"}
1`,title:f?"Show single check":"Show all pages",children:f?"Single":"All Pages"}),e.jsx("button",{onClick:Se,className:"px-2 py-1 text-xs rounded hover:bg-gray-200 font-mono",title:"Zoom out",children:"−"}),e.jsxs("span",{className:"text-xs text-muted-foreground w-12 text-center",children:[Math.round(O*100),"%"]}),e.jsx("button",{onClick:pe,className:"px-2 py-1 text-xs rounded hover:bg-gray-200 font-mono",title:"Zoom in",children:"+"}),e.jsx("button",{onClick:H,className:"px-2 py-1 text-xs rounded hover:bg-gray-200 ml-1",title:"Reset zoom",children:"Reset"}),e.jsx("button",{onClick:x,className:"px-2 py-1 text-xs rounded hover:bg-gray-200 ml-2",title:"Close",children:"✕"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b bg-white shrink-0",onMouseDown:a=>a.stopPropagation(),children:[e.jsx("input",{type:"text",placeholder:"Search check # or payee...",value:y,onChange:a=>w(a.target.value),className:"flex-1 text-sm border rounded px-2.5 py-1.5 outline-none focus:ring-1 focus:ring-blue-400"}),y&&e.jsxs("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:[U.length," result",U.length!==1?"s":""]})]}),y.trim()&&U.length>0&&e.jsx("div",{className:"border-b bg-white max-h-32 overflow-y-auto shrink-0",children:U.map(a=>e.jsxs("button",{type:"button",onClick:()=>{q(a.id),w("")},className:`w-full text-left px-4 py-1.5 text-sm hover:bg-blue-50 flex items-center gap-3 ${a.id===o?"bg-blue-50 font-medium":""}`,children:[e.jsxs("span",{className:"text-blue-700 font-mono",children:["#",a.checkNumber]}),e.jsx("span",{className:"text-muted-foreground truncate",children:a.checkPayee||"Unknown payee"}),e.jsxs("span",{className:"ml-auto text-xs text-muted-foreground",children:["$",Math.abs(a.amount/100).toFixed(2)]})]},a.id))}),e.jsx("div",{ref:g,className:`flex-1 bg-gray-200 ${f?"overflow-auto":"overflow-hidden"}`,style:{cursor:f?void 0:V?"grabbing":"grab",userSelect:ae||me||V?"none":void 0},onWheel:Ee,onMouseDown:$,onMouseMove:Ne,onMouseUp:be,onMouseLeave:be,children:f?m?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading all check pages..."})}):P.length===0?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("p",{className:"text-muted-foreground",children:"No check images available"})}):e.jsx("div",{className:"flex flex-col items-center gap-4 py-4",children:P.map((a,l)=>{const D=S.get(a),W=ue.get(a)||[];return e.jsxs("div",{ref:R=>{R&&N.current.set(a,R)},className:"bg-white shadow rounded",children:[e.jsxs("div",{className:"px-3 py-1.5 border-b bg-gray-50 flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Page ",l+1]}),W.map(R=>{const Y=R.id===o,oe=R.confidence,fe=Y?"bg-blue-600 text-white":oe>=.8?"bg-green-100 text-green-700":oe>=.5?"bg-yellow-100 text-yellow-700":"bg-red-100 text-red-700";return e.jsxs("span",{className:`text-xs rounded px-1.5 py-0.5 cursor-pointer ${fe}`,onClick:()=>q(R.id),title:`${R.checkPayee||"Unknown"} — ${Math.round(oe*100)}% confidence`,children:["#",R.checkNumber,R.checkPayee?` — ${R.checkPayee}`:""]},R.id)})]}),D?e.jsx("img",{src:D,alt:`Check image page ${l+1}`,draggable:!1,style:{width:`${O*100}%`,maxWidth:"none"}}):e.jsx("div",{className:"h-48 flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground text-sm",children:"Failed to load page"})})]},a)})}):I?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading check image..."})}):k?e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx("img",{src:k,alt:`Check #${(j==null?void 0:j.checkNumber)||""}`,draggable:!1,style:{transform:`translate(${E.x}px, ${E.y}px) scale(${O})`,transformOrigin:"center center",maxWidth:"none",maxHeight:"none"}})}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("p",{className:"text-muted-foreground",children:j!=null&&j.checkImageStorageKey?"Failed to load check image":"No check image available"})})}),j&&!f&&e.jsxs("div",{className:"shrink-0 px-4 py-2 border-t bg-gray-50 text-xs flex items-center gap-4 flex-wrap",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"AI Extraction:"}),e.jsxs("span",{children:["Check number: ",j.checkNumber||"—"]}),e.jsxs("span",{children:["Amount:"," ",j.amount!=null?`$${Math.abs(j.amount/100).toLocaleStr
1ing("en-US",{minimumFractionDigits:2})}`:"—"]}),j.category&&e.jsxs("span",{children:["Category: ",j.category]}),j.checkPayee&&e.jsxs("span",{children:["Payee: ",j.checkPayee]}),(()=>{const a=j.confidence,l=a>=.8?"text-green-600":a>=.5?"text-yellow-600":"text-red-600";return e.jsxs("span",{className:`font-medium ${l}`,children:[Math.round(a*100),"% confidence"]})})()]}),e.jsx("div",{className:"absolute bottom-0 right-0 w-4 h-4 cursor-se-resize",onMouseDown:Ce,style:{background:"linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.15) 50%)"}})]})})}function is({transaction:t,onSave:d,onCancel:i,isLoading:x}){const[o,h]=c.useState(t.description),[f,p]=c.useState(t.checkPayee||""),[y,w]=c.useState((t.amount/100).toString()),[k,M]=c.useState(t.type),[S,T]=c.useState(t.category||""),[P,A]=c.useState(t.taxable),[I,u]=c.useState(t.verified),m=b=>{b.preventDefault(),d({description:o,...t.checkNumber||t.checkPayee?{checkPayee:f}:{},amount:Math.round(parseFloat(y)*100),type:k,category:S||void 0,taxable:P,verified:I})};return e.jsxs("form",{onSubmit:m,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Description"}),e.jsx("input",{type:"text",value:o,onChange:b=>h(b.target.value),className:"w-full rounded-md border px-3 py-2"})]}),(t.checkNumber||t.checkPayee)&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Payee"}),e.jsx("input",{type:"text",value:f,onChange:b=>p(b.target.value),className:"w-full rounded-md border px-3 py-2"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Amount ($)"}),e.jsx("input",{type:"number",step:"0.01",value:y,onChange:b=>w(b.target.value),className:"w-full rounded-md border px-3 py-2"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Type"}),e.jsx("select",{value:k,onChange:b=>M(b.target.value),className:"w-full rounded-md border px-3 py-2",children:Object.entries(nt).map(([b,O])=>e.jsx("option",{value:b,children:O},b))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Category"}),e.jsxs("select",{value:S,onChange:b=>T(b.target.value),className:"w-full rounded-md border px-3 py-2",children:[e.jsx("option",{value:"",children:"Select category..."}),rs.map(b=>e.jsx("option",{value:b,children:b},b))]})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:P,onChange:b=>A(b.target.checked)}),e.jsx("span",{className:"text-sm",children:"Taxable"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:b=>u(b.target.checked)}),e.jsx("span",{className:"text-sm",children:"Verified"})]})]}),e.jsxs(Oe,{children:[e.jsx(se,{type:"button",variant:"outline",onClick:i,children:"Cancel"}),e.jsx(se,{type:"submit",disabled:x,children:x?"Saving...":"Save Changes"})]})]})}export{Os 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.