1import{r as g,j as e}from"./ui-DZy4HMEw.js";import{D as W,t as f,a as p,Y as G,B as b,C as L,i as A,j as D,ah as X,k as M,b as F,R as Z,a4 as R,aY as J}from"./index-DqpwcGVt.js";import{S as ee,a as ne,b as te,c as ae,d as se}from"./select-BDDRXW8D.js";import{B as h}from"./badge-DZCpMzYg.js";import{C as ce}from"./ConfirmDialog-B0LybP3r.js";import{L as V}from"./link-2-BDehvTz1.js";import{B as ie}from"./building-2-k5n5Pnjy.js";import{A as re}from"./arrow-right-left-BrebrBI2.js";import"./charts-B0yh2avS.js";import"./stripe-DwV5RDXX.js";const oe=W("Unlink",[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]);function U(n,t){var c=Object.keys(n);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(n);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(n,i).enumerable})),c.push.apply(c,s)}return c}function P(n){for(var t=1;t<arguments.length;t++){var c=arguments[t]!=null?arguments[t]:{};t%2?U(Object(c),!0).forEach(function(s){Q(n,s,c[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(c)):U(Object(c)).forEach(function(s){Object.defineProperty(n,s,Object.getOwnPropertyDescriptor(c,s))})}return n}function Q(n,t,c){return t in n?Object.defineProperty(n,t,{value:c,enumerable:!0,configurable:!0,writable:!0}):n[t]=c,n}function le(n,t){if(n==null)return{};var c={},s=Object.keys(n),i,r;for(r=0;r<s.length;r++)i=s[r],!(t.indexOf(i)>=0)&&(c[i]=n[i]);return c}function de(n,t){if(n==null)return{};var c=le(n,t),s,i;if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);for(i=0;i<r.length;i++)s=r[i],!(t.indexOf(s)>=0)&&Object.prototype.propertyIsEnumerable.call(n,s)&&(c[s]=n[s])}return c}function N(n,t){return ue(n)||xe(n,t)||pe(n,t)||ge()}function ue(n){if(Array.isArray(n))return n}function xe(n,t){var c=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(c!=null){var s=[],i=!0,r=!1,m,x;try{for(c=c.call(n);!(i=(m=c.next()).done)&&(s.push(m.value),!(t&&s.length===t));i=!0);}catch(o){r=!0,x=o}finally{try{!i&&c.return!=null&&c.return()}finally{if(r)throw x}}return s}}function pe(n,t){if(n){if(typeof n=="string")return $(n,t);var c=Object.prototype.toString.call(n).slice(8,-1);if(c==="Object"&&n.constructor&&(c=n.constructor.name),c==="Map"||c==="Set")return Array.from(n);if(c==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return $(n,t)}}function $(n,t){(t==null||t>n.length)&&(t=n.length);for(var c=0,s=new Array(t);c<t;c++)s[c]=n[c];return s}function ge(){throw new TypeError(`Invalid attempt to destructure non-iterable instance. 2In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var me=["src","checkForExisting"],O={},Y=function(t){var c=document.querySelector('script[src="'.concat(t,'"]'));if(c)return O[t]={loading:!1,error:null,scriptEl:c}},H=typeof window<"u"&&typeof window.document<"u";function fe(n){var t=n.src,c=n.checkForExisting,s=c===void 0?!1:c,i=de(n,me),r=t?O[t]:void 0;!r&&s&&t&&H&&(r=Y(t));var m=g.useState(r?r.loading:!!t),x=N(m,2),o=x[0],l=x[1],d=g.useState(r?r.error:null),k=N(d,2),S=k[0],E=k[1],y=g.useState(!1),j=N(y,2),I=j[0],v=j[1];return g.useEffect(function(){if(!(!H||!t||I||S)){r=O[t],!r&&s&&(r=Y(t));var u;r?u=r.scriptEl:(u=document.createElement("script"),u.src=t,Object.keys(i).forEac
2h(function(C){u[C]===void 0?u.setAttribute(C,i[C]):u[C]=i[C]}),r=O[t]={loading:!0,error:null,scriptEl:u});var w=function(){r&&(r.loading=!1),l(!1),v(!0)},_=function(T){r&&(r.error=T),E(T)};return u.addEventListener("load",w),u.addEventListener("error",_),document.body.appendChild(u),function(){u.removeEventListener("load",w),u.removeEventListener("error",_),r&&r.loading&&(u.remove(),delete O[t])}}},[t]),[o,S]}var he=function(t,c,s){var i={};return delete Object.assign(i,t,Q({},s,t[c]))[c],i},ke=function(t,c){var s={plaid:null,open:!1,onExitCallback:null};if(typeof window>"u"||!window.Plaid)throw new Error("Plaid not loaded");s.plaid=c(P(P({},t),{},{onExit:function(l,d){s.open=!1,t.onExit&&t.onExit(l,d),s.onExitCallback&&s.onExitCallback()}}));var i=function(){s.plaid&&(s.open=!0,s.onExitCallback=null,s.plaid.open())},r=function(l){s.plaid&&s.plaid.submit(l)},m=function(l,d){if(!s.open||!s.plaid){d&&d();return}s.onExitCallback=d,s.plaid.exit(l),l&&l.force&&(s.open=!1)},x=function(){s.plaid&&(s.plaid.destroy(),s.plaid=null)};return{open:i,submit:r,exit:m,destroy:x}},Ce=function(t,c){var s=he(t,"publicKey","key");return ke(s,c)},ve="https://cdn.plaid.com/link/v2/stable/link-initialize.js",K=function(){},ye=function(t){var c=fe({src:ve,checkForExisting:!0}),s=N(c,2),i=s[0],r=s[1],m=g.useState(null),x=N(m,2),o=x[0],l=x[1],d=g.useState(!1),k=N(d,2),S=k[0],E=k[1],y=(t.product||[]).slice().sort().join(",");g.useEffect(function(){if(!i&&!(!t.token&&!t.publicKey&&!t.receivedRedirectUri)){if(r||!window.Plaid){console.error("Error loading Plaid",r);return}o?.exit({force:!0},function(){return o.destroy()});var v=Ce(P(P({},t),{},{onLoad:function(){E(!0),t.onLoad&&t.onLoad()}}),window.Plaid.create);return l(v),function(){return v.exit({force:!0},function(){return v.destroy()})}}},[i,r,t.publicKey,t.token,y]);var j=o!=null&&(!i||S),I=function(){t.token||console.warn("react-plaid-link: You cannot call open() without a valid token supplied to usePlaidLink. This is a no-op.")};return{error:r,ready:j,submit:o?o.submit:K,exit:o?o.exit:K,open:o?o.open:I}},z;(function(n){n.OPEN="OPEN",n.EXIT="EXIT",n.HANDOFF="HANDOFF",n.SELECT_INSTITUTION="SELECT_INSTITUTION",n.ERROR="ERROR",n.BANK_INCOME_INSIGHTS_COMPLETED="BANK_INCOME_INSIGHTS_COMPLETED",n.IDENTITY_VERIFICATION_PASS_SESSION="IDENTITY_VERIFICATION_PASS_SESSION",n.IDENTITY_VERIFICATION_FAIL_SESSION="IDENTITY_VERIFICATION_FAIL_SESSION"})(z||(z={}));function je({linkToken:n,onSuccess:t}){const{open:c,ready:s}=ye({token:n,onSuccess:i=>t(i),onExit:i=>{i&&p.error(`Plaid Link error: ${i.error_message||i.error_code}`)}});return e.jsxs(b,{"data-loc":"client/src/pages/BankConnections.tsx:40",onClick:()=>c(),disabled:!s,children:[e.jsx(V,{"data-loc":"client/src/pages/BankConnections.tsx:41",className:"h-4 w-4 mr-2"}),"Connect Bank"]})}function Pe(){const[n,t]=g.useState(null),[c,s]=g.useState(null),[i,r]=g.useState(null),[m,x]=g.useState(null),o=f.banking.listConnections.useQuery(),l=f.banking.getUnmatched.useQuery(),d=f.useUtils(),k=f.banking.getMatches.useQuery(),E={data:f.invoices.list.useQuery().data?.filter(a=>a.status==="sent"||a.status==="overdue"||a.status==="pending")},y=f.banking.createLinkToken.useMutation({onSuccess:a=>{x(a.linkToken)},onError:a=>p.error(a.message)}),j=f.banking.exchangeToken.useMutation({onSuccess:()=>{p.success("Bank account connected!"),d.banking.listConnections.invalidate()},onError:a=>p.error(a.message)}),I=g.useCallback(a=>{j.mutate({publicToken:a,institutionName:"Bank"}),x(null)},[j]),v=f.banking.syncTransactions.useMutation({onSuccess:a=>{p.success(`Synced ${a.synced} transactions: ${a.autoMatched} auto-matched, ${a.unmatched} need review`),d.banking.getUnmatched.invalidate(),d.banking.getMatches.invalidate(),s(null)},onError:a=>{p.error(a.message),s(null)}}),u=f.banking.manualMatch.useMutation({onSuccess:()=>{p.success("Payment matched to invoice!"),d.banking.getUnmatched.invalidate(),d.banking.getMatches.invalidate(),r(null)},onError:a=>p.error(a.message)}),w=f.banking.ignorePayment.useMutation({onSuccess:()=>{p.success("Payment ignored"),d.banking.getUnmatched.invalidate()},onError:a=>p.error(a.message)}),_=f.banking.removeConnection.useMutation({onSuccess:()=>{p.success("Bank disconnected"),d.banking.listConnections.invalidate(),t(null)},onError:a=>p.error(a.message)}
2),C=a=>{s(a),v.mutate({connectionId:a})},T=a=>{switch(a){case"active":return e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:135",className:"bg-green-600",children:"Active"});case"error":return e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:137",variant:"destructive",children:"Error"});case"disconnected":return e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:139",variant:"secondary",children:"Disconnected"});default:return e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:141",variant:"outline",children:a})}},q=a=>{switch(a){case"auto-matched":return e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:148",className:"bg-green-600",children:"Auto"});case"manual-matched":return e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:150",className:"bg-blue-600",children:"Manual"});case"unmatched":return e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:152",variant:"outline",children:"Unmatched"});case"ignored":return e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:154",variant:"secondary",children:"Ignored"});default:return e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:156",variant:"outline",children:a})}};return e.jsxs(G,{"data-loc":"client/src/pages/BankConnections.tsx:161",children:[e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:162",className:"space-y-6 p-4 md:p-6",children:[e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:164",className:"flex items-center justify-between",children:[e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:165",children:[e.jsx("h1",{"data-loc":"client/src/pages/BankConnections.tsx:166",className:"text-2xl font-bold",children:"Banking"}),e.jsx("p",{"data-loc":"client/src/pages/BankConnections.tsx:167",className:"text-muted-foreground",children:"Connect your bank to auto-match Zelle payments to invoices"})]}),m?e.jsx(je,{"data-loc":"client/src/pages/BankConnections.tsx:172",linkToken:m,onSuccess:I}):e.jsxs(b,{"data-loc":"client/src/pages/BankConnections.tsx:174",onClick:()=>y.mutate(),disabled:y.isPending,children:[e.jsx(V,{"data-loc":"client/src/pages/BankConnections.tsx:178",className:"h-4 w-4 mr-2"}),y.isPending?"Connecting...":"Connect Bank"]})]}),e.jsxs(L,{"data-loc":"client/src/pages/BankConnections.tsx:185",children:[e.jsxs(A,{"data-loc":"client/src/pages/BankConnections.tsx:186",children:[e.jsxs(D,{"data-loc":"client/src/pages/BankConnections.tsx:187",className:"flex items-center gap-2",children:[e.jsx(X,{"data-loc":"client/src/pages/BankConnections.tsx:188",className:"h-5 w-5"}),"Connected Accounts"]}),e.jsx(M,{"data-loc":"client/src/pages/BankConnections.tsx:191",children:"Your linked bank accounts for payment matching"})]}),e.jsxs(F,{"data-loc":"client/src/pages/BankConnections.tsx:193",children:[o.data?.length===0&&e.jsx("p",{"data-loc":"client/src/pages/BankConnections.tsx:195",className:"text-muted-foreground text-center py-8",children:'No bank accounts connected yet. Click "Connect Bank" to get started.'}),e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:199",className:"space-y-3",children:o.data?.map(a=>e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:201",className:"flex items-center justify-between p-4 rounded-lg border bg-card",children:[e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:205",className:"flex items-center gap-4",children:[e.jsx(ie,{"data-loc":"client/src/pages/BankConnections.tsx:206",className:"h-8 w-8 text-muted-foreground"}),e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:207",children:[e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:208",className:"font-medium",children:a.institutionName||"Bank Account"}),e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:211",className:"text-sm text-muted-foreground",children:[a.accountName,a.accountMask&&` ····${a.accountMask}`]}),e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:215",className:"text-xs text-muted-foreground",children:["Last synced:"," ",a.lastSyncAt?new Date(a.lastSyncAt).toLocaleDateString():"Never"]})]})]}),e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:223",className:"flex items-center gap-2",children:[T(a.status),e.jsxs(b,{"data-loc":"client/src/pages/BankConnections.tsx:225",variant:"outline",size:"sm",onClick:()=>C(a.id),disabled:c===a.id,children:[e.jsx(Z,{"data-loc":"client/src/pages/BankConnections.tsx:231",className:`h-4 w-4 mr-1 ${c===a.id?"animate-spin":""}`}),"Sync"]}),e.jsx(b,{"data-loc":"client/src/pages/BankConnections.tsx:236",variant:"ghost",size:"sm",onClick:()=>t(a.id),children:e.jsx(oe,{"data-loc":"client/src/pages/BankConnections.tsx:241",className:"h-4 w-4"})})]})]},a.id))})]})]}),e.jsxs(L,{"data-loc":"client/src/pages/BankConnections.tsx:251",children:[e.jsxs(A,{"data-loc":"client/src/pages/BankConnections.tsx:252",children:[e.jsxs(D,{"data-loc":"client/src/pages/BankConnections.tsx:253",className:"flex items-center gap-2",children:[e.jsx(re,{"data-loc":"client/src/pages/BankConnections.tsx:254",className:"h-5 w-5"}),"Unmatched Payments",l.data&&l.data.length>0&&e.jsx(h,{"data-loc":"client/src/pages/BankConnections.tsx:257",variant:"destructive",children:l.data.length})]}),e.jsx(M,{"data-loc":"client/src/pages/BankConnections.tsx:260",children:"Incoming payments that need to be matched to an invoice"})]}),e.jsxs(F,{"data-loc":"client/src/pages/BankConnections.tsx:264",children:[(!l.data||l.data.length===0)&&e.jsx("p",{"data-loc":"client/src/pages/BankConnections.tsx:266",className:"text-muted-foreground text-center py-6",children:"No unmatched payments. Sync your bank to check for new transactions."}),e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:270",className:"space-y-2",children:l.data?.map(a=>e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:272",className:"flex items-center justify-between p-4 rounded-lg border",children:[e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:276",className:"flex-1 grid grid-cols-4 gap-4 items-center",children:[e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:277",className:"text-sm",children:new Date(a.transactionDate).toLocaleDateString()}),e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:280",className:"font-medium text-green-600",children:["$",parseFloat(a.amount).toFixed(2)]}),e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:283",className:"text-sm truncate",children:a.counterpartyName||"Unknown sender"}),e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:286",className:"text-sm text-muted-foreground truncate",children:a.description})]}),e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:290",className:"flex items-center gap-2 ml-4",children:[e.jsxs(ee,{"data-loc":"client/src/pages/BankConnections.tsx:291",value:i?.id===a.id?i?.invoiceId??"":"",onValueChange:B=>r({id:a.id,invoiceId:B}),children:[e.jsx(ne,{"data-loc":"client/src/pages/BankConnections.tsx:301",className:"w-[180px]",children:e.jsx(te,{"data-loc":"client/src/pages/BankConnections.tsx:302",placeholder:"Match to invoice"})}),e.jsx(ae,{"data-loc":"client/src/pages/BankConnections.tsx:304",children:E.data?.map(B=>e.jsxs(se,{"data-loc":"client/src/pages/BankConnections.tsx:306",value:String(B.id),children:["#",B.invoiceNumber," - $",parseFloat(B.total||"0").toFixed(2)]},B.id))})]}),e.jsx(b,{"data-loc":"client/src/pages/BankConnections.tsx:312",size:"sm",disabled:!i||i.id!==a.id||u.isPending,onClick:()=>{i&&i.id===a.id&&u.mutate({paymentMatchId:a.id,invoiceId:parseInt(i.invoiceId)})},children:e.jsx(R,{"data-loc":"client/src/pages/BankConnections.tsx:328",className:"h-4 w-4"})}),e.jsx(b,{"data-loc":"client/src/pages/BankConnections.tsx:330",variant:"ghost",size:"sm",onClick:()=>w.mutate({paymentMatchId:a.id}),disabled:w.isPending,children:e.jsx(J,{"data-loc":"client/src/pages/BankConnections.tsx:338",className:"h-4 w-4"})})]})]},a.id))})]})]}),e.jsxs(L,{"data-loc":"client/src/pages/BankConnections.tsx:348",children:[e.jsxs(A,{"data-loc":"client/src/pages/BankConnections.tsx:349",children:[e.jsxs(D,{"data-loc":"client/src/pages/BankConnections.tsx:350",className:"flex items-center gap-2",children:[e.jsx(R,{"data-loc":"client/src/pages/BankConnections.tsx:351",className:"h-5 w-5"}),"Recent Matches"]}),e.jsx(M,{"data-loc":"client/src/pages/BankConnections.tsx:354",children:"Auto and manually matched payments"})]}),e.jsxs(F,{"data-loc":"client/src/pages/BankConnections.tsx:356",children:[(!k.data||k.data.filter(a=>a.matchStatus==="auto-matched"||a.matchStatus==="manual-matched").length===0)&&e.jsx("p",{"data-loc":"client/src/pages/BankConnections.tsx:363",className:"text-muted-foreground text-center py-6",children:"No matched payments yet."}),e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:367",className:"space-y-2",children:k.data?.filter(a=>a.matchStatus==="auto-matched"||a.matchStatus==="manual-matched").slice(0,50).map(a=>e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:376",className:"flex items-center justify-between p-3 rounded-lg border",children:[e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:380",className:"flex-1 grid grid-cols-4 gap-4 items-center",children:[e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:381",className:"text-sm",children:new Date(a.transactionDate).toLocaleDateString()}),e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:384",className:"font-medium text-green-600",children:["$",parseFloat(a.amount).toFixed(2)]}),e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:387",className:"text-sm truncate",children:a.counterpartyName||"Unknown"}),e.jsxs("div",{"data-loc":"client/src/pages/BankConnections.tsx:390",className:"text-sm text-muted-foreground",children:["Invoice #",a.matchedInvoiceId]})]}),e.jsx("div",{"data-loc":"client/src/pages/BankConnections.tsx:394",className:"ml-4",children:q(a.matchStatus)})]},a.id))})]})]})]}),e.jsx(ce,{"data-loc":"client/src/pages/BankConnections.tsx:404",open:n!==null,onCancel:()=>t(null),title:"Disconnect Bank Account",description:"This will remove the bank connection. You can reconnect at any time.",onConfirm:()=>{n&&_.mutate({connectionId:n})},confirmLabel:"Disconnect",destructive:!0})]})}export{Pe 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.