1import{r as l,j as e}from"./vendor-react-BXDKjWfl.js";import{B as me}from"./badge-BDtfWqsC.js";import{B as u}from"./button-Dde8KDtM.js";import{C as x,a as h,b as ue,c as fe}from"./card-fjvTZ4w9.js";import{D as xe,d as he,a as pe,b as je,c as ye}from"./dialog-OHBmBSaY.js";import{I}from"./input-S-mxI4AP.js";import{L as V}from"./label-kbiiXifT.js";import{P as E}from"./pagination-DGcE_InF.js";import{A as ge,S as F,a as H,b as $,c as U,d as O,T as Ne,e as be,f as C,g as S}from"./app-layout-Cl4qc2jQ.js";import{u as we}from"./app-CQYd8FmO.js";import{D as ve}from"./DataTable-bqZtHQxk.js";import{b as _e}from"./helper-C4ndmdZS.js";import{u as Ve,H as Ce,L as K,r as P}from"./vendor-inertia-Ca3DBwCx.js";import{a as Se}from"./vendor-other-OHcCBNj6.js";import{g as Pe,a as Ae}from"./payment-method-config-dSSl-X3R.js";import{u as Q}from"./vendor-i18n-QDUiSOiS.js";import{LucideTrendingUp as Me,DollarSign as Y,Clock as Te,Check as G,LucideWallet as We,Link as ke,Copy as qe,ArrowDownCircle as De,ArrowUpCircle as Le}from"./vendor-icons-tduVCsjY.js";import"./vendor-radix-D7dRWJwM.js";import"./vendor-headless-DBRk1dBw.js";import"./vendor-utils-Sp7XtC9M.js";import"./utils-DzIIg4YZ.js";import"./icon-0E0oqJO5.js";import"./sidebar-5XiAvn3f.js";import"./tooltip-Dle4dATa.js";import"./icon-BGEUBaAS.js";import"./dropdown-menu-CmNN286a.js";import"./app-logo-BTVMfI_7.js";import"./NotificationBell-CoU36plr.js";import"./vendor-echo-CtsglDNk.js";import"./ServerUpdateBanner-CdSuecKf.js";/* empty css */import"./input-vdyiKJdm.js";import"./wrapper-yjymp1gY.js";import"./notification-modal-BdayYlPd.js";import"./validator-B-5JJu-W.js";import"./dayjs-9Rt4kJN4.js";import"./confirm-dialog-CDw1xupt.js";import"./input-error-BB5qxL-U.js";import"./index-Dcn7fwJM.js";import"./date-time-range-picker-field-B_1AEpYo.js";import"./select-field-C5OgWyuK.js";import"./color-field-BdIS1FKn.js";import"./color-swatch-Dqppna59.js";import"./vendor-editor-UjQxlT0Z.js";import"./upload-field-BlXooYEB.js";import"./confirm-dialog-by-state-DmKszwwM.js";const Re=[{title:"Dashboard",href:"/dashboard"},{title:"Affiliate Portal",href:"#"}];function d(r,a){return`${a??"BDT"} ${Number(r).toFixed(2)}`}function A(r){const a=Object.entries(r);return a.length===0?"â":a.map(([o,j])=>d(j,o)).join(" / ")}function p({status:r}){const a={pending:"pending",approved:"verified",rejected:"failed",paid:"paid",credit:"verified",debit:"destructive"};return e.jsx(me,{variant:a[r]??"secondary",children:r})}function J({type:r}){return e.jsxs("span",{className:`inline-flex items-center gap-1 text-xs font-medium ${r==="credit"?"text-green-600":"text-red-600"}`,children:[r==="credit"?e.jsx(De,{className:"size-3.5"}):e.jsx(Le,{className:"size-3.5"}),r]})}function ze(){const{t:r}=Q(),a=l.useMemo(()=>Pe(),[]),o=l.useMemo(()=>Ae(),[]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:r("form.fields.managePaymentMethods",{defaultValue:"Manage your payment methods for withdrawals."})}),e.jsx(K,{href:route("affiliate.payment-methods.create"),children:e.jsx(u,{size:"sm",children:r("form.fields.addPaymentMethod",{defaultValue:"Add Payment Method"})})})]}),e.jsx(ve,{columns:a,routeNamePrefix:"affiliate.payment-methods",permissionPrefix:"",extraFiltersFields:o,isViewBtnRequired:!1,isExportBtnRequired:!1})]})}function Tt(){const{referralLink:r,balances:a,totalEarned:o,totalWithdrawn:j,pendingWithdrawals:M,histories:c,withdrawals:m,paymentMethods:y,tab:X,coupon:g}=Ve().props,{setIsLoading:Z}=we(),{t:s}=Q(),[T,ee]=l.useState(typeof window<"u"?window.innerWidth<1024:!1),[W,k]=l.useState(!1),[te,N]=l.useState(!1),[q,b]=l.useState(""),[w,D]=l.useState(""),[n,se]=l.useState(()=>a[0]?.currency_code??"BDT"),[L,i]=l.useState(null),[R,z]=l.useState(!1),[ae,v]=l.useState(!1),re=l.useRef(null);l.useEffect(()=>{Z(!1)},[]),l.useEffect(()=>{const t=()=>ee(window.innerWidth<1024);return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]);const le=()=>{navigator.clipboard.writeText(r).then(()=>{k(!0),setTimeout(()=>k(!1),2e3)})},de=async t=>{t.preventDefault(),i(null);const f=parseFloat(q);if(!f||f<=0){i("Please enter a valid amount.");return}const B=a.find(_=>_.currency_code===n);if(!B||f>
1B.balance){i("Amount exceeds your current balance.");return}if(!w){i("Please select a payment method.");return}z(!0);try{await Se.post(route("affiliate.withdraw"),{requested_amount:f,user_payment_method_id:parseInt(w),currency_code:n}),v(!0),b(""),D(""),setTimeout(()=>{N(!1),v(!1),P.reload({only:["withdrawals","balances","pendingWithdrawals"]})},1500)}catch(_){const ce=_?.response?.data?.error??"Something went wrong. Please try again.";i(ce)}finally{z(!1)}},ne=t=>{P.get(route("affiliate.dashboard"),{history_page:t},{preserveState:!0,replace:!0})},ie=t=>{P.get(route("affiliate.dashboard"),{withdrawals_page:t},{preserveState:!0,replace:!0})},oe=[{title:"Total Earned",value:A(o),icon:Me,color:"text-blue-600",bg:"bg-blue-50 dark:bg-blue-950"},{title:"Total Withdrawn",value:A(j),icon:Y,color:"text-purple-600",bg:"bg-purple-50 dark:bg-purple-950"},{title:"Pending Withdrawals",value:A(M),icon:Te,color:"text-yellow-600",bg:"bg-yellow-50 dark:bg-yellow-950"}];return e.jsxs(ge,{breadcrumbs:Re,children:[e.jsx(Ce,{title:"Affiliate Portal"}),e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:s("form.fields.affiliatePortal",{defaultValue:"Affiliate Portal"})}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("form.fields.affiliatePortalSubtitle",{defaultValue:"Earn commissions by referring new stores."})})]}),e.jsxs(xe,{open:te,onOpenChange:t=>{N(t),t||(i(null),v(!1))},children:[e.jsx(he,{asChild:!0,children:e.jsxs(u,{variant:"default",disabled:a.every(t=>t.balance<=0)||y.length===0||Object.entries(M).length!==0,children:[e.jsx(Y,{className:"size-4"}),s("form.fields.requestWithdrawal",{defaultValue:"Request Withdrawal"})]})}),e.jsxs(pe,{children:[e.jsx(je,{children:e.jsx(ye,{children:s("form.fields.requestWithdrawal",{defaultValue:"Request Withdrawal"})})}),ae?e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6 text-center",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-green-100",children:e.jsx(G,{className:"size-6 text-green-600"})}),e.jsx("p",{className:"font-medium text-green-700",children:s("form.fields.withdrawalSubmittedSuccess",{defaultValue:"Withdrawal request submitted successfully!"})})]}):e.jsxs("form",{onSubmit:de,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(V,{htmlFor:"withdraw_currency",children:s("form.fields.currency",{defaultValue:"Currency"})}),e.jsxs(F,{value:n,onValueChange:t=>{se(t),b("")},children:[e.jsx(H,{id:"withdraw_currency",children:e.jsx($,{})}),e.jsx(U,{children:a.filter(t=>t.balance>0).map(t=>e.jsxs(O,{value:t.currency_code,children:[t.currency_code," â ",d(t.balance,t.currency_code)," ",s("form.fields.available",{defaultValue:"available"})]},t.currency_code))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(V,{htmlFor:"withdraw_amount",children:s("form.fields.amount",{defaultValue:"Amount"})}),e.jsx(I,{id:"withdraw_amount",ref:re,type:"number",min:"1",step:"0.01",max:a.find(t=>t.currency_code===n)?.balance??0,value:q,onChange:t=>b(t.target.value),placeholder:`Max: ${d(a.find(t=>t.currency_code===n)?.balance??0,n)}`,required:!0})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(V,{htmlFor:"withdraw_method",children:s("form.fields.paymentMethod",{defaultValue:"Payment Method"})}),e.jsxs(F,{value:w,onValueChange:D,required:!0,children:[e.jsx(H,{id:"withdraw_method",children:e.jsx($,{placeholder:s("form.fields.selectPaymentMethod",{defaultValue:"Select a payment method"})})}),e.jsx(U,{children:y.map(t=>e.jsxs(O,{value:String(t.id),children:[t.type.toUpperCase()," â ",t.account_name," (",t.account_number,")",t.is_default&&e.jsxs("span",{className:"text-muted-foreground ml-1 text-xs",children:["(",s("form.fields.default",{defaultValue:"default"}),")"]})]},t.id))})]})]}),L&&e.jsx("p",{className:"text-sm text-red-600",children:L}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>N(!1),children:s("form.fields.cancel",{defaultValue:"Cancel"})}),e.jsx(u,{type:"submit",disabled:R,children:R?s("form.fields.submitting",{defaultValue:"Submitting..."}):s("form.fields.submitRequest",{defaultValue:"Submit Request"})})]})]})]})]})]}),a.length>0&&e.jsx("div",{className:"grid grid-cols-2 gap-4 lg:grid-cols-4",children:a.map(t=>e.jsx(x,{className:"overflow-hidden",children:e.jsxs(h,{className:"flex items-center gap-4 p-4",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-emerald-50 dark:bg-emerald-950",children:e.jsx(We,{className:"size-6 text-emerald-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-primary truncate text-xs",children:[s("form.fields.balance",{defaultValue:"Balance"})," (",t.currency_code,")"]}),e.jsx("p",{className:"truncate text-base font-bold",children:d(t.balance,t.currency_code)})]})]})},t.currency_code))}),e.jsx("div",{className:"grid grid-cols-2 gap-4 lg:grid-cols-3",children:oe.map(t=>e.jsx(x,{className:"overflow-hidden",children:e.jsxs(h,{className:"flex items-center gap-4 p-4",children:[e.jsx("div",{className:`flex h-12 w-12 shrink-0 items-center justify-center rounded-xl ${t.bg}`,children:e.jsx(t.icon,{className:`size-6 ${t.color}`})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-primary truncate text-xs",children:s("form.fields."+_e(t.title),{defaultValue:t.title})}),e.jsx("p",{className:"truncate text-base font-bold",children:t.value})]})]})},t.title))}),e.jsxs(x,{children:[e.jsx(ue,{className:"pb-2",children:e.jsxs(fe,{className:"text-primary flex items-center gap-2",children:[e.jsx(ke,{className:"size-4"}),s("form.fields.yourReferralLink",{defaultValue:"Your Referral Link"})]})}),e.jsxs(h,{children:[g&&e.jsx("p",{className:"text-primary text-md mb-3",children:s("form.fields.affliateCouponDiscountMessage",{code:g.code,discount:g.amount})}),e.jsx("p",{className:"text-muted-foreground mb-3 text-sm",children:s("form.fields.shareReferralCopy",{defaultValue:"Share this link. When someone registers a store through your link and pays the setup fee, you earn a commission."})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(I,{value:r,readOnly:!0,className:"font-mono text-xs"}),e.jsxs(u,{variant:"outline",onClick:le,className:"shrink-0",children:[W?e.jsx(G,{className:"size-4 text-green-600"}):e.jsx(qe,{className:"size-4"}),W?s("form.fields.copied",{defaultValue:"Copied!"}):s("form.fields.copy",{defaultValue:"Copy"})]})]})]})]}),e.jsxs(Ne,{defaultValue:X??"history",children:[e.jsxs(be,{children:[e.jsx(C,{value:"history",children:s("form.fields.commissionHistory",{defaultValue:"Commission History"})}),e.jsx(C,{value:"withdrawals",children:s("form.fields.withdrawals",{defaultValue:"Withdrawals"})}),e.jsx(C,{value:"paymentMethods",children:s("form.fields.paymentMethods",{defaultValue:"Payment Methods"})})]}),e.jsxs(S,{value:"history",children:[c.data.length===0?e.jsx("p",{className:"text-muted-foreground px-3 py-8 text-center text-sm",children:s("form.fields.noCommissionHistoryYet",{defaultValue:"No commission history yet."})}):T?e.jsx("div",{className:"divide-y",children:c.data.map(t=>e.jsxs("div",{className:"hover:bg-muted/40 space-y-2 px-3 py-4 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(J,{type:t.type}),e.jsx(p,{status:t.status})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-muted-foreground font-medium",children:[s("form.fields.store",{defaultValue:"Store"}),":"]}),e.jsx("span",{children:t.store_name??"â"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-muted-foreground font-medium",children:[s("form.fields.amount",{defaultValue:"Amount"}),":"]}),e.jsxs("span",{children:[d(t.amount,t.currency_code),t.percentage!==null&&e.jsxs("span",{className:"text-muted-foreground ml-1 text-xs",children:["@ ",t.percentage,"%"]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-muted-foreground font-medium",children:[s("form.fields.commission",{defaultValue:"Commission"}),":"]}),e.jsx("span",{className:"font-medium text-green-700",children:d(t.got_amount,t.currency_code)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-muted-foreground font-medium",children:[s("form.fields.date",{defaultValue:"Date"}),":"]}),e.jsx("span",{className:"text-muted-foreground text-xs",children:t.created_at})]})]},t.id))}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-left",children:[e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.type",{defaultValue:"Type"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.store",{defaultValue:"Store"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.amount",{defaultValue:"Amount"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.commission",{defaultValue:"Commission"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.status",{defaultValue:"Status"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.date",{defaultValue:"Date"})})]})}),e.jsx("tbody",{children:c.data.map(t=>e.jsxs("tr",{className:"hover:bg-muted/40 border-b last:border-0",children:[e.jsx("td",{className:"px-3 py-2.5",children:e.jsx(J,{type:t.type})}),e.jsx("td",{className:"px-3 py-2.5",children:t.store_name??"â"}),e.jsxs("td",{className:"px-3 py-2.5",children:[d(t.amount,t.currency_code),t.percentage!==null&&e.jsxs("span",{className:"text-muted-foreground ml-1 text-xs",children:["@ ",t.percentage,"%"]})]}),e.jsx("td",{className:"px-3 py-2.5 font-medium text-green-700",children:d(t.got_amount,t.currency_code)}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx(p,{status:t.status})}),e.jsx("td",{className:"text-muted-foreground px-3 py-2.5 text-xs",children:t.created_at})]},t.id))})]})}),e.jsx("div",{className:"mt-4",children:e.jsx(E,{currentPage:c.meta.current_page,totalPages:c.meta.last_page,onPageChange:ne})})]}),e.jsxs(S,{value:"withdrawals",children:[m.data.length===0?e.jsx("p",{className:"text-muted-foreground px-3 py-8 text-center text-sm",children:s("form.fields.noWithdrawalRequestsYet",{defaultValue:"No withdrawal requests yet."})}):T?e.jsx("div",{className:"divide-y",children:m.data.map(t=>e.jsxs("div",{className:"hover:bg-muted/40 space-y-2 px-3 py-4 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-semibold",children:d(t.requested_amount,t.currency_code)}),e.jsx(p,{status:t.status})]}),t.admin_note!==null&&e.jsx("p",{className:`text-xs ${t.status==="rejected"?"text-red-400":"text-foreground"}`,children:t.admin_note}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-muted-foreground font-medium",children:[s("form.fields.paymentMethod",{defaultValue:"Payment Method"}),":"]}),e.jsx("span",{className:"text-xs",children:t.payment_method_type?e.jsxs(e.Fragment,{children:[t.payment_method_type.toUpperCase(),t.payment_account_number&&e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",t.payment_account_number,")"]})]}):"â"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-muted-foreground font-medium",children:[s("form.fields.transactionId",{defaultValue:"Transaction ID"}),":"]}),e.jsx("span",{className:"text-muted-foreground text-xs",children:t.admin_transaction_id??"â"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-muted-foreground font-medium",children:[s("form.fields.processedAt",{defaultValue:"Processed At"}),":"]}),e.jsx("span",{className:"text-muted-foreground text-xs",children:t.processed_at??"â"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-muted-foreground font-medium",children:[s("form.fields.requestedAt",{defaultValue:"Requested At"}),":"]}),e.jsx("span",{className:"text-muted-foreground text-xs",children:t.created_at})]})]},t.id))}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-left",children:[e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.amount",{defaultValue:"Amount"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.paymentMethod",{defaultValue:"Payment Method"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.status",{defaultValue:"Status"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.transactionId",{defaultValue:"Transaction ID"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.processedAt",{defaultValue:"Processed At"})}),e.jsx("th",{className:"text-muted-foreground px-3 py-2 font-medium",children:s("form.fields.requestedAt",{defaultValue:"Requested At"})})]})}),e.jsx("tbody",{children:m.data.map(t=>e.jsxs("tr",{className:"hover:bg-muted/40 border-b last:border-0",children:[e.jsx("td",{className:"px-3 py-2.5 font-medium",children:d(t.requested_amount,t.currency_code)}),e.jsx("td",{className:"px-3 py-2.5",children:t.payment_method_type?e.jsxs("span",{className:"text-xs",children:[t.payment_method_type.toUpperCase(),t.payment_account_number&&e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",t.payment_account_number,")"]})]}):"â"}),e.jsxs("td",{className:"px-3 py-2.5",children:[e.jsx(p,{status:t.status}),t.admin_note!==null&&e.jsx("p",{className:`mt-1 text-xs ${t.status==="rejected"?"text-red-400":"text-foreground"}`,children:t.admin_note})]}),e.jsx("td",{className:"text-muted-foreground px-3 py-2.5 text-xs",children:t.admin_transaction_id??"â"}),e.jsx("td",{className:"text-muted-foreground px-3 py-2.5 text-xs",children:t.processed_at??"â"}),e.jsx("td",{className:"text-muted-foreground px-3 py-2.5 text-xs",children:t.created_at})]},t.id))})]})}),e.jsx("div",{className:"mt-4",children:e.jsx(E,{currentPage:m.meta.current_page,totalPages:m.meta.last_page,onPageChange:ie})})]}),e.jsx(S,{value:"paymentMethods",children:e.jsx(ze,{})})]}),y.length===0&&e.jsx(x,{className:"border-yellow-200 bg-yellow-50 dark:bg-yellow-950",children:e.jsx(h,{className:"p-4",children:e.jsxs("p",{className:"text-sm text-yellow-800 dark:text-yellow-200",children:[s("You have no active payment methods.")," ",e.jsx(K,{href:route("affiliate.payment-methods.create"),className:"font-medium underline underline-offset-2",children:s("Add one now")})," ",s("to request withdrawals.")]})})})]})]})}export{Tt 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.