1import{r as l,aj as g,p as t,w as b,T as m,B as H,bF as N,L as o,S as O,aZ as V,a_ as _,x as F,y as z,bj as G}from"./index-C9IH3k-2.js";import{T as I,g as K,N as Z,aT as q}from"./TemplateUtil-D1DzmWLm.js";import{P as J}from"./PageDescription-BrOUsEZE.js";import{F as Q}from"./Table-isZ0WXp4.js";import{S as X}from"./index-8jSYgZzf.js";import"./Wrapper-ChjuDa3w.js";import"./HelperMethods-C-ewwU_x.js";import"./index-BOwvFOZJ.js";import"./Pagination-D1z-xPUv.js";import"./HolderOutlined-YOHjCGKZ.js";const f={paymentConfigs:"/api/v1/admin/reseller/paymentConfigs",paymentConfig:"/api/v1/admin/reseller/paymentConfig"},c=[{field:"showPlan",title:"Plans Page",on:"Visible",off:"Hidden",tag:"For this reseller's customers"},{field:"showWaWalletAddBalance",title:"WhatsApp Wallet",on:"Visible",off:"Hidden",tag:"For this reseller's customers"},{field:"showAiWalletAddBalance",title:"AI Wallet",on:"Visible",off:"Hidden",tag:"For this reseller's customers"},{field:"showUpgradePlan",title:"Upgrade & Add-ons",on:"Allowed",off:"Blocked",tag:"For the reseller itself"}],de=()=>{const[d,A]=l.useState([]),[y,h]=l.useState([]),[P,x]=l.useState(!1),[u,R]=l.useState(""),[i,w]=l.useState(null),[k,j]=l.useState(null),[U,T]=l.useState(!1),[p]=g.useForm(),S=async()=>{try{const e=await F(f.paymentConfigs);h(e?.data||[])}catch(e){console.error("Error fetching reseller payment configs:",e),h([])}},W=async()=>{x(!0);const[e]=await Promise.allSettled([q(),S()]);A(e.status==="fulfilled"?e.value?.data||[]:[]),x(!1)};l.useEffect(()=>{W()},[]);const v=l.useMemo(()=>{const e=new Map(y.map(s=>[s.resellerId,s]));return d.map(s=>{const r=e.get(s.id),n={resellerId:s.id,username:s.username,lastUpdateTime:r?.lastUpdateTime||r?.creationTime||null};return c.forEach(({field:a})=>{n[a]=r?.[a]!==!1}),n})},[d,y]),B=l.useMemo(()=>d.map(e=>e.username).filter(Boolean).sort((e,s)=>e.localeCompare(s)).map(e=>({label:e,value:e})),[d]),L=u?v.filter(e=>e.username===u):v,M=async e=>{j(e.resellerId);try{const r=(await F(f.paymentConfigs))?.data||[];h(r);const n=r.find(a=>a.resellerId===e.resellerId);w(e),p.setFieldsValue(Object.fromEntries(c.map(({field:a})=>[a,n?.[a]!==!1])))}catch(s){console.error("Error loading reseller payment config:",s)}finally{j(null)}},C=()=>{w(null),p.resetFields()},$=async e=>{T(!0);try{const s={resellerId:i.resellerId};c.forEach(({field:r})=>{s[r]=e[r]!==!1}),await z(f.paymentConfig,s),G.success({title:"Success",description:`Updated controls for ${i.username}.`}),await S(),C()}catch(s){console.error("Error saving reseller payment config:",s)}finally{T(!1)}},D=[{title:"Reseller Name",dataIndex:"username",key:"username",fixed:"left",sorter:(e,s)=>(e.username||"").localeCompare(s.username||"")},...c.map(({field:e,title:s,on:r,off:n,tag:a})=>({title:t.jsx(b,{title:`${a}.`,children:s}),key:e,align:"center",width:160,render:(Y,E)=>t.jsx(I,{color:E[e]?"green":"red",children:E[e]?r:n})})),{title:"Last Updated",key:"lastUpdateTime",sorter:(e,s)=>new Date(e.lastUpdateTime||0)-new Date(s.lastUpdateTime||0),render:(e,s)=>t.jsx(m.Text,{children:s.lastUpdateTime?K(s.lastUpdateTime):"â"})},{title:"Action",key:"action",align:"center",width:100,render:(e,s)=>t.jsx(b,{title:"Edit this reseller's controls",children:t.jsx(H,{size:"small",icon:t.jsx(N,{}),loading:k===s.resellerId,onClick:()=>M(s),children:"Edit"})})}];return t.jsxs(o,{vertical:!0,gap:"middle",children:[t.jsx(m.Title,{level:4,style:{margin:0},children:"Reseller Feature Controls"}),t.jsx(J,{description:"What is this page?",children:`Every reseller is listed here with what its customers can currently see â the subscription plans page, and the WhatsApp / AI wallet "Add Balance" buttons â plus whether the reseller itself may upgrade its customers' plans at the prorated price or assign add-ons to them. The list is read only; use Edit on a row to change it. Everything is permitted by default, so a reseller you have never edited shows all green.`}),t.jsx(o,{justify:"space-between",align:"center",wrap:!0,gap:"middle",children:t.jsx(O,{showSearch:!0,allowClear:!0,placeholder:"Search reseller by name",suffixIcon:t.jsx(V,{}),value:u||void 0,onChange:e=>R(e||""),options:B,optionFilterProp:"label",style:{width:320,maxWidth:"100%"}})}),t.jsx(Q,{columns:D,dataSource:L,rowKey:"resellerId",loading:P,pagination:{defaultPageSize:10,showSizeChanger:!0,showTotal:e=>`Total ${e} resellers`},scroll:{x:"max-content"},locale:{emptyText:t.jsx(_,{description:"No resellers found."})}}),t.jsxs(Z,{title:i?`Edit controls â ${i.username}`:"Edit controls",open:!!i,onOk:()=>p.submit(),onCancel:C,okText:"Save",confirmLoading:U,forceRender:!0,children:[t.jsx(m.Paragraph,{type:"secondary",style:{marginBottom:16},children:"Turn a switch off to restrict it. Turning everything back on clears this reseller's record."}),t.jsx(g,{form:p,onFinish:$,children:t.jsx(o,{vertical:!0,gap:16,children:c.map(({field:e,title:s,on:r,off:n,tag:a})=>
1t.jsxs(o,{justify:"space-between",align:"flex-start",gap:"middle",children:[t.jsx(o,{vertical:!0,gap:2,style:{flex:1},children:t.jsxs(o,{align:"center",gap:"small",wrap:!0,children:[t.jsx(m.Text,{strong:!0,children:s}),t.jsx(I,{style:{marginInlineEnd:0},children:a})]})}),t.jsx(g.Item,{name:e,valuePropName:"checked",style:{margin:0},children:t.jsx(X,{checkedChildren:r,unCheckedChildren:n})})]},e))})})]})]})};export{de 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.