import { defineComponent, computed, resolveComponent, createElementBlock, openBlock, normalizeStyle, normalizeClass, unref, Fragment, createCommentVNode, createElementVNode, renderList, createBlock, mergeProps, renderSlot, createTextVNode, toDisplayString, createVNode } from 'vue';
import '../../../utils/index.mjs';
import { RANKING_LIST_MAX_LIMIT, rankingListProps } from './ranking-list.mjs';
import { createNamespace } from '../../../utils/create-namespace.mjs';

"use strict";
const _hoisted_1 = ["title"];
const _hoisted_2 = ["title"];
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "LlRankingList" },
  __name: "ranking-list",
  props: rankingListProps,
  setup(__props) {
    const bem = 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 = computed(() => {
      const limit = Number(props.limit);
      if (!Number.isFinite(limit) || limit <= 0) return RANKING_LIST_MAX_LIMIT;
      return Math.min(Math.floor(limit), RANKING_LIST_MAX_LIMIT);
    });
    const renderList$1 = 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 = computed(() => {
      const top = renderList$1.value.slice(0, 3);
      return [top[1], top[0], top[2]].filter(Boolean);
    });
    const listList = computed(
      () => props.type === "podium" ? renderList$1.value.slice(3) : renderList$1.value
    );
    const rankLevel = (rank) => {
      if (props.type !== "podium") return "";
      return rank <= 3 ? `top-${rank}` : "";
    };
    const rootStyle = 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 = resolveComponent("ll-avatar");
      const _component_ll_empty = resolveComponent("ll-empty");
      return openBlock(), createElementBlock(
        "div",
        {
          class: normalizeClass([unref(bem).b(), unref(bem).m(_ctx.type)]),
          style: normalizeStyle(rootStyle.value)
        },
        [
          renderList$1.value.length ? (openBlock(), createElementBlock(
            Fragment,
            { key: 0 },
            [
              createCommentVNode(" \u5956\u53F0\u533A\uFF1A\u4EC5\u5956\u53F0\u6837\u5F0F\u5C55\u793A\u524D\u4E09\u540D "),
              _ctx.type === "podium" && podiumList.value.length ? (openBlock(), createElementBlock(
                "div",
                {
                  key: 0,
                  class: normalizeClass(unref(bem).e("podium"))
                },
                [
                  (openBlock(true), createElementBlock(
                    Fragment,
                    null,
                    renderList(podiumList.value, (item) => {
                      return openBlock(), createElementBlock(
                        "div",
                        {
                          key: item.rank,
                          class: normalizeClass([unref(bem).e("podium-item"), unref(bem).is(`rank-${item.rank}`)])
                        },
                        [
                          createElementVNode(
                            "div",
                            {
                              class: normalizeClass(unref(bem).e("podium-avatar"))
                            },
                            [
                              _ctx.showAvatar && item.avatar ? (openBlock(), createBlock(_component_ll_avatar, mergeProps({
                                key: 0,
                                ref_for: true
                              }, item.avatar, {
                                class: [unref(bem).e("avatar"), unref(bem).is(`top-${item.rank}`)]
                              }), null, 16, ["class"])) : createCommentVNode("v-if", true),
                              createElementVNode(
                                "span",
                                {
                                  class: normalizeClass([unref(bem).e("medal"), unref(bem).is(`top-${item.rank}`)])
                                },
                                [
                                  renderSlot(_ctx.$slots, "avatar", mergeProps({ ref_for: true }, item), () => [
                                    createTextVNode(
                                      toDisplayString(item.rank),
                                      1
                                      /* TEXT */
                                    )
                                  ])
                                ],
                                2
                                /* CLASS */
                              )
                            ],
                            2
                            /* CLASS */
                          ),
                          createElementVNode("div", {
                            class: normalizeClass(unref(bem).e("podium-label")),
                            title: item.label
                          }, [
                            renderSlot(_ctx.$slots, "label", mergeProps({ ref_for: true }, item), () => [
                              createTextVNode(
                                toDisplayString(item.label),
                                1
                                /* TEXT */
                              )
                            ])
                          ], 10, _hoisted_1),
                          createElementVNode(
                            "div",
                            {
                              class: normalizeClass(unref(bem).e("podium-value"))
                            },
                            [
                              renderSlot(_ctx.$slots, "value", mergeProps({ ref_for: true }, item), () => [
                                createTextVNode(
                                  toDisplayString(item.valueText),
                                  1
                                  /* TEXT */
                                )
                              ])
                            ],
                            2
                            /* CLASS */
                          )
                        ],
                        2
                        /* CLASS */
                      );
                    }),
                    128
                    /* KEYED_FRAGMENT */
                  ))
                ],
                2
                /* CLASS */
              )) : createCommentVNode("v-if", true),
              createCommentVNode(" \u5217\u8868\u533A "),
              createElementVNode(
                "div",
                {
                  class: normalizeClass(unref(bem).e("list"))
                },
                [
                  (openBlock(true), createElementBlock(
                    Fragment,
                    null,
                    renderList(listList.value, (item) => {
                      return openBlock(), createElementBlock(
                        "div",
                        {
                          key: item.rank,
                          class: normalizeClass([unref(bem).e("item"), unref(bem).is(`rank-${item.rank}`)])
                        },
                        [
                          renderSlot(_ctx.$slots, "item", mergeProps({ ref_for: true }, item), () => [
                            createCommentVNode(" \u6392\u540D "),
                            createElementVNode(
                              "div",
                              {
                                class: normalizeClass([unref(bem).e("rank"), unref(bem).is(rankLevel(item.rank))])
                              },
                              [
                                createElementVNode(
                                  "span",
                                  {
                                    class: normalizeClass(unref(bem).e("rank-text"))
                                  },
                                  toDisplayString(item.rank),
                                  3
                                  /* TEXT, CLASS */
                                )
                              ],
                              2
                              /* CLASS */
                            ),
                            createCommentVNode(" \u5934\u50CF "),
                            _ctx.showAvatar && item.avatar ? (openBlock(), createBlock(_component_ll_avatar, mergeProps({
                              key: 0,
                              ref_for: true
                            }, item.avatar, {
                              class: unref(bem).e("avatar")
                            }), null, 16, ["class"])) : createCommentVNode("v-if", true),
                            createCommentVNode(" \u5185\u5BB9 "),
                            createElementVNode(
                              "div",
                              {
                                class: normalizeClass(unref(bem).e("content"))
                              },
                              [
                                createElementVNode(
                                  "div",
                                  {
                                    class: normalizeClass(unref(bem).e("head"))
                                  },
                                  [
                                    createElementVNode("div", {
                                      class: normalizeClass(unref(bem).e("label")),
                                      title: item.label
                                    }, [
                                      renderSlot(_ctx.$slots, "label", mergeProps({ ref_for: true }, item), () => [
                                        createTextVNode(
                                          toDisplayString(item.label),
                                          1
                                          /* TEXT */
                                        )
                                      ])
                                    ], 10, _hoisted_2),
                                    createElementVNode(
                                      "div",
                                      {
                                        class: normalizeClass(unref(bem).e("value"))
                                      },
                                      [
                                        renderSlot(_ctx.$slots, "value", mergeProps({ ref_for: true }, item), () => [
                                          createTextVNode(
                                            toDisplayString(item.valueText),
                                            1
                                            /* TEXT */
                                          )
                                        ])
                                      ],
                                      2
                                      /* CLASS */
                                    )
                                  ],
                                  2
                                  /* CLASS */
                                ),
                                item.description ? (openBlock(), createElementBlock(
                                  "div",
                                  {
                                    key: 0,
                                    class: normalizeClass(unref(bem).e("description"))
                                  },
                                  toDisplayString(item.description),
                                  3
                                  /* TEXT, CLASS */
                                )) : createCommentVNode("v-if", true),
                                _ctx.showBar ? (openBlock(), createElementBlock(
                                  "div",
                                  {
                                    key: 1,
                                    class: normalizeClass(unref(bem).e("bar"))
                                  },
                                  [
                                    createElementVNode(
                                      "div",
                                      {
                                        class: normalizeClass(unref(bem).e("bar-inner")),
                                        style: normalizeStyle(barStyle(item))
                                      },
                                      null,
                                      6
                                      /* CLASS, STYLE */
                                    )
                                  ],
                                  2
                                  /* CLASS */
                                )) : createCommentVNode("v-if", true)
                              ],
                              2
                              /* CLASS */
                            )
                          ])
                        ],
                        2
                        /* CLASS */
                      );
                    }),
                    128
                    /* KEYED_FRAGMENT */
                  ))
                ],
                2
                /* CLASS */
              )
            ],
            64
            /* STABLE_FRAGMENT */
          )) : (openBlock(), createElementBlock(
            "div",
            {
              key: 1,
              class: normalizeClass(unref(bem).e("empty"))
            },
            [
              renderSlot(_ctx.$slots, "empty", {}, () => [
                createVNode(_component_ll_empty)
              ])
            ],
            2
            /* CLASS */
          ))
        ],
        6
        /* CLASS, STYLE */
      );
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=ranking-list.vue2.mjs.map
