"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js");
require("../../../../../store/modules/designStore/designStore.js");
require("../../../../../settings/designSetting.js");
require("../../../../../../node_modules/.pnpm/screenfull@6.0.2/node_modules/screenfull/index.js");
require("../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js");
require("../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js");
require("../../../../../../node_modules/.pnpm/html2canvas@1.4.1/node_modules/html2canvas/dist/html2canvas.esm.js");
require("../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseClone.js");
require("../../../../../../node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/index.js");
require("../../../../../enums/pageEnum.js");
require("../../../../../router/index.js");
require("../../../../../../node_modules/.pnpm/vue3-lazyload@0.2.5-beta_a6dezdz3je235ci4e3tu4rayna/node_modules/vue3-lazyload/dist/vue3-lazyload.esm.js");
require("../../../../../components/GoSkeleton/index.vue.js");
require("../../../../../components/GoLoading/index.js");
const useChartDataFetch_hook = require("../../../../../hooks/useChartDataFetch.hook.js");
require("../../../../../api/axios.js");
require("../../../../../../node_modules/.pnpm/echarts@5.4.3/node_modules/echarts/index.js");
require("../../../../../store/modules/langStore/langStore.js");
const chartEditStore = require("../../../../../store/modules/chartEditStore/chartEditStore.js");
const runtimeCore_esmBundler = require("../../../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js");
const reactivity_esmBundler = require("../../../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js");
const shared_esmBundler = require("../../../../../../node_modules/.pnpm/@vue_shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.js");
const _withScopeId = (n) => (runtimeCore_esmBundler.pushScopeId("data-v-c881aae3"), n = n(), runtimeCore_esmBundler.popScopeId(), n);
const _hoisted_1 = { class: "ranking-info" };
const _hoisted_2 = ["innerHTML"];
const _hoisted_3 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ runtimeCore_esmBundler.createElementVNode("div", { class: "shine" }, null, -1));
const _hoisted_4 = [
  _hoisted_3
];
const _sfc_main = /* @__PURE__ */ runtimeCore_esmBundler.defineComponent({
  __name: "index",
  props: {
    chartConfig: {
      type: Object,
      required: true
    }
  },
  setup(__props) {
    const props = __props;
    const { w, h } = reactivity_esmBundler.toRefs(props.chartConfig.attr);
    const { rowNum, unit, color, textColor, borderColor, indexFontSize, leftFontSize, rightFontSize } = reactivity_esmBundler.toRefs(
      props.chartConfig.option
    );
    const status = reactivity_esmBundler.reactive({
      mergedConfig: props.chartConfig.option,
      rowsData: [],
      rows: [
        {
          scroll: 0,
          ranking: 1,
          name: "",
          value: "",
          percent: 0
        }
      ],
      heights: [0],
      animationIndex: 0,
      animationHandler: 0,
      updater: 0,
      avgHeight: 0
    });
    const calcRowsData = () => {
      let { dataset, rowNum: rowNum2, sort } = status.mergedConfig;
      sort && dataset.sort(({ value: a }, { value: b }) => {
        if (a > b)
          return -1;
        if (a < b)
          return 1;
        if (a === b)
          return 0;
      });
      const value = dataset.map(({ value: value2 }) => value2);
      const min = Math.min(...value) || 0;
      const minAbs = Math.abs(min);
      const max = Math.max(...value) || 0;
      const total = max + minAbs;
      dataset = dataset.map((row, i) => ({
        ...row,
        ranking: i + 1,
        percent: (row.value + minAbs) / total * 100
      }));
      const rowLength = dataset.length;
      if (rowLength > rowNum2 && rowLength < 2 * rowNum2) {
        dataset = [...dataset, ...dataset];
      }
      dataset = dataset.map((d, i) => ({ ...d, scroll: i }));
      status.rowsData = dataset;
      status.rows = dataset;
    };
    const calcHeights = (onresize = false) => {
      const { rowNum: rowNum2, dataset } = status.mergedConfig;
      const avgHeight = h.value / rowNum2;
      status.avgHeight = avgHeight;
      if (!onresize)
        status.heights = new Array(dataset.length).fill(avgHeight);
    };
    const animation = async (start = false) => {
      let { avgHeight, animationIndex, mergedConfig, rowsData, updater } = status;
      const { waitTime, carousel, rowNum: rowNum2 } = mergedConfig;
      const rowLength = rowsData.length;
      if (rowNum2 >= rowLength)
        return;
      if (start) {
        await new Promise((resolve) => setTimeout(resolve, waitTime));
        if (updater !== status.updater)
          return;
      }
      const animationNum = carousel === "single" ? 1 : rowNum2;
      let rows = rowsData.slice(animationIndex);
      rows.push(...rowsData.slice(0, animationIndex));
      status.rows = rows.slice(0, rowNum2 + 1);
      status.heights = new Array(rowLength).fill(avgHeight);
      await new Promise((resolve) => setTimeout(resolve, 300));
      if (updater !== status.updater)
        return;
      status.heights.splice(0, animationNum, ...new Array(animationNum).fill(0));
      animationIndex += animationNum;
      const back = animationIndex - rowLength;
      if (back >= 0)
        animationIndex = back;
      status.animationIndex = animationIndex;
      status.animationHandler = setTimeout(animation, waitTime * 1e3 - 300);
    };
    const stopAnimation = () => {
      status.updater = (status.updater + 1) % 999999;
      if (!status.animationHandler)
        return;
      clearTimeout(status.animationHandler);
    };
    const onRestart = async () => {
      try {
        if (!status.mergedConfig)
          return;
        let { dataset, rowNum: rowNum2, sort } = status.mergedConfig;
        stopAnimation();
        calcRowsData();
        let flag = true;
        if (dataset.length <= rowNum2) {
          flag = false;
        }
        calcHeights(flag);
        animation(flag);
      } catch (error) {
        console.error(error);
      }
    };
    onRestart();
    runtimeCore_esmBundler.watch(
      () => w.value,
      () => {
        onRestart();
      }
    );
    runtimeCore_esmBundler.watch(
      () => h.value,
      () => {
        onRestart();
      }
    );
    runtimeCore_esmBundler.watch(
      () => rowNum.value,
      () => {
        onRestart();
      }
    );
    runtimeCore_esmBundler.watch(
      () => props.chartConfig.option.dataset,
      () => {
        onRestart();
      },
      {
        deep: false
      }
    );
    useChartDataFetch_hook.useChartDataFetch(props.chartConfig, chartEditStore.useChartEditStore, (resData) => {
      props.chartConfig.option.dataset = resData;
      onRestart();
    });
    runtimeCore_esmBundler.onUnmounted(() => {
      stopAnimation();
    });
    return (_ctx, _cache) => {
      return runtimeCore_esmBundler.openBlock(), runtimeCore_esmBundler.createElementBlock("div", {
        class: "go-tables-rank",
        style: shared_esmBundler.normalizeStyle(`color: ${reactivity_esmBundler.unref(textColor)}`)
      }, [
        (runtimeCore_esmBundler.openBlock(true), runtimeCore_esmBundler.createElementBlock(runtimeCore_esmBundler.Fragment, null, runtimeCore_esmBundler.renderList(status.rows, (item, i) => {
          return runtimeCore_esmBundler.openBlock(), runtimeCore_esmBundler.createElementBlock("div", {
            class: "row-item",
            key: item.toString() + item.scroll,
            style: shared_esmBundler.normalizeStyle(`height: ${status.heights[i]}px;`)
          }, [
            runtimeCore_esmBundler.createElementVNode("div", _hoisted_1, [
              runtimeCore_esmBundler.createElementVNode("div", {
                class: "rank",
                style: shared_esmBundler.normalizeStyle(`color: ${reactivity_esmBundler.unref(color)};font-size: ${reactivity_esmBundler.unref(indexFontSize)}px`)
              }, "No." + shared_esmBundler.toDisplayString(item.ranking), 5),
              runtimeCore_esmBundler.createElementVNode("div", {
                class: "info-name",
                style: shared_esmBundler.normalizeStyle(`font-size: ${reactivity_esmBundler.unref(leftFontSize)}px`),
                innerHTML: item.name
              }, null, 12, _hoisted_2),
              runtimeCore_esmBundler.createElementVNode("div", {
                class: "ranking-value",
                style: shared_esmBundler.normalizeStyle(`color: ${reactivity_esmBundler.unref(textColor)};font-size: ${reactivity_esmBundler.unref(rightFontSize)}px`)
              }, shared_esmBundler.toDisplayString(status.mergedConfig.valueFormatter ? status.mergedConfig.valueFormatter(item) : item.value) + " " + shared_esmBundler.toDisplayString(reactivity_esmBundler.unref(unit)), 5)
            ]),
            runtimeCore_esmBundler.createElementVNode("div", {
              class: "ranking-column",
              style: shared_esmBundler.normalizeStyle(`border-color: ${reactivity_esmBundler.unref(borderColor)}`)
            }, [
              runtimeCore_esmBundler.createElementVNode("div", {
                class: "inside-column",
                style: shared_esmBundler.normalizeStyle(`width: ${item.percent}%;background-color: ${reactivity_esmBundler.unref(color)}`)
              }, _hoisted_4, 4)
            ], 4)
          ], 4);
        }), 128))
      ], 4);
    };
  }
});
exports.default = _sfc_main;
