'use strict';

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

var vue = require('vue');
require('../../../utils/index.js');
var rankingList = require('./ranking-list.js');
var createNamespace = require('../../../utils/create-namespace.js');

"use strict";
const _hoisted_1 = ["title"];
const _hoisted_2 = ["title"];
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{ name: "LlRankingList" },
  __name: "ranking-list",
  props: rankingList.rankingListProps,
  setup(__props) {
    const bem = createNamespace.createNamespace("ranking-list");
    const props = __props;
    const getLabel = (item) => item?.[props.fieldNames.label || "label"];
    const getValue = (item) => item?.[props.fieldNames.value || "value"];
    const getDescription = (item) => item?.[props.fieldNames.description || "description"];
    const getAvatar = (item) => item?.[props.fieldNames.avatar || "avatar"];
    const formatValue = (value, item) => {
      if (typeof props.valueFormatter === "function") {
        return props.valueFormatter(value, item);
      }
      if (typeof value !== "number" || Number.isNaN(value)) return "-";
      return props.thousandSeparator ? value.toLocaleString("en-US") : String(value);
    };
    const safeLimit = vue.computed(() => {
      const limit = Number(props.limit);
      if (!Number.isFinite(limit) || limit <= 0) return rankingList.RANKING_LIST_MAX_LIMIT;
      return Math.min(Math.floor(limit), rankingList.RANKING_LIST_MAX_LIMIT);
    });
    const renderList = vue.computed(() => {
      const list = (props.data || []).map((raw) => {
        const value = Number(getValue(raw)) || 0;
        return {
          raw,
          label: getLabel(raw) ?? "",
          value,
          description: getDescription(raw) ?? "",
          avatar: getAvatar(raw)
        };
      });
      list.sort(
        (a, b) => props.order === "asc" ? a.value - b.value : b.value - a.value
      );
      const sliced = list.slice(0, safeLimit.value);
      const maxValue = sliced.reduce((max, item) => Math.max(max, item.value), 0);
      return sliced.map((item, index) => ({
        rank: index + 1,
        label: item.label,
        value: item.value,
        valueText: formatValue(item.value, item.raw),
        description: item.description,
        avatar: item.avatar,
        percent: maxValue > 0 ? item.value / maxValue * 100 : 0,
        raw: item.raw
      }));
    });
    const podiumList = vue.computed(() => {
      const top = renderList.value.slice(0, 3);
      return [top[1], top[0], top[2]].filter(Boolean);
    });
    const listList = vue.computed(
      () => props.type === "podium" ? renderList.value.slice(3) : renderList.value
    );
    const rankLevel = (rank) => {
      if (props.type !== "podium") return "";
      return rank <= 3 ? `top-${rank}` : "";
    };
    const rootStyle = vue.computed(() => {
      const style = {};
      if (props.background) style.background = props.background;
      if (props.color) style.color = props.color;
      return style;
    });
    const barStyle = (item) => {
      const style = {
        width: `${item.percent}%`
      };
      if (props.barColor) style.background = props.barColor;
      return style;
    };
    return (_ctx, _cache) => {
      const _component_ll_avatar = vue.resolveComponent("ll-avatar");
      const _component_ll_empty = vue.resolveComponent("ll-empty");
      return vue.openBlock(), vue.createElementBlock(
        "div",
        {
          class: vue.normalizeClass([vue.unref(bem).b(), vue.unref(bem).m(_ctx.type)]),
          style: vue.normalizeStyle(rootStyle.value)
        },
        [
          renderList.value.length ? (vue.openBlock(), vue.createElementBlock(
            vue.Fragment,
            { key: 0 },
            [
              vue.createCommentVNode(" \u5956\u53F0\u533A\uFF1A\u4EC5\u5956\u53F0\u6837\u5F0F\u5C55\u793A\u524D\u4E09\u540D "),
              _ctx.type === "podium" && podiumList.value.length ? (vue.openBlock(), vue.createElementBlock(
                "div",
                {
                  key: 0,
                  class: vue.normalizeClass(vue.unref(bem).e("podium"))
                },
                [
                  (vue.openBlock(true), vue.createElementBlock(
                    vue.Fragment,
                    null,
                    vue.renderList(podiumList.value, (item) => {
                      return vue.openBlock(), vue.createElementBlock(
                        "div",
                        {
                          key: item.rank,
                          class: vue.normalizeClass([vue.unref(bem).e("podium-item"), vue.unref(bem).is(`rank-${item.rank}`)])
                        },
                        [
                          vue.createElementVNode(
                            "div",
                            {
                              class: vue.normalizeClass(vue.unref(bem).e("podium-avatar"))
                            },
                            [
                              _ctx.showAvatar && item.avatar ? (vue.openBlock(), vue.createBlock(_component_ll_avatar, vue.mergeProps({
                                key: 0,
                                ref_for: true
                              }, item.avatar, {
                                class: [vue.unref(bem).e("avatar"), vue.unref(bem).is(`top-${item.rank}`)]
                              }), null, 16, ["class"])) : vue.createCommentVNode("v-if", true),
                              vue.createElementVNode(
                                "span",
                                {
                                  class: vue.normalizeClass([vue.unref(bem).e("medal"), vue.unref(bem).is(`top-${item.rank}`)])
                                },
                                [
                                  vue.renderSlot(_ctx.$slots, "avatar", vue.mergeProps({ ref_for: true }, item), () => [
                                    vue.createTextVNode(
                                      vue.toDisplayString(item.rank),
                                      1
                                      /* TEXT */
                                    )
                                  ])
                                ],
                                2
                                /* CLASS */
                              )
                            ],
                            2
                            /* CLASS */
                          ),
                          vue.createElementVNode("div", {
                            class: vue.normalizeClass(vue.unref(bem).e("podium-label")),
                            title: item.label
                          }, [
                            vue.renderSlot(_ctx.$slots, "label", vue.mergeProps({ ref_for: true }, item), () => [
                              vue.createTextVNode(
                                vue.toDisplayString(item.label),
                                1
                                /* TEXT */
                              )
                            ])
                          ], 10, _hoisted_1),
                          vue.createElementVNode(
                            "div",
                            {
                              class: vue.normalizeClass(vue.unref(bem).e("podium-value"))
                            },
                            [
                              vue.renderSlot(_ctx.$slots, "value", vue.mergeProps({ ref_for: true }, item), () => [
                                vue.createTextVNode(
                                  vue.toDisplayString(item.valueText),
                                  1
                                  /* TEXT */
                                )
                              ])
                            ],
                            2
                            /* CLASS */
                          )
                        ],
                        2
                        /* CLASS */
                      );
                    }),
                    128
                    /* KEYED_FRAGMENT */
                  ))
                ],
                2
                /* CLASS */
              )) : vue.createCommentVNode("v-if", true),
              vue.createCommentVNode(" \u5217\u8868\u533A "),
              vue.createElementVNode(
                "div",
                {
                  class: vue.normalizeClass(vue.unref(bem).e("list"))
                },
                [
                  (vue.openBlock(true), vue.createElementBlock(
                    vue.Fragment,
                    null,
                    vue.renderList(listList.value, (item) => {
                      return vue.openBlock(), vue.createElementBlock(
                        "div",
                        {
                          key: item.rank,
                          class: vue.normalizeClass([vue.unref(bem).e("item"), vue.unref(bem).is(`rank-${item.rank}`)])
                        },
                        [
                          vue.renderSlot(_ctx.$slots, "item", vue.mergeProps({ ref_for: true }, item), () => [
                            vue.createCommentVNode(" \u6392\u540D "),
                            vue.createElementVNode(
                              "div",
                              {
                                class: vue.normalizeClass([vue.unref(bem).e("rank"), vue.unref(bem).is(rankLevel(item.rank))])
                              },
                              [
                                vue.createElementVNode(
                                  "span",
                                  {
                                    class: vue.normalizeClass(vue.unref(bem).e("rank-text"))
                                  },
                                  vue.toDisplayString(item.rank),
                                  3
                                  /* TEXT, CLASS */
                                )
                              ],
                              2
                              /* CLASS */
                            ),
                            vue.createCommentVNode(" \u5934\u50CF "),
                            _ctx.showAvatar && item.avatar ? (vue.openBlock(), vue.createBlock(_component_ll_avatar, vue.mergeProps({
                              key: 0,
                              ref_for: true
                            }, item.avatar, {
                              class: vue.unref(bem).e("avatar")
                            }), null, 16, ["class"])) : vue.createCommentVNode("v-if", true),
                            vue.createCommentVNode(" \u5185\u5BB9 "),
                            vue.createElementVNode(
                              "div",
                              {
                                class: vue.normalizeClass(vue.unref(bem).e("content"))
                              },
                              [
                                vue.createElementVNode(
                                  "div",
                                  {
                                    class: vue.normalizeClass(vue.unref(bem).e("head"))
                                  },
                                  [
                                    vue.createElementVNode("div", {
                                      class: vue.normalizeClass(vue.unref(bem).e("label")),
                                      title: item.label
                                    }, [
                                      vue.renderSlot(_ctx.$slots, "label", vue.mergeProps({ ref_for: true }, item), () => [
                                        vue.createTextVNode(
                                          vue.toDisplayString(item.label),
                                          1
                                          /* TEXT */
                                        )
                                      ])
                                    ], 10, _hoisted_2),
                                    vue.createElementVNode(
                                      "div",
                                      {
                                        class: vue.normalizeClass(vue.unref(bem).e("value"))
                                      },
                                      [
                                        vue.renderSlot(_ctx.$slots, "value", vue.mergeProps({ ref_for: true }, item), () => [
                                          vue.createTextVNode(
                                            vue.toDisplayString(item.valueText),
                                            1
                                            /* TEXT */
                                          )
                                        ])
                                      ],
                                      2
                                      /* CLASS */
                                    )
                                  ],
                                  2
                                  /* CLASS */
                                ),
                                item.description ? (vue.openBlock(), vue.createElementBlock(
                                  "div",
                                  {
                                    key: 0,
                                    class: vue.normalizeClass(vue.unref(bem).e("description"))
                                  },
                                  vue.toDisplayString(item.description),
                                  3
                                  /* TEXT, CLASS */
                                )) : vue.createCommentVNode("v-if", true),
                                _ctx.showBar ? (vue.openBlock(), vue.createElementBlock(
                                  "div",
                                  {
                                    key: 1,
                                    class: vue.normalizeClass(vue.unref(bem).e("bar"))
                                  },
                                  [
                                    vue.createElementVNode(
                                      "div",
                                      {
                                        class: vue.normalizeClass(vue.unref(bem).e("bar-inner")),
                                        style: vue.normalizeStyle(barStyle(item))
                                      },
                                      null,
                                      6
                                      /* CLASS, STYLE */
                                    )
                                  ],
                                  2
                                  /* CLASS */
                                )) : vue.createCommentVNode("v-if", true)
                              ],
                              2
                              /* CLASS */
                            )
                          ])
                        ],
                        2
                        /* CLASS */
                      );
                    }),
                    128
                    /* KEYED_FRAGMENT */
                  ))
                ],
                2
                /* CLASS */
              )
            ],
            64
            /* STABLE_FRAGMENT */
          )) : (vue.openBlock(), vue.createElementBlock(
            "div",
            {
              key: 1,
              class: vue.normalizeClass(vue.unref(bem).e("empty"))
            },
            [
              vue.renderSlot(_ctx.$slots, "empty", {}, () => [
                vue.createVNode(_component_ll_empty)
              ])
            ],
            2
            /* CLASS */
          ))
        ],
        6
        /* CLASS, STYLE */
      );
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=ranking-list.vue2.js.map
