'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-8277cbb3.js');
const global = require('./global-b7b1b8fe.js');
const domContextHooks_module = require('./dom-context-hooks.module-e7b6727c.js');
const index_module = require('./index.module-f8c8495f.js');
const cjs = require('./cjs-1066ec21.js');
const sqmLeaderboardRankView = require('./sqm-leaderboard-rank-view-67fd7934.js');

const GET_RANK = index_module.dist.gql `
  query ($type: String!, $filter: UserLeaderboardFilterInput) {
    viewer {
      ... on User {
        leaderboardRank(type: $type, filter: $filter) {
          rowNumber
          rank
          denseRank
        }
      }
    }
  }
`;
function useLeaderboardRank(props) {
  var _a, _b, _c, _d;
  const programIdContext = index_module.H();
  // Default to context, overriden by props
  const programId = (_a = props.programId) !== null && _a !== void 0 ? _a : programIdContext;
  const user = index_module.J();
  const rankVariables = programId
    ? {
      type: props.leaderboardType,
      filter: { programId_eq: programId },
    }
    : {
      type: props.leaderboardType,
      filter: {},
    };
  if (props.interval) {
    rankVariables.filter["interval"] = props.interval;
  }
  const { data: rankData } = index_module.wn(GET_RANK, rankVariables, !(user === null || user === void 0 ? void 0 : user.jwt));
  const fullRankText = ((_b = rankData === null || rankData === void 0 ? void 0 : rankData.viewer) === null || _b === void 0 ? void 0 : _b.leaderboardRank) ? global.intl.formatMessage({ id: "rankText", defaultMessage: props.rankText }, {
    rank: (_d = (_c = rankData === null || rankData === void 0 ? void 0 : rankData.viewer) === null || _c === void 0 ? void 0 : _c.leaderboardRank) === null || _d === void 0 ? void 0 : _d[props.rankType],
  })
    : props.unrankedText || "unranked";
  return {
    data: {
      rank: fullRankText,
    },
  };
}

const sqmLeaderboardRankCss = "p,.P{font-size:var(--sl-font-size-small);color:var(--sqm-text);margin-top:0px}p.Subtitle,.P.Subtitle{color:var(--sqm-text-subdued);margin:0px}";

const LeaderboardRank = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    /**
     * @uiName Rank text
     * @uiWidget textArea
     */
    this.rankText = "You are currently in {rank, selectordinal, one {#st} two {#nd} few {#rd} other {#th} } place!";
    domContextHooks_module.h$1(this);
  }
  disconnectedCallback() { }
  render() {
    const props = index_module.isDemo()
      ? useLeaderboardRankDemo(this)
      : useLeaderboardRank(this);
    return index.h(sqmLeaderboardRankView.LeaderboardRankView, Object.assign({}, props));
  }
};
function useLeaderboardRankDemo(props) {
  const rank = global.intl.formatMessage({ id: "rankText", defaultMessage: props.rankText }, {
    rank: 1,
  }) || "1st";
  return cjs.cjs({
    data: {
      rank,
    },
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}
LeaderboardRank.style = sqmLeaderboardRankCss;

exports.sqm_leaderboard_rank = LeaderboardRank;
