1import{n as q,p as K,q as X,s as j,j as s,L as z,E as F,D as J}from"./main-B85zqRjd.js";import{d as Z,R as i}from"./vendor-react-Bjxsyr_G.js";import{f as _}from"./filterStyles-Dc9vUaM-.js";import{L as ee}from"./ListPageHeader-CDHXn2yx.js";import{M as se}from"./MobileListActionsBar-BguqKu3h.js";import{T as ae}from"./TableData-BQgdfr6d.js";import{B as w}from"./Button-xfGKx8Ra.js";import{P as te}from"./PaginationControls-CEOp50ep.js";import{u as re}from"./useListUrlState-Gg9ZqxAl.js";import{u as oe}from"./usePermissions-BMvQlfNo.js";import{c as U}from"./permissions-D17sBPbQ.js";import{u as ie,a as ne,b as le}from"./referralsApi-Dhbk5E1e.js";import{m as M}from"./filterOptions-Cwg047pw.js";import{c as ce}from"./affiliatesColumns-oOCCnvqx.js";import{D as de}from"./vendor-redux-CkTbKByD.js";import{u as pe}from"./useMediaQuery-Bzu3CIqR.js";import{u as me}from"./useExportWithNotification-D0Qmj8Hk.js";import{u as ue}from"./vendor-i18n-CmmgQqfv.js";import"./vendor-forms-Chlqk9RW.js";import"./Filters-D_K0s731.js";import"./Checkbox-D6300evD.js";import"./DateTimePicker-h9qPaIf5.js";import"./dateUtils-Cn8z919x.js";import"./formatDate-C6Vg3jtv.js";
1import"./TransformAffiliateResponse-Bt9Rhnvh.js";import"./downloadBlob-B7c8Dpai.js";const k=[{value:"ads_services",label:"Ads Services"},{value:"influencers",label:"Influencers"},{value:"paid_pr",label:"Paid PR"},{value:"supportive_sites",label:"Supportive sites"},{value:"promotion",label:"Promotion"},{value:"meta",label:"Meta"},{value:"sponsorships",label:"Sponsorships"}];function fe({t:e,counts:a,options:l={},user:c}){const p=(a==null?void 0:a.active)||0,d=(a==null?void 0:a.suspended)||0,m=[{id:"all",name:e&&e("REPORTS.ALL")||"All"},...M(l.managers)],u=Array.isArray(k)?k.map(n=>({id:n.value,name:n.label})):[],f=[{id:"",name:e&&e("REPORTS.ALL")||"All"},...M(l.referralTypes||u)],R=[{type:"tab",filterOption:"status",defaultValue:"active",tabNames:[{text:e?e("REFERRALS.ACTIVE"):"Active",value:"active",count:p},{text:e?e("REFERRALS.SUSPENDED"):"Suspended",value:"suspended",count:d}]},...U(c)?[{type:"select",filterOption:"manager",placeholder:e?e("AFFILIATES.SELECT_MANAGER"):"Select manager",options:m,grow:!0}]:[]],E=[{type:"input",filterOption:"search",placeholder:e?e("USERS.SEARCH"):"Search",grow:!0},{type:"select",filterOption:"type",placeholder:e?e("REFERRALS.REFERRAL_TYPE"):"Type",options:f,grow:!0}];return{filtersConfig:R,secConfig:E}}function De(){const{t:e}=ue(),a=Z(),{user:l,isManagerWithViewOnly:c}=oe(),[p]=ie(),{query:d,sortBy:m,sortDesc:u,onFiltersChanged:f,onSort:R,goToPage:E}=re({defaultStatus:"active",extraFilters:["type"]}),n=pe(q),h=me(p,"referrals.xlsx"),[x,B]=i.useState(!1),{data:o}=ne(),{data:r,isFetching:A,isLoading:G,refetch:S}=le(d);i.useEffect(()=>{r&&!x&&B(!0)},[r,x]);const I=U(l),{data:v}=K({role:typeof window<"u"&&window.roles&&window.roles.referral?window.roles.referral:void 0},{skip:!I}),b=(o==null?void 0:o.active)||0,$=(o==null?void 0:o.pending)||0,C=(o==null?void 0:o.suspended)||0,{filtersConfig:D,secConfig:W}=i.useMemo(()=>fe({t:e,counts:{active:b,suspended:C},options:{managers:v},user:l}),[e,b,$,C,v,l]),Q=(r==null?void 0:r.items)||[],V=(r==null?void 0:r.totalPages)||1,H=(r==null?void 0:r.currentPage)||1,L=i.useCallback(()=>a("/referral-form"),[a]),N=i.useCallback(t=>{t!=null&&t.id&&a(c?`/referrals/show/${t.id}`:`/referral-form/${t.id}`)},[a,c]),y=i.useCallback(t=>{t!=null&&t.id&&a(`/account-details/${t.id}`)},[a]),g=de(),[P]=X(),T=i.useCallback(async t=>{try{await P(t.id).unwrap(),g(j({notification:e?e("MESSAGE.USER_UNLOCKED"):"User unlocked",notificationColor:"green"})),S()}catch{g(j({notification:e?e("COMMON.ERROR"):"Error",notificationColor:"red"}))}},[P,g,e,S]),Y=i.useMemo(()=>ce({t:e,isSmall:n,onEdit:N,onView:y,onUnlock:T}),[e,n,N,y,T]),O=i.useCallback(()=>h(d),[h,d]);return!x&&(G||A)?s.jsx(z,{}):s.jsxs("div",{className:"px-4 pb-4 pt-[6px] md:px-6 md:pb-6 md:pt-[14px]",children:[s.jsx(ee,{title:e?e("REFERRALS.REFERRALS"):"Referrals",titleClassName:"text-[25.2px] font-medium mb-4 text-[var(--mdn-tab-text)]",filtersConfig:D,secConfig:W,onFiltersChanged:f,filtersMaxWidth:"600px",filtersProps:{isDashboard:!0,controlsUnderline:!0},actionsRight:n?null:s.jsxs("div",{className:"w-full flex flex-col justify-between h-[108px]",children:[s.jsx(w,{variant:"action",className:`${_.addNewButton} w-[250px] max-[960px]:m-auto whitespace-nowrap`,onClick:L,disabled:c,children:e?e("REFERRALS.ADD_NEW_REFERRAL"):"Add New Referral"}),s.jsx("button",{className:`${F} ${_.exportButton} ml-auto`,"aria-label":"Export",onClick:O,children:s.jsx("i",{className:"mdi mdi-upload","aria-hidden":"true"})})]})}),n?s.jsxs(se,{children:[s.jsx("div",{className:"flex items-center",children:s.jsx(w,{variant:"action",className:"rounded-none whitespace-nowrap",onClick:L,disabled:c,children:e?e("REFERRALS.ADD_NEW_REFERRAL"):"Add New Referral"})}),s.jsx("button",{className:F,"aria-label":"Export",onClick:O,children:s.jsx("i",{className:"mdi mdi-upload","aria-hidden":"true"})})]}):null,s.jsx("div",{className:"bg-[var(--mdn-white)]",children:s.jsx(ae,{columns:Y,items:Q,loading:A,...J,showIndex:!n,sortBy:m,sortDesc:u,onSort:R})}),s.jsx(te,{currentPage:H,totalPages:V,onChange: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.