import{h as e}from"./p-083180bf.js";import{b as a,j as r,f as t}from"./p-a7fc1e02.js";import{d,J as l,H as o,L as n,w as s,R as i}from"./p-d0993bb9.js";import{u}from"./p-642f2c89.js";import{u as c}from"./p-d18dedd4.js";const m=a("sq:useReferralTable"),f=d.gql`
  query getReferrals(
    $programId: ID
    $rewardFilter: RewardFilterInput
    $locale: RSLocale
  ) {
    viewer {
      ... on User {
        referredByReferral(programId: $programId) {
          dateConverted
          dateFraudChecksCompleted
          dateModerated
          dateModified
          dateReferralEnded
          dateReferralPaid
          dateReferralStarted
          dateUserModified
          referrerUser {
            firstName
            lastName
          }
          rewards(filter: $rewardFilter) {
            id
            type
            value
            unit
            name
            dateGiven
            dateExpires
            dateCancelled
            dateRedeemed
            dateScheduledFor
            fuelTankCode
            fuelTankType
            currency
            prettyValue(locale: $locale)
            statuses
            globalRewardKey
            programRewardKey
            partnerFundsTransfer {
              id
              status
              dateScheduled
              dateCreated
              dateTransferred
            }
            meta {
              status
              integration {
                name
              }
              message
              customMeta
            }
            rewardRedemptionTransactions {
              data {
                exchangedRewards {
                  data {
                    prettyValue(locale: $locale)
                    type
                    fuelTankCode
                    globalRewardKey
                  }
                }
              }
            }
          }
        }
      }
    }
  }
`,p=d.gql`
  query getReferrals(
    $limit: Int!
    $offset: Int!
    $referralFilter: ReferralFilterInput
    $rewardFilter: RewardFilterInput
    $locale: RSLocale
  ) {
    viewer {
      ... on User {
        id
        paidReferrals: referrals(
          filter: { dateReferralPaid_timeframe: "this_10_years" }
          limit: 1
        ) {
          totalCount
        }
        referrals(limit: $limit, offset: $offset, filter: $referralFilter) {
          totalCount
          count
          data {
            id
            referredUser {
              id
              accountId
              firstName
              lastName
              email
              programGoals {
                goalId
                programId
                count
                firstDate
                lastDate
                conversionCount
              }
            }
            shareLinkUsed
            referralCodeUsed
            moderationStatus
            dateConverted
            dateFraudChecksCompleted
            dateModerated
            dateModified
            dateReferralEnded
            dateReferralPaid
            dateReferralStarted
            dateUserModified
            programId
            program {
              id
              name
            }
            fraudData {
              autoModerationStatus
              manualModerationStatus
              moderationStatus
            }
            rewards(filter: $rewardFilter) {
              id
              type
              value
              unit
              name
              dateGiven
              dateExpires
              dateCancelled
              dateRedeemed
              dateScheduledFor
              fuelTankCode
              fuelTankType
              currency
              prettyValue(locale: $locale)
              pendingReasons
              statuses
              globalRewardKey
              programRewardKey
              partnerFundsTransfer {
                id
                status
                dateScheduled
                dateCreated
                dateTransferred
              }
              referral {
                dateModerated
                fraudData {
                  autoModerationStatus
                  manualModerationStatus
                  moderationStatus
                }
              }
              meta {
                status
                integration {
                  name
                }
                message
                customMeta
              }
              rewardRedemptionTransactions {
                data {
                  exchangedRewards {
                    data {
                      prettyValue(locale: $locale)
                      type
                      fuelTankCode
                      globalRewardKey
                    }
                  }
                }
              }
            }
            childNodes(limit: 10, offset: 0) {
              data {
                data {
                  id
                  ... on FlatReward {
                    id
                    statuses
                    type
                    value
                  }
                  ... on ProgramEmailTransaction {
                    id
                    rewardId
                    dateCreated
                    dateSent
                    dateQueued
                  }
                }
                depth
              }
            }
          }
        }
      }
    }
  }
`,g=d.gql`
  query getImpactTax {
    viewer {
      ... on User {
        id
        impactConnection {
          connected
          taxHandlingEnabled
          publisher {
            requiredTaxDocumentType
            currentTaxDocument {
              status
              type
              dateCreated
            }
            withdrawalSettings {
              paymentMethod
            }
            payoutsAccount {
              hold
              holdReasons
              balance
            }
          }
        }
      }
    }
  }
`;function v(a,d,m){var v,w,R,h;const C=l(),b=o(),I=null!==(v=a.programId)&&void 0!==v?v:b,T="GLOBAL"===I?null:I,F=T?"classic"===T?{programId_exists:!1}:{programId_eq:T}:{},S={userId_eq:null==C?void 0:C.id,accountId_eq:null==C?void 0:C.accountId},[$,k]=r(((e,a)=>({...e,...a})),{columns:[],rows:[],loading:!1,page:0}),x=n(),{data:M,loading:E}=s(f,{programId:"classic"===T?null:T,rewardFilter:S,locale:x},!a.showReferrer||!(null==C?void 0:C.jwt)),P=null===(w=null==M?void 0:M.viewer)||void 0===w?void 0:w.referredByReferral,q=a.showReferrer&&!!(null==P?void 0:P.dateReferralStarted),{data:U,loading:L}=s(g,{},!(null==C?void 0:C.jwt)),D=null===(R=null==U?void 0:U.viewer)||void 0===R?void 0:R.impactConnection,{envelope:N,states:_,callbacks:j}=i(p,(e=>{var a;return null===(a=null==e?void 0:e.viewer)||void 0===a?void 0:a.referrals}),{limit:a.perPage,offset:0},{referralFilter:F,rewardFilter:S,locale:x},a.showReferrer&&E&&!M||!(null==C?void 0:C.jwt));t((()=>{0===_.currentPage&&q&&j.setLimit(a.perPage-1)}),[q]),t((()=>{a.showReferrer&&q?(j.setLimit(a.perPage-1),j.setCurrentPage(0)):(j.setLimit(a.perPage),j.setCurrentPage(0))}),[a.showReferrer]);const K=u(),B=null==N?void 0:N.data,G=c();t((()=>{k({loading:!0}),N&&async function(a){const r=a.filter((e=>"loading"!==e.slot&&"empty"!==e.slot)),t=null==r?void 0:r.map((async e=>y(e,(()=>e.renderLabel()))));let d;if(q&&0===_.currentPage){const a=null==r?void 0:r.map((async a=>y(a,(()=>a.renderReferrerCell(P,x,e)))));d=await Promise.all(a)}const l=null==B?void 0:B.map((async a=>{const t=null==r?void 0:r.map((async r=>y(r,(()=>r.renderCell(a,{locale:x,taxConnection:D},e)))));return await Promise.all(t)})),o=l&&[d,...await Promise.all(l)].filter((e=>e));k({rows:o});const n=t&&await Promise.all(t);k({columns:n,loading:!1,page:_.currentPage})}(G)}),[N,G,K]);const V=!(null===(h=null==$?void 0:$.rows)||void 0===h?void 0:h.length)&&!(null==B?void 0:B.length);return{states:{hasNext:_.currentPage<_.pageCount-1,hasPrev:_.currentPage>0,show:_.loading||$.loading||L?"loading":V?"empty":"rows",namespace:"sqm-referral-table"},data:{textOverrides:{showLabels:!a.hideLabels,prevLabel:a.prevLabel,moreLabel:a.moreLabel},hiddenColumns:a.hiddenColumns,smBreakpoint:a.smBreakpoint,mdBreakpoint:a.mdBreakpoint},elements:{columns:$.columns,rows:$.rows,emptyElement:d,loadingElement:m},callbacks:{nextPage:()=>{0===_.currentPage&&q&&j.setLimit(a.perPage),j.setCurrentPage(_.currentPage+1)},prevPage:()=>{1===_.currentPage&&q&&j.setLimit(a.perPage-1),j.setCurrentPage(_.currentPage-1)}}}}function w(e){try{return JSON.stringify(e)}catch(e){return"An unknown error"}}async function y(a,r){const t=a.tagName.toLowerCase();let d;await customElements.whenDefined(t);try{d=r()}catch(a){return"renderReferrerCell"===r.name?m("column does not have a renderReferrerCell method."):m("label promise failed",a),m("label promise failed",a),e("span",null)}try{return await d}catch(a){m("Error rendering label",a);const r=w(a);return e("details",null,e("summary",null,"Error"),r)}}export{w as g,y as t,v as u}