1import{j as e,B as s,A as a,b as r,T as t,G as n,d5 as i,bo as l,af as d,ag as c,ak as o,a6 as p,al as x,am as h,an as j,ao as m,ap as u,I as g,E as y,x as f,aq as b,C as k}from"./DYw7LMfG.js";import{a as v,b as C}from"./UqzzAnT4.js";import{y as S}from"./BFMbySPq.js";import{u as U,b as w}from"./DNA11vdE.js";import"./DXvvCRrN.js";const R=e=>{if(!e)return"â";return new Date(e).toLocaleString()},A=()=>{const{user:A}=U(),[z,B]=v.useState(!0),[I,F]=v.useState(!1),[E,P]=v.useState(!1),[T,W]=v.useState([]),[_,q]=v.useState(0),[D,G]=v.useState(null),[L,N]=v.useState(null),O=Boolean(A?.isSuperAdmin),X=v.useCallback(async()=>{if(O)try{F(!0),G(null);const e=await w.get("/payments/admin/expired-plan-check-reports",{params:{limit:50,skip:0}});e.data?.success&&(W(e.data.reports||[]),q(e.data.total??0))}catch(e){G(e.response?.data?.message||e.message||"Failed to load reports")}finally{B(!1),F(!1)}},[O]);return v.useEffect(()=>{X()},[X]),O?z?e.jsx(s,{sx:{display:"flex",justifyContent:"center",p:3},children:e.jsx(r,{})}):e.jsxs(s,{children:[e.jsxs(s,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3,flexWrap:"wrap",gap:1},children:[e.jsx(t,{variant:"h4",sx:{fontSize:{xs:"1.25rem",md:"2.125rem"}},children:"Expired Plan Check Reports"}),e.jsxs(s,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:[e.jsx(n,{variant:"contained",color:"primary",startIcon:E?e.jsx(r,{size:20,color:"inherit"}):e.jsx(i,{}),onClick:async()=>{if(O&&!E)try{P(!0),G(null);const e=await w.post("/payments/check-expired-plans");e.data?.success?(S.success(e.data.message??"Check completed."),await X()):S.error(e.data?.message??"Check failed.")}catch(e){const s=e.response?.data?.message||e.message||"Failed to run expired plan check";G(s),S.error(s)}finally{P(!1)}},disabled:E,children:E?"Running...":"Run check now"}),e.jsx(n,{variant:"outlined",startIcon:e.jsx(l,{}),onClick:X,disabled:I,children:I?"Refreshing...":"Refresh"})]})]}),e.jsx(t,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"Results of POST /payments/check-expired-plans (Stripe + Apple fallback). Each run is recorded here."}),D&&e.jsx(a,{severity:"error",sx:{mb:2},onClose:()=>G(null),children:D}),0===T.length?e.jsx(d,{children:e.jsx(c,{children:e.jsx(t,{color:"text.secondary",children:"No expired plan check reports yet. Run check-expired-plans (e.g. via cron or manually) to create records."})})}):e.jsx(o,{component:p,sx:{overflowX:"auto"},children:e.jsxs(x,{size:"small",sx:{minWidth:700},children:[e.jsx(h,{children:e.jsxs(j,{children:[e.jsx(m,{width:48}),e.jsx(m,{children:"Run at"}),e.jsx(m,{children:"Run by"}),e.jsx(m,{align:"right",children:"Stripe checked"}),e.jsx(m,{align:"right",children:"Stripe updated"}),e.jsx(m,{align:"right",children:"Apple checked"}),e.jsx(m,{align:"right",children:"Apple updated"}),e.jsx(m,{align:"right",children:"Total updated"})]})}),e.jsx(u,{children:T.map(a=>{const r=L===a._id,n=a.runByUserId,i="object"==typeof n&&n?.email?n.email:a.runByUserId??"â";return e.jsxs(C.Fragment,{children:[e.jsxs(j,{hover:!0,children:[e.jsx(m,{children:e.jsx(g,{size:"small",onClick:()=>N(r?null:a._id),children:r?e.jsx(y,{}):e.jsx(f,{})})}),e.jsx(m,{children:R(a.runAt)}),e.jsx(m,{children:i}),e.jsx(m,{align:"right",children:a.stripeChecked??0}),e.jsx(m,{align:"right",children:e.jsx(b,{size:"small",label:a.stripeUpdatedCount??0,color:(a.stripeUpdatedCount??0)>0?"primary":"default"})}),e.jsx(m,{align:"right",children:a.appleChecked??0}),e.jsx(m,{align:"right",children:e.jsx(b,{size:"small",label:a.appleUpdatedCount??0,color:(a.appleUpdatedCount??0)>0?"secondary":"default"})}),e.jsx(m,{align:"right",children:e.jsx("strong",{children:a.totalUpdated??0})})]}),e.jsx(j,{children:e.jsx(m,{colSpan:8,sx:{py:0,borderBottom:0},children:e.jsx(k,{in:r,timeout:"auto",children:e.jsxs(s,{sx:{py:2,pl:2},children:[a.message&&e.jsx(t,{variant:"body2",sx:{mb:1},children:a.message}),a.stripeUpdatedUsers?.length>0&&e.jsx(t,{variant:"subtitle2",sx:{mt:1},children:"Stripe updated:"}),a.stripeUpdatedUsers?.map((s,a)=>e.jsxs(t,{variant:"body2",component:"div",sx:{pl:2,fontFamily:"monospace"},children:[s.email," â ",s.newPlan," (",s.newBillingCycle,")"]},a)),a.appleUpdatedUsers?.length>0&&e.jsx(t,{variant:"subtitle2",sx:{mt:1},children:"Apple set expired:"}),a.appleUpdatedUsers?.map((s,a)=>e.jsx(t,{variant:"body2",component:"div",sx:{pl:2,fontFamily:"monospace"},children:s.email},a))]})})})})]},a._id)})})]})}),_>T.length&&e.jsxs(t,{variant:"body2",color:"text.secondary",sx:{mt:2},children:["Showing ",T.length," of ",_," reports."]})]}):e.jsx(s,{sx:{p:3},children:e.jsx(a,{severity:"error",children:"Access denied. Super admin privileges required."})})};export{A 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.