1import{n as Z,o as ee,p as te,q as ae,s as M,j as a,L as ie,E as R,D as se}from"./main-CMViuH_f.js";import{d as oe,R as n}from"./vendor-react-Bjxsyr_G.js";import{u as ne}from"./usePermissions-BMwlS-_T.js";import{c as _}from"./permissions-CCOu_b7F.js";import{f as O}from"./filterStyles-Dc9vUaM-.js";import{L as re}from"./ListPageHeader-BMU8lTAw.js";import{M as le}from"./MobileListActionsBar-DlllOZob.js";import{T as de}from"./TableData-rsaJzmAi.js";import{B as y}from"./Button-DzyKh4DA.js";import{P as pe}from"./PaginationControls-BTJ-3hRF.js";import{u as ce}from"./useListUrlState-Gg9ZqxAl.js";import{a as me,b as fe,c as ue}from"./affiliatesApi-DvcXrG9x.js";import{m as ge}from"./filterOptions-BFwkiKTT.js";import{a as xe}from"./affiliatesColumns-CwpMY1rP.js";import{D as Ae}from"./vendor-redux-CkTbKByD.js";import{u as k}from"./useMediaQuery-Bzu3CIqR.js";import{u as Ee}from"./useExportWithNotification-B5bzP4e_.js";import{u as he}from"./vendor-i18n-CmmgQqfv.js";import"./vendor-forms-Chlqk9RW.js";import"./Filters-B_zORFkG.js";import"./Checkbox-103DDomz.js";import"./DateTimePicker-DzJlOK33.js";import"./dateUtils-Cn8z919x.js";import"./formatDate-C6Vg3jtv.js";
1import"./TransformAffiliateResponse-Dl1Ei_ej.js";import"./downloadBlob-B7c8Dpai.js";function Le({t:e,counts:t,options:l={},user:r}){const m=(t==null?void 0:t.approved)||0,d=(t==null?void 0:t.pending)||0,c=(t==null?void 0:t.suspended)||0,f=(t==null?void 0:t.rejected)||0,u=[{id:"all",name:e&&e("REPORTS.ALL")||"All"},...ge(l.managers)],g=[{type:"tab",filterOption:"status",stretch:!0,defaultValue:"approved",tabNames:[{text:e?e("AFFILIATES.APPROVED"):"Approved",value:"approved",count:m},{text:e?e("AFFILIATES.PENDING"):"Pending",value:"pending",count:d},{text:e?e("AFFILIATES.SUSPENDED"):"Suspended",value:"suspended",count:c},{text:e?e("AFFILIATES.REJECTED"):"Rejected",value:"rejected",count:f}]}],x=[{type:"input",filterOption:"search",placeholder:e?e("USERS.SEARCH"):"Search",grow:!0},..._(r)?[{type:"select",filterOption:"manager",placeholder:e?e("AFFILIATES.SELECT_MANAGER"):"Select manager",options:u,grow:!0}]:[]];return{filtersConfig:g,secConfig:x}}function qe(){const{t:e}=he(),t=oe(),{user:l,isManagerWithViewOnly:r}=ne(),[m]=me(),{query:d,status:c,sortBy:f,sortDesc:u,onFiltersChanged:g,onSort:x,goToPage:h}=ce({defaultStatus:"approved"}),p=k(Z),B=k(ee),L=Ee(m,"affiliates.xlsx"),U=n.useCallback(o=>{window.scrollTo({top:0,behavior:"smooth"}),h(o)},[h]),{data:i,isLoading:G}=fe(),{data:s,isFetching:$,isLoading:W,refetch:C}=ue(d),D=_(l),{data:w,isLoading:Q}=te({role:typeof window<"u"&&window.roles&&window.roles.affiliate?window.roles.affiliate:void 0},{skip:!D}),V=G||W||Q,N=(i==null?void 0:i.approved)||0,S=(i==null?void 0:i.pending)||0,I=(i==null?void 0:i.suspended)||0,H=(i==null?void 0:i.rejected)||0,{filtersConfig:K,secConfig:q}=n.useMemo(()=>Le({t:e,counts:{approved:N,pending:S,suspended:I,rejected:H},options:{managers:w},user:l}),[e,N,S,I,w,l]),A=(s==null?void 0:s.items)||[],J=(s==null?void 0:s.totalPages)||1,F=(s==null?void 0:s.currentPage)||1,X=(s==null?void 0:s.perPage)||(A?A.length:0),z=Math.max(0,(F-1)*(X||0)),T=n.useCallback(o=>{t(r?`/affiliates/show/${o.id}`:`/affiliates/${o.id}`)},[t,r]),b=n.useCallback(o=>{t(`/account-details/${o.id}`)},[t]),E=Ae(),[j]=ae(),v=n.useCallback(async o=>{try{await j(o.id).unwrap(),E(M({notification:e?e("MESSAGE.USER_UNLOCKED"):"User unlocked",notificationColor:"green"})),C()}catch{E(M({notification:e?e("COMMON.ERROR"):"Error",notificationColor:"red"}))}},[j,E,e,C]),Y=n.useMemo(()=>xe({t:e,status:c,isSmall:p,onEdit:T,onView:b,onUnlock:v}),[e,c,p,B,T,b,v]),P=n.useCallback(()=>L(d),[L,d]);return V?a.jsx(ie,{fullscreen:!1}):a.jsxs("div",{className:"px-4 pb-4 pt-[4px] md:px-6 md:pb-6 md:pt-[10px]",children:[a.jsx(re,{title:e?e("AFFILIATES.AFFILIATES"):"Affiliates",titleClassName:"text-[25.2px] font-medium text-[var(--mdn-tab-text)]",filtersConfig:K,secConfig:q,onFiltersChanged:g,filtersMaxWidth:"600px",filtersProps:{isDashboard:!0,controlsUnderline:!0},actionsRight:p?null:a.jsxs("div",{className:"w-full flex flex-col justify-between h-[108px]",children:[a.jsx(y,{variant:"action",className:`${O.addNewButtonWithMargin} w-[250px] max-[960px]:m-auto whitespace-nowrap`,onClick:()=>t("/affiliates/new"),disabled:r,children:e?e("AFFILIATES.ADD_NEW_AFFILIATE"):"Add New Affiliate"}),a.jsx("button",{className:`${R} ${O.exportButton} ml-auto`,"aria-label":"Export",onClick:P,children:a.jsx("i",{className:"mdi mdi-upload","aria-hidden":"true"})})]})}),p?a.jsxs(le,{children:[a.jsx("div",{className:"flex items-center",children:a.jsx(y,{variant:"action",className:"rounded-none whitespace-nowrap",onClick:()=>t("/affiliates/new"),disabled:r,children:e?e("AFFILIATES.ADD_NEW_AFFILIATE"):"Add New Affiliate"})}),a.jsx("button",{className:`${R} rounded-none`,"aria-label":"Export",onClick:P,children:a.jsx("i",{className:"mdi mdi-upload mb-2","aria-hidden":"true"})})]}):null,a.jsx("div",{className:"bg-[var(--mdn-white)]",children:a.jsx(de,{columns:Y,items:A,loading:$,...se,wrapHeaderTwoLines:!0,showIndex:!p,sortBy:f,sortDesc:u,onSort:x,indexOffset:z})}),a.jsx(pe,{currentPage:F,totalPages:J,onChange:U})]})}export{qe 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.