1import{aj as o,r as i,p as e,L as P,T as n,w as b,B as g,b2 as D,ag as oe,S as C,x as O,y as Y,bj as y,A as K,br as Ie,D as Ce,C as we,ak as Te,a0 as J,a1 as r,v as se,N as m,a$ as Ae,aq as We,b0 as Pe,a_ as Fe,b1 as ne,R as Ne}from"./index-C9IH3k-2.js";import{I as w,a2 as X,T as R,N as W,W as u,g as Q}from"./TemplateUtil-D1DzmWLm.js";import ve from"./PaymentOverview-C5qcWR99.js";import Se from"./PaymentStatus-CAgnu4_k.js";import Be from"./Audit-Ck3wU_mb.js";import{P as De}from"./PhoneFeature-D7MHCLCP.js";import{P as Re}from"./PhoneFeatureTag-Dkd4EtBQ.js";import Ee from"./Transaction-t3lowlRg.js";import{G as re,b as le,W as ie}from"./MainApp-BoiAvjMg.js";import{R as Ue}from"./UserSwitchOutlined--6-IKbBL.js";import"./Wrapper-ChjuDa3w.js";import"./HelperMethods-C-ewwU_x.js";import"./AuditConstant-C6syQHOu.js";import"./index-CmSVNJzc.js";import"./index-Bv3SRNsl.js";import"./CalendarOutlined-DyzsKNdO.js";import"./ClockCircleOutlined-Cym7vptW.js";import"./WalletPointsFilter-D06q_Gh8.js";import"./Table-isZ0WXp4.js";import"./index-BOwvFOZJ.js";import"./Pagination-D1z-xPUv.js";import"./HolderOutlined-YOHjCGKZ.js";import"./index-1obnpDkF.js";import"./index-DNqpjC0Z.js";import"./ArrowUpOutlined-BhfGhE4E.js";import"./ArrowDownOutlined-Lx40NDq8.js";const Le=({customerDetails:d})=>{const[s]=o.useForm(),[G,F]=i.useState(!1),[M,N]=i.useState(!1),[f]=o.useForm(),[q,T]=i.useState(!1),[x,v]=i.useState(!1),[j,z]=i.useState(null),E=async c=>{N(!0);try{const h=await Y("/api/v1/admin/addResellerWalletPoints",{customerId:d.id,walletPoints:c.walletPoints,comment:c.comment});h?.status===200&&(y.success({message:"Success",description:h.data?.message}),s.resetFields(),F(!1))}catch{y.error({message:"Error",description:"Failed to update wallet points."})}finally{N(!1)}},I=async c=>{v(!0);try{const h=await K("/api/v1/admin/waWallet/reseller/addBalance",{resellerId:d.id,type:c.type,amount:c.amount});h?.status===200&&(y.success({message:"Success",description:h.data?.message}),f.resetFields(),T(!1))}catch{y.error({message:"Error",description:"Failed to update WA balance."})}finally{v(!1)}};return i.useEffect(()=>{const c=async()=>{try{const h=await O(`/api/v1/admin/waWallet/reseller/${d.id}`);h?.status===200&&z(h.data)}catch(h){console.error("Failed to fetch WhatsApp balance:",h)}};d?.id&&c()},[d?.id]),e.jsxs(e.Fragment,{children:[e.jsx(w,{children:e.jsxs(P,{justify:"space-between",align:"center",wrap:!0,gap:"middle",children:[e.jsxs(P,{align:"center",gap:"small",children:[e.jsx(n.Title,{level:5,style:{margin:0},children:"Reseller Management"}),e.jsx(X,{orientation:"vertical"}),e.jsx(b,{title:"Wallet Points",children:e.jsx(R,{color:re(d?.walletPoints),icon:e.jsx(le,{}),children:d?.walletPoints??"-"})}),e.jsx(b,{title:"WA Wallet Balance",children:e.jsxs(R,{color:re(j?.balance),icon:e.jsx(ie,{}),children:[j?.currency," ",j?.balance??"-"]})})]}),e.jsxs(P,{gap:"small",children:[e.jsx(g,{icon:e.jsx(le,{}),onClick:()=>F(!0),children:"Update Wallet Points"}),e.jsx(g,{icon:e.jsx(ie,{}),onClick:()=>T(!0),children:"Add WA Balance"})]})]})}),e.jsx(W,{title:`Update Wallet Points â ${d?.username}`,open:G,onOk:()=>s.submit(),onCancel:()=>{F(!1),s.resetFields()},okText:"Update",confirmLoading:M,width:500,children:e.jsxs(o,{form:s,layout:"vertical",onFinish:E,children:[e.jsx(o.Item,{name:"walletPoints",label:"Wallet Points",rules:[{required:!0,message:"Please enter wallet points!"},{type:"number",message:"Please enter a valid number"}],children:e.jsx(D,{style:{width:"100%"},placeholder:"Positive to add, negative to deduct",formatter:c=>`${c}`.replace(/\B(?=(\d{3})+(?!\d))/g,","),parser:c=>c.replace(/\$\s?|(,*)/g,"")})}),e.jsx(o.Item,{name:"comment",label:"Comment",rules:[{required:!0,message:"Please enter a comment!"},{max:500,message:"Max 500 characters"}],children:e.jsx(oe.TextArea,{rows:3,placeholder:"Reason for adjustment",showCount:!0,maxLength:500})})]})}),e.jsx(W,{title:`Add WhatsApp Balance â ${d?.username}`,open:q,onOk:()=>f.submit(),onCancel:()=>{T(!1),f.resetFields()},okText:"Submit",confirmLoading:x,width:400,children:e.jsxs(o,{form:f,layout:"vertical",initialValues:{type:"CREDIT"},onFinish:I,children:[e.jsx(o.Item,{name:"type",label:"Type",rules:[{required:!0}],children:e.jsx(C,{options:[{label:"Credit",value:"CREDIT"},{label:"Debit",value:"DEBIT"}]})}),e.jsx(o.Item,{name:"amount",label:"Amount",rules:[{required:!0,message:"Please enter amount!"},{type:"number",min:.01,message:"Amount must be greater than 0"}],children:e.jsx(D,{style:{width:"100%"},placeholder:"Enter amount",min:.01,formatter:c=>`${c}`.replace(/\B(?=(\d{3})+(?!\d))/g,","),parser:c=>c.replace(/\$\s?|(,*)/g,"")})})]})})]})},dt=()=>{const{id:d}=Ie(),[s,G]=i.useState(null),[F,M]=i.useState(!0),[N,f]=i.useState({}),[q,T]=i.useState({}),[x,v]=i.useState({}),[j]=o.useForm(),[z,E]=i.useState(!1),[I]=o.useForm(),[c,h]=i.useState(!1),[k,ce]=i.useState([]),[de,Z]=i.useState(!1),[pe,ee]=i.useState(null),me=Ce();i.useEffect(()=>{(async()=>
1{if(!s?.wabaTokens)return;s.wabaTokens.forEach(async l=>{if(l.phoneNumberId)try{const p=await O(`/api/v1/admin/phoneNumber/profile/${l.phoneNumberId}`,!1);v(S=>({...S,[l.phoneNumberId]:p?.data}))}catch(p){v(S=>({...S,[l.phoneNumberId]:{error:!0,errorDetail:p?.response?.data?.detail||"Unknown error occurred"}}))}})})()},[s]);const U=we();i.useEffect(()=>{d&&(async()=>{try{const a=await O(`/api/v1/admin/customer/${d}`);G(a?.data)}catch(a){console.error("Error fetching customer data:",a)}finally{M(!1)}})()},[d]);const he=async t=>{ee(t);try{const a=await Y("/api/v1/admin/getTokenForUser",JSON.stringify({username:t}));if(a.status===200){Ae({userName:t,token:a.data.token,authState:!0});const l=We(a.data.token);await Pe(me,window.location.pathname,U,l),U("/")}}catch(a){m.error(a.response?.data?.message||a.message||"Failed to switch user")}finally{ee(null)}},ue=async()=>{Z(!0);try{const t=await Y("/api/v1/admin/agents",{search:[{fieldName:"customerId",value:[d]}],pagination:{current:1,pageSize:50}});t?.status===200&&ce(t.data?.results||[])}catch{m.error("Failed to fetch agents")}finally{Z(!1)}},xe=t=>{U("/Subscription",{state:{customerDetails:s,customerId:d,selectedToken:t}})},je=async t=>{T(a=>({...a,[t]:!0}));try{const a=await O(`/api/v1/admin/getWchatter/${t}`);f(l=>({...l,[t]:a?.data}))}catch{m.error("Failed to fetch wChatter report"),f(l=>({...l,[t]:null}))}finally{T(a=>({...a,[t]:!1}))}},be=t=>{W.confirm({title:`Add WA Wallet Balance for ${t}`,width:500,content:e.jsxs(o,{form:j,layout:"vertical",initialValues:{phoneNumberId:t},onFinish:async a=>{try{E(!0);const l={phoneNumberId:t,amount:a.amount,type:a.type||"CREDIT"},p=await K("/api/v1/admin/waWallet/addBalance",l,!1);p.status===200&&(y.success({message:"Success",description:`Balance updated successfully. New balance: ${p.data?.balance} ${p.data?.currency||""}`}),j.resetFields(),W.destroyAll())}catch{y.error({message:"Error",description:"Failed to update WA wallet balance. Please try again."})}finally{E(!1)}},children:[e.jsx(o.Item,{name:"type",label:"Transaction Type",initialValue:"CREDIT",children:e.jsxs(C,{children:[e.jsx(C.Option,{value:"CREDIT",children:"Credit"}),e.jsx(C.Option,{value:"DEBIT",children:"Debit"})]})}),e.jsx(o.Item,{name:"amount",label:"amount",rules:[{required:!0,message:"Please input amount!"}],children:e.jsx(D,{style:{width:"100%"},placeholder:"Enter amount to add to wallet"})})]}),okText:"Add Amount",cancelText:"Cancel",okButtonProps:{loading:z},async onOk(){try{await j.validateFields(),j.submit()}catch{return Promise.reject()}},onCancel(){j.resetFields()}})},ge=t=>{W.confirm({title:`Add AI Credits for ${t}`,width:520,content:e.jsxs(o,{form:I,layout:"vertical",initialValues:{phoneNumberId:t,type:"CREDIT"},onFinish:async a=>{try{h(!0);const l={phoneNumberId:t,type:a.type||"CREDIT",amount:a.amount,...a.postGstAmount!==void 0&&a.postGstAmount!==null?{postGstAmount:a.postGstAmount}:{},...a.comment?{comment:a.comment}:{}},p=await K("/api/v1/admin/aiWallet/addBalance",l,!1);p?.status===200&&(y.success({message:"Success",description:`AI Credits updated. New balance: ${p.data?.balance??"?"} ${p.data?.currency||""}`}),I.resetFields(),W.destroyAll())}catch{y.error({message:"Error",description:"Failed to update AI Credits balance. Please try again."})}finally{h(!1)}},children:[e.jsx(o.Item,{name:"type",label:"Transaction Type",initialValue:"CREDIT",children:e.jsxs(C,{children:[e.jsx(C.Option,{value:"CREDIT",children:"Credit"}),e.jsx(C.Option,{value:"DEBIT",children:"Debit"})]})}),e.jsx(o.Item,{name:"amount",label:"Amount (wallet balance â¹)",rules:[{required:!0,message:"Please input amount"}],tooltip:"The figure that actually hits aiWallet.balance",children:e.jsx(D,{style:{width:"100%"},placeholder:"e.g. 500.00",min:0})}),e.jsx(o.Item,{name:"postGstAmount",label:"Post-GST Amount (â¹, optional)",tooltip:"What the customer actually paid including GST â kept for tax invoicing",children:e.jsx(D,{style:{width:"100%"},placeholder:"e.g. 590.00",min:0})}),e.jsx(o.Item,{name:"comment",label:"Comment (optional)",children:e.jsx(oe.TextArea,{rows:2,placeholder:"e.g. Initial top-up via bank transfer",maxLength:300,showCount:!0})})]}),okText:"Apply",cancelText:"Cancel",okButtonProps:{loading:c},async onOk(){try{await I.validateFields(),I.submit()}catch{return Promise.reject()}},onCancel(){I.resetFields()}})},ye=()=>!s?.wabaTokens||s.wabaTokens.length===0?e.jsx(Fe,{description:e.jsx(n.Text,{type:"secondary",children:"No phone numbers available."})}):e.jsx(ne,{children:s.wabaTokens.map((t,a)=>e.jsxs(ne.Panel,{header:e.jsxs(P,{justify:"space-between",children:[e.jsx(n.Text,{strong:!0,copyable:{text:t.displayPhoneNumber,onCopy:()=>m.success("Copied to clipboard")},children:t.displayPhoneNumber}),t.phoneFeature&&t.phoneFeature.activeUpto&&e.jsx(Re,{planName:t.phoneFeature.planName,planSlug:t.phoneFeature.planSlug,activeUpto:t.phoneFeature.activeUpto}),e.jsxs(n.Text,{copyable:{text:t.phoneNumberId,onCopy:()=>m.success("Copied to clipboard")},children:["Phone Number Id: ",e.jsx(R,{color:"blue",children:t.phoneNumberId})]})]}),children:[e.jsxs(J,{gutter:[16,16],children:[e.jsx(r,{span:12,children:e.jsx(b,{title:"WhatsApp Business Account ID",children:e.jsxs(n.Text,{copyable:{text:t.whatsappBusinessAccountId,onCopy:()=>m.success("Copied to clipboard")},children:[e.jsx("strong",{children:"Whatsapp Business Account ID:"})," ",t.whatsappBusinessAccountId]})})}),e.jsx(r,{span:12,children:e.jsx(b,{title:"Business ID associated with this number",children:e.jsxs(n.Text,{copyable:{text:t.businessId,onCopy:()=>m.success("Copied to clipboard")},children:[e.jsx("strong",{children:"Business Portfolio ID:"})," ",t.businessId]})})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Creation Time:"})," ",Q(t.creationTime)]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Last Update Time:"})," ",Q(t.lastUpdateTime)]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Profile Name:"}),x[t.phoneNumberId]?.verified_name||"N/A"]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Quality Rating:"}),x[t.phoneNumberId]?.quality_rating||"No rating data"]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Account Mode:"}),x[t.phoneNumberId]?.account_mode||"No mode data"]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Daily Messaging Limit:"}),x[t.phoneNumberId]&&(x[t.phoneNumberId]?.whatsapp_business_manager_messaging_limit||x[t.phoneNumberId]?.messaging_limit_tier)||"No limit data"]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Number Type:"}),x[t.phoneNumberId]?x[t.phoneNumberId]?.is_on_biz_app===!0?"SMB":x[t.phoneNumberId]?.is_on_biz_app===!1?"Cloud":"":""]})}),e.jsx(r,{span:24,children:e.jsxs(se,{wrap:!0,children:[e.jsx(b,{title:"Activate or update the plan",children:e.jsx(g,{type:"primary",onClick:()=>xe(t),children:"Update Plan"})}),e.jsx(b,{title:"Check Report",children:e.jsx(g,{type:"primary",onClick:()=>U("/Reporting/MessageReport",{state:{Id:t.phoneNumberId}}),children:"Report"})}),e.jsx(b,{title:"Get WChatter details",children:e.jsx(g,{type:"primary",onClick:()=>je(t.phoneNumberId),loading:q[t.phoneNumberId],children:"WChatter Details"})}),e.jsx(b,{title:"Add balance to WA Wallet",children:e.jsx(g,{type:"primary",onClick:()=>be(t.phoneNumberId),children:"Add WA Balance"})}),e.jsx(b,{title:"Add AI Credits balance",children:e.jsx(g,{type:"primary",onClick:()=>ge(t.phoneNumberId),children:"Add AI Balance"})})]})})]}),N[t.phoneNumberId]&&(()=>{const l=N[t.phoneNumberId]||{},p=l.platformConfig||{},S=Array.isArray(l.userConfig)?l.userConfig:[],te=l.inboxConfig||{},$=p.wchatterSiteUrl||"",B=p.accountId||"",_=$&&B?`${$}/app/accounts/${B}/dashboard`:"",V=te.inboxId||"",H=$&&B&&V?`${$}/app/accounts/${B}/settings/inboxes/${V}`:"",ae=te.webhookUrl||"";return e.jsxs(e.Fragment,{children:[e.jsx(X,{children:"WChatter Details"}),e.jsxs(u,{bordered:!0,size:"small",column:3,children:[e.jsx(u.Item,{label:"Site URL",span:3,children:e.jsx(n.Text,{copyable:{text:_,onCopy:()=>m.success("URL copied")},children:_?e.jsx("a",{href:_,target:"_blank",rel:"noopener noreferrer",children:_}):""})}),e.jsx(u.Item,{label:"Inbox URL",span:3,children:H?e.jsx("a",{href:H,target:"_blank",rel:"noopener noreferrer",children:H}):""}
1),e.jsx(u.Item,{label:"Webhook URL",span:3,children:e.jsx(n.Text,{copyable:{text:ae,onCopy:()=>m.success("Webhook URL copied")},children:ae})}),e.jsx(u.Item,{label:"Company/Account ID",children:B}),e.jsx(u.Item,{label:"Company Name",children:p.companyName||""}),e.jsx(u.Item,{label:"Inbox ID",children:V}),S.map((A,fe)=>e.jsxs(Ne.Fragment,{children:[e.jsx(u.Item,{label:"User ID",children:A?.id||""}),e.jsx(u.Item,{label:"Username",children:e.jsx(n.Text,{copyable:{text:A?.username||"",onCopy:()=>m.success("Username copied")},children:A?.username||""})}),e.jsx(u.Item,{label:"Name of user",children:A?.name||""}),e.jsx(u.Item,{label:"Email",children:e.jsx(n.Text,{copyable:{text:A?.email,onCopy:()=>m.success("Email copied")},children:A?.email})})]},fe))]})]})})(),t.phoneFeature&&e.jsx(De,{feature:t.phoneFeature,registred:t?.active})]},a))});if(F)return e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:e.jsx(Te,{size:"large"})});const L={customerId:d,tableSize:"small"};return e.jsxs(P,{vertical:!0,gap:"large",children:[e.jsx(P,{justify:"space-between",children:e.jsx(n.Title,{level:4,style:{margin:0},children:"Customer Detail"})}),e.jsxs(J,{gutter:[24,24],children:[e.jsx(r,{span:24,children:e.jsx(w,{children:e.jsx(se,{orientation:"vertical",size:"middle",style:{width:"100%"},children:s&&e.jsxs(J,{gutter:[16,16],children:[e.jsx(r,{span:12,children:e.jsxs(n.Text,{copyable:{text:s.username,onCopy:()=>m.success("Copied to clipboard")},children:[e.jsx("strong",{children:"Username:"})," ",s.username]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{copyable:{text:s.phoneNumber,onCopy:()=>m.success("Copied to clipboard")},children:[e.jsx("strong",{children:"Phone Number:"})," ",s.phoneNumber]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{copyable:{text:s.email,onCopy:()=>m.success("Copied to clipboard")},children:[e.jsx("strong",{children:"Email:"})," ",s.email]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Type:"})," ",s.type]})}),e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Active:"})," ",s.active?"Yes":"No"]})}),s.reseller&&e.jsx(r,{span:12,children:e.jsxs(n.Text,{children:[e.jsx("strong",{children:"Reseller:"})," ",s.reseller.username]})}),e.jsx(r,{span:24,children:e.jsx(g,{loading:de,onClick:ue,children:"Fetch Agents"})}),k.length>0&&e.jsxs(r,{span:24,children:[e.jsxs(X,{orientation:"left",children:["Agents (",k.length,")"]}),k.map(t=>e.jsx(u,{size:"small",column:{xs:1,sm:2,md:3},style:{marginBottom:8},items:[{label:"Username",children:e.jsx(n.Text,{copyable:!0,strong:!0,children:t.username})},{label:"Name",children:t.name||"-"},{label:"Email",children:t.email||"-"},{label:"Role",children:t.role},{label:"Status",children:e.jsx(R,{color:t.active?"green":"red",children:t.active?"Active":"Inactive"})},{label:"Phone Number IDs",children:t.phoneNumberIds?.length>0?t.phoneNumberIds.map(a=>e.jsx(R,{children:a},a)):"-"},{label:"Created",children:Q(t.creationTime)},{label:"Change",children:e.jsx(g,{icon:e.jsx(Ue,{}),loading:pe===t.username,onClick:()=>he(t.username),children:"Change"})}],bordered:!0},t.id))]})]})})})}),e.jsx(r,{span:24,children:s?.type==="RESELLER"?e.jsx(Le,{customerDetails:s}):e.jsx(w,{title:"Phone Numbers",children:ye()})}),e.jsx(r,{span:24,children:e.jsx(w,{children:e.jsx(Be,{...L,preFilledColumns:["customerId"]})})}),e.jsx(r,{span:24,children:e.jsx(w,{children:e.jsx(Ee,{...L,preFilledColumns:["customer"]})})}),e.jsx(r,{span:24,children:e.jsx(w,{children:e.jsx(Se,{...L,preFilledColumns:["customer.username"]})})}),e.jsx(r,{span:24,children:e.jsx(w,{children:e.jsx(ve,{...L,preFilledColumns:["customerId"]})})})]})]})};export{dt 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.