1import{j as e,n as ce,r as w,l as de,u as ue,N as he}from"./vendor-react-2cb5d109.js";import{b as m,g as C,ek as I,aV as R,d as p,ca as O,cm as ge,a7 as X,a8 as ee,i as ae,eh as xe,c1 as me}from"./vendor-vy-bde48d53.js";import{H as te}from"./vendor-misc-09f7f1da.js";import{ar as pe,bo as ne,Z as ve,bp as B,bq as je,z as Y,w as oe,k as fe,d as be}from"./app-core-47ba8b05.js";import{u as we,a as ie,b as Ce,C as Z,r as Ie,c as Pe,d as Ee,e as ye,U as De}from"./UsageExplorer-119bc2c4.js";import{b6 as Te,b7 as Ne,i as S,S as U,T as A,aA as Se,B as N,I as Ue,g as _e}from"./vendor-mui-c34240eb.js";import{c as u,s as $,ag as H,d as P,aZ as Ae,ab as se,$ as L,a_ as re,h as M,a$ as Le,ac as f,l as b,ar as Ve,aN as ke,o as Oe,a2 as Be,a3 as q,b0 as Me,b1 as Ge,b2 as Re,a as $e}from"./vendor-vy-ds-da93fbfd.js";import{V as He}from"./VyTooltip-4f1579b8.js";import{u as We}from"./use-page-param-6119b40d.js";import{u as Fe}from"./use-table-pagination-2ef45298.js";import{u as ze}from"./use-toggle-783e3c5d.js";import{P as Ke}from"./PdfViewer-2c895b77.js";import{I as Ye}from"./InvoiceBillingStatusPill-7e8135e5.js";import"./use-filters-param-3eac83d6.js";import"./use-state-params-e6f24508.js";import"./use-to-day-param-da30d2fa.js";import"./use-pagination-reset-handler-46085f8b.js";import"./chart-theme-256de34b.js";import"./use-debounce-9c73162a.js";import"./use-search-with-search-params-e26dc43c.js";import"./use-sync-query-param-to-state-995010ee.js";import"./use-meters-85139a64.js";import"./use-menu-fcf82705.js";import"./date-range-shortcuts-faf6e149.js";import"./RevenueReportToolbar-1ae08560.js";import"./picker-value-utils-d352bb2c.js";import"./use-trigger-report-job-5eafb877.js";import"./papaparse.min-eac00b5a.js";import"./chart-panel-consts-11f72b7b.js";import"./use-account-f5081143.js";import"./reference-data-query-options-consts-650f2d3a.js";import"./use-customers-names-b6b996a9.js";import"./use-effect-once-07b631b8.js";import"./vendor-pdfjs-a174bb6b.js";import"./get-invoice-status-role-2d5ffc66.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};a.SENTRY_RELEASE={id:"a44d049e7c59"};var n=new a.Error().stack;
1n&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[n]="aa6f21c2-9f9c-49a1-ac1b-2e3fe9699edb",a._sentryDebugIdIdentifier="sentry-dbid-aa6f21c2-9f9c-49a1-ac1b-2e3fe9699edb")}catch{}})();const Q=40,Ze=100,qe=32,Qe=({logo:a,isLoading:n=!1})=>e.jsx(Te,{position:"sticky",sx:{bgcolor:"background.paper",boxShadow:"none"},children:e.jsx(Ne,{sx:{justifyContent:"center"},children:e.jsx(u,{direction:"row",sx:{alignItems:"center",justifyContent:"center",color:$.content.strong},children:n?e.jsx(S,{variant:"rectangular",width:120,height:Q}):m(a)?e.jsx(H,{width:Ze,height:qe}):e.jsx("img",{src:a,alt:"",style:{height:Q}})})})}),Je=160,Xe=51,ea=()=>e.jsxs(e.Fragment,{children:[e.jsx(te,{children:e.jsx("title",{children:"Vayu: Customer Portal"})}),e.jsxs(u,{sx:{justifyContent:"center",alignItems:"center",width:"100%",height:"100vh",textAlign:"center",p:2,gap:3,bgcolor:"background.paper"},children:[e.jsx(u,{sx:{color:$.content.strong},children:e.jsx(H,{width:Je,height:Xe})}),e.jsxs(u,{sx:{gap:1},children:[e.jsx(P,{variant:"headingM",children:"Your link has expired"}),e.jsx(P,{variant:"bodyL",sx:{color:"text.secondary"},children:"Please request a new link"})]})]})]}),aa=63,ta=20,na=()=>e.jsxs(u,{direction:"row",sx:{alignItems:"center",gap:1,pb:1,pl:4},children:[e.jsx(P,{variant:"bodyM",sx:{color:"text.secondary"},children:"Revenue Platform Powered by"}),e.jsx(u,{sx:{color:$.content.strong},children:e.jsx(H,{width:aa,height:ta})})]}),oa=({customer:a})=>e.jsxs(U,{children:[e.jsx(U,{spacing:2,direction:"row",sx:{alignItems:"center"},children:e.jsxs(U,{direction:"row",divider:e.jsx(pe,{orientation:"vertical",flexItem:!0}),sx:{alignItems:"center",gap:2},children:[e.jsx(He,{tooltipContent:a.name,placement:"top",arrow:!0,showOnlyWhenTruncated:!0,children:e.jsx(A,{variant:"h5",sx:{fontSize:"24px",...Ae},children:a.name})}),e.jsx(A,{color:"text.secondary",sx:{fontSize:"24px",fontWeight:300},children:"Invoice portal"})]})}),e.jsx(A,{variant:"body1",color:"textSecondary",sx:{fontWeight:300},children:"View your usage, credit and invoices"})]}),ia=ce.memo(({isLoading:a,encodedPdf:n})=>e.jsx(U,{sx:{backgroundColor:"#ECEDEE",padding:"32px",alignItems:"center"},children:a?e.jsx(S,{variant:"rectangular",width:"100%",height:"100%"}):n&&e.jsx(Ke,{base64EncodedPdf:n})})),sa=({selectedInvoice:a,drawerOpen:n,toggleDrawer:t,customer:i,access:s,allowUsageDataDownload:r})=>{const{data:l,isLoading:x}=we(s,a.id,{enabled:n}),h=ie(s),o=w.useCallback(async()=>{m(l)||await ne(l.encodedPdf,a.customerName,a.name)},[l,a.customerName,a.name]),c=()=>h(a);return e.jsxs(Se,{anchor:"right",open:n,onClose:()=>t(),sx:{width:"767px",flexShrink:0,"& .MuiDrawer-paper":{width:"767px",height:"100vh",boxSizing:"border-box",display:"flex",flexDirection:"column",backgroundColor:"#ECEDEE"}},children:[e.jsxs(N,{sx:{display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",bgcolor:"background.default",px:3,py:2,gap:2},children:[e.jsxs(A,{variant:"h5",sx:{color:"text.primary"},children:[i.name," - ",a.name]}),e.jsxs(u,{direction:"row",sx:{gap:1,alignItems:"center"},children:[e.jsx(Ue,{onClick:o,disabled:x,children:e.jsx(se,{})}),r&&e.jsx(L,{"aria-label":"Download usage data",onClick:c,...C(I.invoiceViewer.downloadUsageReport),children:e.jsx(re,{})})]})]}),e.jsx(_e,{}),e.jsx(ia,{isLoading:x,encodedPdf:l==null?void 0:l.encodedPdf})]})},ra=({invoice:a,access:n,allowUsageDataDownload:t,onViewInvoice:i})=>{const s=Ce(),r=ie(n),l=c=>c.stopPropagation(),x=c=>{l(c),i(a)},h=async c=>{l(c),await ve(s,{...n,invoiceId:a.id},{pending:"Downloading invoice...",success:"Invoice downloaded",error:"Failed to download invoice"},{onSuccess:({encodedPdf:v})=>ne(v,a.customerName,a.name)})},o=async c=>{l(c),await r(a)};return e.jsxs(u,{direction:"row",sx:{alignItems:"center",justifyContent:"flex-end",gap:1},children:[e.jsx(M,{title:"View invoice",children:e.jsx(L,{variant:"outlined","aria-label":"View invoice",onClick:x,...C(I.invoicesTable.viewInvoice),children:e.jsx(Le,{width:f,height:f})})}),e.jsx(M,{title:"Download invoice",children:e.jsx(L,{variant:"outlined","aria-label":"Download invoice",onClick:h,...C(I.invoicesTable.downloadInvoice),children:e.jsx(se,{width:f,height:f})})}),t&&e.jsx(M,{title:"Download usage data (CSV)",children:e.jsx(L,{variant:"outlined","aria-label":"Download usage data",onClick:o,...C(I.invoicesTable.downloadUsageReport),children:e.jsx(re,{width:f,height:f})})})]})},g={AMOUNT:"amount",PERIOD:"period",ISSUED_AT:"issuedAt",DUE_DATE:"dueDate",INVOICE_NUMBER:"invoiceNumber",PLAN_NAME:"planName",BILLING_STATUS:"billingStatus",ACTIONS:"actions"};function J(a){return a.revenueBreakdown.total+a.revenueBreakdown.creditsUsed}const la={field:g.PLAN_NAME,headerName:"Plan name",flex:1,minWidth:140,valueGetter:(a,n)=>n.invoice.planName??"",renderCell:({row:a})=>e.jsx(b,{value:a.invoice.planName??void 0,align:"left"})};function ca({showPlanName:a,allowUsageDataDownload:n}){return[{field:g.AMOUNT,headerName:"Amount",minWidth:140,valueGetter:(t,i)=>J(i.invoice),renderCell:({row:t})=>e.jsx(b,{value:R(J(t.invoice),t.invoice.currency),align:"left"})},{field:g.PERIOD,headerName:"Period",minWidth:200,valueGetter:(t,i)=>
1i.invoice.billingCycle.startTime,sortComparator:B,renderCell:({row:t})=>e.jsx(b,{value:je(t.invoice.billingCycle),align:"left"})},{field:g.ISSUED_AT,headerName:"Issue date",minWidth:130,valueGetter:(t,i)=>i.invoice.issuedAt,sortComparator:B,renderCell:({row:t})=>e.jsx(b,{value:p(t.invoice.issuedAt)?Y(t.invoice.issuedAt):void 0,align:"left"})},{field:g.DUE_DATE,headerName:"Due date",minWidth:130,valueGetter:(t,i)=>i.invoice.dueDate,sortComparator:B,renderCell:({row:t})=>e.jsx(b,{value:p(t.invoice.dueDate)?Y(t.invoice.dueDate):void 0,align:"left"})},{field:g.INVOICE_NUMBER,headerName:"Invoice number",minWidth:150,valueGetter:(t,i)=>i.invoice.invoiceNumber,renderCell:({row:t})=>e.jsx(b,{value:t.invoice.invoiceNumber,align:"left"})},...a?[la]:[],{field:g.BILLING_STATUS,headerName:"Status",minWidth:150,sortable:!1,renderCell:({row:t})=>e.jsx(Ye,{billingStatus:t.invoice.billingStatus,isTrial:t.invoice.isTrial})},{field:g.ACTIONS,headerName:"",minWidth:n?150:110,sortable:!1,resizable:!1,align:"right",renderCell:({row:t})=>e.jsx(ra,{invoice:t.invoice,access:t.access,allowUsageDataDownload:n,onViewInvoice:t.onViewInvoice})}]}const da=550,ua=[10,25,50],ha=({invoices:a,customer:n,access:t,totalInvoicesCount:i,invoicesSummary:s,portalSettings:r,isFetching:l=!1})=>{const[x,h]=ze(!1),[o,c]=w.useState(null),[v,V]=We(),[E,k]=Fe(Z),y=w.useCallback(d=>{c(d),h()},[h]),D=w.useMemo(()=>ca({showPlanName:r.showPlanName,allowUsageDataDownload:r.allowUsageDataDownload}),[r.showPlanName,r.allowUsageDataDownload]),_=w.useMemo(()=>a.map(d=>({id:d.id,invoice:d,access:t,onViewInvoice:y})),[a,t,y]);return e.jsxs(e.Fragment,{children:[e.jsxs(e.Fragment,{children:[e.jsxs(u,{direction:"row",sx:{gap:2,paddingBlock:3,alignItems:"center"},divider:e.jsx(Ve,{orientation:"vertical",flexItem:!0}),children:[e.jsx(P,{variant:"labelL",children:`${i} total invoices`}),e.jsx(G,{count:(s==null?void 0:s[O.Overdue])??0,label:"overdue",color:"error.main"}),e.jsx(G,{count:(s==null?void 0:s[O.Paid])??0,label:"paid",color:"success.main"}),e.jsx(G,{count:(s==null?void 0:s[O.PendingPayment])??0,label:"pending",color:"warning.main"})]}),e.jsx(ke,{sx:{height:da,overflow:"hidden"},children:e.jsx(Oe,{rows:_,columns:D,getRowId:d=>d.id,rowCount:i,loading:l,pagination:!0,paginationMode:"server",paginationModel:{page:v??0,pageSize:E??Z},onPaginationModelChange:d=>{V(d.page),k(d.pageSize)},pageSizeOptions:ua,sortingMode:"client",initialState:{sorting:{sortModel:[{field:g.ISSUED_AT,sort:"desc"}]}}})})]}),p(o)&&e.jsx(sa,{selectedInvoice:o,drawerOpen:x,toggleDrawer:h,customer:n,access:t,allowUsageDataDownload:r.allowUsageDataDownload})]})};function G({count:a,label:n,color:t}){return e.jsxs(u,{direction:"row",sx:{gap:.5,alignItems:"center"},children:[e.jsx(P,{variant:"body1",sx:{color:t},children:a}),e.jsx(P,{variant:"body1",sx:{color:"text.secondary"},children:n})]})}const ga=({value:a,onChange:n})=>e.jsxs(Be,{value:a,onChange:(t,i)=>n(i),sx:{borderBottom:1,borderColor:"divider"},children:[e.jsx(q,{value:"invoices",label:"All invoices",iconPosition:"start",icon:e.jsx(Me,{width:18,height:18}),...C(I.tabs.invoices)}),e.jsx(q,{value:"usage",label:"Usage breakdown",iconPosition:"start",icon:e.jsx(Ge,{width:18,height:18}),...C(I.tabs.usage)})]}),xa=oe(De);function ma(a,n){return a.creditKind===X.MONETARY?R(a.balance,n):`${ee(a.balance)} ${a.units??"units"}`}function pa(a){return ae(a.creditTypeName)?`Available credits â ${a.creditTypeName}`:"Available credits"}function va(a,n){return a.projectedBalance>=a.balance?null:a.creditKind===X.MONETARY?R(a.projectedBalance,n):`${ee(a.projectedBalance)} ${a.units??"units"}`}function ja(a,n){const t=va(a,n),i=m(a.closestEntryExpiryDate)?void 0:`${a.initialGrantSchedule===xe.ONE_TIME?"Expires on":"Resets"} ${me(a.closestEntryExpiryDate)}`,s=p(t)?`Projected after pending invoices: ${t}`:void 0,r=[i,s].filter(p).join(" · ");return ae(r)?r:void 0}const fa=()=>{const[a]=de(),n=ue(),t=a.get("token")??"",i=a.get("customerId")??"",{access:s,isTokenMode:r,hasAccess:l,needsLogin:x,isQueryEnabled:h}=Ie(t,i,be()),{data:o,isError:c,isLoading:v,isFetching:V}=Pe(s,{enabled:h}),[E,k]=w.useState("invoices"),{data:y}=Ee(s,{enabled:h&&p(o)}),{data:D}=ye(t,{enabled:r&&p(o)}),_=(D==null?void 0:D.creditPools)??[],d=p(y)&&y.usageByDateBreakdown.length>0,W=(o==null?void 0:o.currency)??ge;if(x){const j=encodeURIComponent(`${n.pathname}${n.search}`);return e.jsx(he,{to:`/login?returnTo=${j}`,replace:!0})}if(!l||c||m(o)&&!v)return e.jsx(ea,{});const T=o==null?void 0:o.portalSettings,le=(T==null?void 0:T.hideInvoices)??!1,F=_.length>0&&e.jsx(u,{direction:"row",sx:{gap:2,flexWrap:"wrap"},children:_.map(j=>e.jsx(Re,{label:pa(j),value:ma(j,W),caption:ja(j,W)},j.id))}),z=m(o)||m(T)?null:e.jsxs(e.Fragment,{children:[F,e.jsx(ha,{invoices:o.invoices,customer:o.customer,access:s,totalInvoicesCount:o.totalInvoicesCount,invoicesSummary:o.invoicesSummary,portalSettings:T,isFetching:V})]}),K=m(o)?null:d?e.jsx(u,{sx:{flex:o.portalSettings.showUsageTable?1:void 0,minHeight:0},children:e.jsx(xa,{variant:"customerPortal",showTable:o.portalSettings.showUsageTable})}):e.jsx($e,{title:"No usage data yet",description:"Usage will appear here once events are received for this customer."});return e.jsxs(e.Fragment,{children:[e.jsx(te,{children:e.jsx("title",{children:"Vayu: Customer Portal"})}),e.jsxs(N,{sx:{flexGrow:1,display:"flex",flexDirection:"column",height:"100%",bgcolor:"background.paper"},children:[e.jsx(Qe,{logo:o==null?void 0:o.account.logoUrl,isLoading:v}),e.jsx(N,{sx:{padding:"20px 122px",width:"100%",height:"100%",display:"flex",flexDirection:"column",overflow:"hidden",overflowY:"auto"},children:v||m(o)?e.jsxs(e.Fragment,{children:[e.jsx(N,{sx:{mb:3},children:e.jsx(S,{variant:"rectangular",width:"100%",height:120})}),e.jsxs(N,{children:[e.jsx(S,{variant:"rectangular",width:"100%",height:50,sx:{mb:1}}),e.jsx(S,{variant:"rectangular",width:"100%",height:400})]})]}):e.jsxs(U,{sx:{gap:1,flex:1,minHeight:0},children:[e.jsx(oa,{customer:o.customer}),le?e.jsxs(e.Fragment,{children:[F,K]}):d?e.jsxs(e.Fragment,{children:[e.jsx(ga,{value:E,onChange:k}),E==="invoices"&&z,E==="usage"&&K]}):z]})}),e.jsx(na,{})]})]})},at=oe(fe(fa));
1export{at as CustomerPortalPage};
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.