1import{j as t,r as Z,i as h,T as tt,g as J,b as T,B as Q,I as xt,P as gt}from"./vendor-mui-C-ZIhv98.js";import{F as k,z as St,M as Ct,H as wt,C as yt}from"./index-B83XaGtb.js";import{r as i}from"./vendor-react-eXwhXRaO.js";import{I as _t}from"./InfoOutlined-DyhIIb9K.js";import{u as jt}from"./use-posted-table-sort-CSL2Arxw.js";import{c as E,q as S,w as D,n as et,l as Dt,o as vt,s as Pt,e as Rt,b as st}from"./vendor-firebase-DUTjPSH1.js";import"./vendor-utils-9gOWU9uB.js";import{u as At}from"./use-posted-table-LNK0atvQ.js";import{P as It}from"./posted-table-DC_eUuhM.js";import{C as Ft}from"./common-filter-SG4yBNrj.js";import{P as Lt}from"./posted-sortable-header-BcoHsGvq.js";import{f as W}from"./status-colors-D3BmDtcd.js";import{f as at,b as Bt}from"./common-filter-labels-BkT-oeM2.js";import{u as Nt}from"./use-active-row-scroll-BF2-TxUl.js";import{O as Tt}from"./open-drawer-button-BDM-WqFj.js";import{S as nt}from"./sticky-action-cell-CaOE_F3S.js";import{a as Ot}from"./format-timestamp-Do_tOFfD.js";import{F as p,C as kt}from"./charge-brands-drawer-B27sBRij.js";import{g as Et,h as R,i as Wt}from"./docs-note-list-C_7tpBSc.js";import{D as Ht,a as $t,b as Mt}from"./docs-action-list-_RQ9ZYKb.js";import"./vendor-player-CIRS_UPS.js";import"./vendor-redux-CMPsAOw6.js";import"./vendor-forms-60pWfZxG.js";import"./vendor-phone-BXVD6DEZ.js";import"./vendor-animation-lISua3i-.js";import"./table-context-C6Xa-gRT.js";import"./report-resolution-footer-LUjP08in.js";import"./video-panel-DMJnBYd_.js";import"./user-BNPNl05X.js";import"./SocialPlatform-C2r4o-Gn.js";import"./drawer-navigation-C4THGRJW.js";import"./drawer-user-container-mCjmebp3.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},n=new e.Error().stack;
1n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2073847a-425f-420f-a1ae-3720bf98cf8e",e._sentryDebugIdIdentifier="sentry-dbid-2073847a-425f-420f-a1ae-3720bf98cf8e")}catch{}})();function Gt({row:e,onOpenDrawer:n,isActive:o}){const r=Nt(o),l=W()[e.status]??{text:"#637381",background:"#919EAB29"};return t.jsxs(Z,{ref:r,sx:{height:74,...o&&{backgroundColor:"rgba(var(--palette-grey-500Channel) / 0.08)","td:first-of-type":{boxShadow:"inset 3px 0 0 var(--palette-grey-500)"}}},children:[t.jsx(h,{children:e.brand_name||"-"}),t.jsx(h,{children:Ot(e.date_failed)}),t.jsx(h,{children:t.jsx(tt,{variant:"body2",sx:{fontWeight:"bold",color:l.text,backgroundColor:l.background,padding:"2px 6px",borderRadius:"6px",width:"fit-content"},children:at[e.status]??"-"})}),t.jsx(h,{children:e.amount_to_pay!==void 0?`$${e.amount_to_pay.toFixed(2)}`:"â"}),t.jsx(h,{children:e.stripe_debt!==void 0?`$${e.stripe_debt.toFixed(2)}`:"â"}),t.jsx(h,{children:e.stripe_credit!==void 0?`$${e.stripe_credit.toFixed(2)}`:"â"}),t.jsx(h,{children:e.open_cpm_cost!==void 0?`$${e.open_cpm_cost.toFixed(2)}`:"â"}),t.jsx(h,{children:e.pending_submissions_count??0}),t.jsx(nt,{align:"right",className:"actions-popover",children:t.jsx(Tt,{onClick:()=>n(e)})})]})}const O=[{id:"brand_name",label:"Brand Name",cellSortable:!1,width:"22%",minWidth:"180px"},{id:"date_failed",label:"Date Failed",cellSortable:!0,width:"16%",minWidth:"160px"},{id:"status",label:"Status",cellSortable:!1,width:"12%",minWidth:"120px"},{id:"amount_to_pay",label:"Amount to Pay",cellSortable:!1,width:"12%",minWidth:"120px"},{id:"stripe_debt",label:"Debt",cellSortable:!1,width:"10%",minWidth:"100px"},{id:"stripe_credit",label:"Credit",cellSortable:!1,width:"10%",minWidth:"100px"},{id:"open_cpm_cost",label:"Open CPM Cost",cellSortable:!1,width:"12%",minWidth:"120px"},{id:"pending_submissions_count",label:"Pending Submissions",cellSortable:!1,width:"17%",minWidth:"160px"},{id:"",label:"",cellSortable:!1,width:"6%",minWidth:"64px"}];function qt(){return t.jsx(Z,{sx:{height:74},children:O.map((e,n)=>n===O.length-1?t.jsx(nt,{sx:{width:72},children:t.jsx(J,{variant:"rounded",width:40,height:40,sx:{margin:"auto"}})},e.id||n):t.jsx(h,{children:t.jsx(J,{variant:"rounded"})},e.id||n))})}const Vt=[{status:p.PENDING,description:"Brand on payment hold with active (LIVE or VERIFYING) submissions still running."},{status:p.FINAL,description:"All submissions done. Debt is ready to be collected.",transitionLabel:"All submissions finish"}],Ut=[{status:p.PAID,description:"Debt covered â set automatically when Stripe balance + open CPM cost ⤠0. Hold is cleared."},{status:p.WRITTEN_OFF,description:"Debt forgiven manually. Brand stays on hold â record stays active and can be reactivated."}],zt=[{label:"Sync",color:"inherit",description:"Available on Pending, Final, Written Off. Recalculates debt from Stripe â marks Paid and clears hold if covered."},{label:"Write Off",color:"error",description:"Available on Pending or Final. Marks debt as written off. Brand remains on hold."},{label:"Reactivate",color:"warning",description:"Available on Written Off. Restores record to Final (or Pending if submissions still running)."}],Yt=[{text:"Brand pays (auto-charge, top-up, refund, etc.) â system checks debt automatically and marks Paid if covered."},{text:"All submissions finish for a pending brand â record transitions to Final automatically."},{text:"Brand goes on hold â record is created or updated automatically."}];function X({status:e,description:n,transitionLabel:o},r){return{label:at[e],colors:r[e],description:n,transitionLabel:o}}function Kt({open:e,onClose:n}){const o=W();return t.jsxs(Et,{open:e,onClose:n,title:"How Charge Brands works",children:[t.jsx(R,{title:"Statuses",children:t.jsx(Ht,{items:Vt.map(r=>X(r,o))})}),t.jsx(T,{}),t.jsx(R,{title:"Terminal states",children:t.jsx($t,{items:Ut.map(r=>X(r,o))})}),t.jsx(T,{}),t.jsx(R,{title:"Actions",children:t.jsx(Mt,{items:zt})}),t.jsx(T,{}),t.jsx(R,{title:"Auto-sync",children:t.jsx(Wt,{items:Yt})})]})}const Jt="date_failed",Qt="failed_brand_payments";async function Xt(e=null,n=10,o=Jt,r=!0,d="",l){const m=E(k,Qt);let u=S(m);if(l&&l.length>0){const w=l.map(A=>D("status","==",A));u=S(u,et(...w))}d&&(u=S(u,D("brand_name",">=",d),D("brand_name","<=",`${d}`))),u=S(u,vt(o,r?"desc":"asc"),Dt(n)),e&&(u=S(u,Pt(e)));const C=await Rt(u);return{chargeBrands:C.docs.map(w=>({...w.data(),id:w.id})),lastVisible:C.empty?null:C.docs[C.docs.length-1]}}const ot="failed_brand_payments";async function Zt(e,n){const o=E(k,ot);let r=S(o);if(n&&n.length>0){const l=n.map(m=>D("status","==",m));r=S(r,et(...l))}return(await st(r)).data().count}async function te(){const e=E(k,ot),n=["pending","final","paid","written_off"],o=await Promise.all(n.map(async d=>{const l=S(e,D("status","==",d)),m=await st(l);return[d,m.data().count]}));return{all:o.reduce((d,[,l])=>d+l,0),...Object.fromEntries(o)}}function ee({title:e}){const{isDesc:n,sortBy:o,handleSort:r}=jt("date_failed","desc"),[d,l]=i.useState([]),[m,u]=i.useState(p.ALL),[C,H]=i.useState({[p.ALL]:0,[p.PENDING]:0,[p.FINAL]:0,[p.PAID]:0,[p.WRITTEN_OFF]:0}),[w,A]=i.useState(!0),[b,y]=i.useState(null),[v,$]=i.useState(!1),[it,M]=i.useState(!1),[I,rt]=i.useState(0),f=i.useRef([]),F=i.useRef(!1),{showNotification:lt}=St(),{postedTableProps:G,propsForRequest:q,setPage:_}=At(z),{page:P,onPageChange:V,resetPage:dt}=G,{rowsPerPage:x,lastVisible:ct,setLastVisible:ut,setTotalCount:ft,setIsLoading:U}=q;async function z({reset:s=!1}){U(!0);try{const a=m===p.ALL?void 0:[m],{chargeBrands:c,lastVisible:j}=await Xt(s?null:ct,x,o,n,"",a);l(N=>{const K=s?c:[...N,...c];return f.current=K,K}),ut(j);const Y=await Zt("",a);if(ft(Y),rt(Y),s){const N=await te();H(N),A(!1)}}catch{lt("Failed to load charge brands",{variant:"error"})}finally{U(!1)}}i.useEffect(()=>{dt(),z({reset:!0})},[x,o,n,m]);const pt=i.useCallback(s=>{u(s)},[]),mt=i.useCallback((s,a)=>
1{l(c=>c.map(j=>j.id===s?{...j,status:a}:j)),y(c=>c?.id===s?{...c,status:a}:c)},[]),ht=i.useCallback(s=>{l(a=>a.map(c=>c.id===s.id?s:c)),y(s)},[]),g=b?f.current.findIndex(s=>s.id===b.id):-1;i.useEffect(()=>{if(!F.current||!b)return;const a=f.current.findIndex(c=>c.id===b.id)+1;a<f.current.length&&(F.current=!1,y(f.current[a]),_(Math.floor(a/x)))},[d.length]);const L=i.useCallback(()=>{if(g<=0)return;const s=f.current[g-1];y(s);const a=Math.floor((g-1)/x);a!==P&&_(a)},[g,P,x,_]),B=i.useCallback(()=>{const s=g+1;if(s<f.current.length){y(f.current[s]);const a=Math.floor(s/x);a!==P&&_(a)}else f.current.length<I&&(F.current=!0,V(Math.floor(s/x)))},[g,P,x,I,V,_]);i.useEffect(()=>{if(!v)return;const s=a=>{(a.key==="ArrowLeft"||a.key==="ArrowUp")&&L(),(a.key==="ArrowRight"||a.key==="ArrowDown")&&B()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[v,L,B]);const bt=d.map((s,a)=>({...s,id:s.id||`row-${a}`}));return t.jsxs(Ct,{maxWidth:"xl",sx:{paddingTop:3},children:[t.jsxs(Q,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[t.jsx(tt,{variant:"h4",children:e}),t.jsx(xt,{onClick:()=>M(!0),sx:{color:"text.disabled",p:.5},children:t.jsx(_t,{sx:{fontSize:18}})})]}),t.jsx(Ft,{selectedFilter:m,onFilterSelect:pt,itemCounts:C,itemColors:W(),itemLabels:Bt,isLoading:w}),t.jsx(gt,{sx:{width:"100%",overflow:"hidden",borderRadius:"16px",border:"1px solid #e0e0e0"},children:t.jsx(Q,{sx:{display:"flex",flexDirection:"column",width:"100%"},children:t.jsx(It,{border:!1,tableData:bt,maxHeight:"calc(100vh - 339.5px)",...G,...q,TableRowComponent:({row:s})=>t.jsx(Gt,{row:s,onOpenDrawer:a=>{y(a),requestAnimationFrame(()=>$(!0))},isActive:v&&b?.id===s.id},s.id),TableRowSkeleton:()=>t.jsx(qt,{}),TableHeaderComponent:()=>t.jsx(Lt,{isDesc:n,sortBy:o,handleSort:r,isSortingAvailable:!0,postedSortableHeaderData:O,stickyLastCell:!0})})})}),b&&t.jsx(kt,{open:v,onClose:()=>$(!1),row:d.find(s=>s.id===b.id)??b,onStatusChange:mt,onRowUpdate:ht,onPrev:L,onNext:B,hasPrev:g>0,hasNext:g<f.current.length-1||f.current.length<I}),t.jsx(Kt,{open:it,onClose:()=>M(!1)})]})}const se={title:`Charge Brands | Dashboard - ${yt.appName}`};function Te(){return t.jsxs(t.Fragment,{children:[t.jsx(wt,{children:t.jsx("title",{children:se.title})}),t.jsx(ee,{title:"Charge Brands"})]})}export{Te 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.