import "../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.mjs";
import "../../../../../store/modules/designStore/designStore.mjs";
import "../../../../../settings/designSetting.mjs";
import "../../../../../../node_modules/.pnpm/screenfull@6.0.2/node_modules/screenfull/index.mjs";
import "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.mjs";
import "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.mjs";
import "../../../../../../node_modules/.pnpm/html2canvas@1.4.1/node_modules/html2canvas/dist/html2canvas.esm.mjs";
import cloneDeep from "../../../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/cloneDeep.mjs";
import "../../../../../../node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/index.mjs";
import "../../../../../enums/pageEnum.mjs";
import "../../../../../router/index.mjs";
import "../../../../../../node_modules/.pnpm/vue3-lazyload@0.2.5-beta_a6dezdz3je235ci4e3tu4rayna/node_modules/vue3-lazyload/dist/vue3-lazyload.esm.mjs";
import "../../../../../components/GoSkeleton/index.vue.mjs";
import "../../../../../components/GoLoading/index.mjs";
import { useChartDataFetch } from "../../../../../hooks/useChartDataFetch.hook.mjs";
import "../../../../../api/axios.mjs";
import "../../../../../../node_modules/.pnpm/echarts@5.4.3/node_modules/echarts/index.mjs";
import "../../../../../store/modules/langStore/langStore.mjs";
import { useChartEditStore } from "../../../../../store/modules/chartEditStore/chartEditStore.mjs";
import { option } from "./config.mjs";
import { defineComponent, watch, onMounted, openBlock, createElementBlock, createElementVNode as createBaseVNode, Fragment, renderList, createCommentVNode, pushScopeId, popScopeId } from "../../../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.mjs";
import { reactive } from "../../../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.mjs";
import { normalizeStyle, toDisplayString } from "../../../../../../node_modules/.pnpm/@vue_shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.mjs";
const _withScopeId = (n) => (pushScopeId("data-v-66b968b8"), n = n(), popScopeId(), n);
const _hoisted_1 = { class: "label-column" };
const _hoisted_2 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createBaseVNode("div", { class: "laset" }, " ", -1));
const _hoisted_3 = { class: "capsule-container" };
const _hoisted_4 = {
  key: 0,
  class: "capsule-item-value"
};
const _hoisted_5 = { class: "unit-label" };
const _hoisted_6 = {
  key: 0,
  class: "unit-text"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    chartConfig: {
      type: Object,
      default: () => ({})
    }
  },
  setup(__props) {
    const props = __props;
    const state = reactive({
      defaultConfig: option,
      mergedConfig: null,
      capsuleLength: [],
      capsuleValue: [],
      labelData: [],
      capsuleItemHeight: ""
    });
    watch(
      () => props.chartConfig.option,
      (newVal) => {
        calcData(newVal);
      },
      {
        deep: true
      }
    );
    const calcData = (data, type) => {
      let cloneConfig = cloneDeep(props.chartConfig.option || {});
      state.mergedConfig = cloneConfig;
      if (type == "preview") {
        cloneConfig.dataset = data;
      }
      calcCapsuleLengthAndLabelData(state.mergedConfig.dataset);
    };
    const calcCapsuleLengthAndLabelData = (dataset) => {
      try {
        const { source } = dataset;
        if (!source || !source.length)
          return;
        state.capsuleItemHeight = numberSizeHandle(state.mergedConfig.itemHeight);
        const capsuleValue = source.map((item) => item[state.mergedConfig.dataset.dimensions[1]]);
        const maxValue = Math.max(...capsuleValue);
        state.capsuleValue = capsuleValue;
        state.capsuleLength = capsuleValue.map((v) => maxValue ? v / maxValue : 0);
        const oneFifth = maxValue / 5;
        const labelData = Array.from(new Set(new Array(6).fill(0).map((v, i) => Math.ceil(i * oneFifth))));
        state.labelData = labelData;
      } catch (error) {
        console.warn(error);
      }
    };
    const numberSizeHandle = (val) => {
      return val + "px";
    };
    onMounted(() => {
      calcData(props.chartConfig.option);
    });
    useChartDataFetch(props.chartConfig, useChartEditStore, (newData) => {
      calcData(newData, "preview");
    });
    return (_ctx, _cache) => {
      return state.mergedConfig ? (openBlock(), createElementBlock("div", {
        key: 0,
        class: "go-dv-capsule-chart",
        style: normalizeStyle({
          fontSize: numberSizeHandle(state.mergedConfig.valueFontSize),
          paddingLeft: numberSizeHandle(state.mergedConfig.paddingLeft),
          paddingRight: numberSizeHandle(state.mergedConfig.paddingRight)
        })
      }, [
        createBaseVNode("div", _hoisted_1, [
          (openBlock(true), createElementBlock(Fragment, null, renderList(state.mergedConfig.dataset.source, (item) => {
            return openBlock(), createElementBlock("div", {
              key: item[state.mergedConfig.dataset.dimensions[0]],
              style: normalizeStyle({ height: state.capsuleItemHeight, lineHeight: state.capsuleItemHeight })
            }, toDisplayString(item[state.mergedConfig.dataset.dimensions[0]]), 5);
          }), 128)),
          _hoisted_2
        ]),
        createBaseVNode("div", _hoisted_3, [
          (openBlock(true), createElementBlock(Fragment, null, renderList(state.capsuleLength, (capsule, index) => {
            return openBlock(), createElementBlock("div", {
              key: index,
              class: "capsule-item",
              style: normalizeStyle({ height: state.capsuleItemHeight })
            }, [
              createBaseVNode("div", {
                class: "capsule-item-column",
                style: normalizeStyle(`width: ${capsule * 100}%; background-color: ${state.mergedConfig.colors[index % state.mergedConfig.colors.length]};height:calc(100% - ${2}px);`)
              }, [
                state.mergedConfig.showValue ? (openBlock(), createElementBlock("div", _hoisted_4, toDisplayString(state.capsuleValue[index]), 1)) : createCommentVNode("", true)
              ], 4)
            ], 4);
          }), 128)),
          createBaseVNode("div", _hoisted_5, [
            (openBlock(true), createElementBlock(Fragment, null, renderList(state.labelData, (label, index) => {
              return openBlock(), createElementBlock("div", {
                key: label + index
              }, toDisplayString(label), 1);
            }), 128))
          ])
        ]),
        state.mergedConfig.unit ? (openBlock(), createElementBlock("div", _hoisted_6, toDisplayString(state.mergedConfig.unit), 1)) : createCommentVNode("", true)
      ], 4)) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
