<template>
  <div class="custom-text-box">
    <div class="content">
      {{ option.dataset }}
    </div>
  </div>
</template>
<script setup>
import { toRefs, shallowReactive, watch, ref, computed } from 'vue';
import { useChartDataFetch } from '../../../hooks/useChartDataFetch.hook';
import { useChartEditStore } from '@/store/modules/chart/chartEditStore';

const config = ref(null);

import('./config.js').then(module => {
  config.value = module;
});

// 计算属性
const configOption = computed(() => {
  return config.value ? config.value.option : {};
});

const props = defineProps({
  chartConfig: {
    type: Object,
    required: true
  }
});

const option = shallowReactive({
  dataset: configOption.dataset
});

const { w, h } = toRefs(props.chartConfig.attr);
const { size, gradient } = toRefs(props.chartConfig.option);

const { from, to, deg } = gradient.value;

console.log(from, to, deg);

watch(
  () => props.chartConfig.option.dataset,
  newData => {
    option.dataset = newData;
  },
  {
    immediate: true,
    deep: false
  }
);

useChartDataFetch(props.chartConfig, useChartEditStore, newData => {
  option.dataset = newData;
});
</script>

<style lang="less" scoped>
.custom-text-box {
  display: flex;
  align-items: center;
  justify-content: center;
  .content {
    font-size: v-bind('size + "px"');
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent; /* 兼容非WebKit浏览器 */
    background-image: linear-gradient(v-bind('deg + "deg"'), v-bind('from'), v-bind('to'));
  }
}
</style>
