<template>
  <div  class="go-title-xuncha">
    <img class="img" :width="w" :height="h" src="@/assets/images/chart/xunchaguiji/onlinenumbg.png" />
    <div class="divbox">
      <span class="labelbox">{{ labelText }}</span>
      <span class="valbox">{{ dataset }}</span>
      <span class="unitbox">{{ unitText }}</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { PropType, toRefs } from 'vue'
import { CreateComponentType } from '@/packages/index.d'
import { useChartDataFetch } from '@/hooks';
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore';

const props = defineProps({
  chartConfig: {
    type: Object as PropType<CreateComponentType>,
    required: true
  }
})

const { w, h } = toRefs(props.chartConfig.attr)
const {
  labelText,
  labelSize,
  labelColor,
  valSize,
  valColor,
  valFlod,
  unitText,
  unitSize,
  unitColor,
  dataset
} = toRefs(props.chartConfig.option)
 // 数据callback处理（预览时触发）
 useChartDataFetch(props.chartConfig, useChartEditStore, (resData: any[]) => {
  props.chartConfig.option.dataset = resData;
});
</script>

<style lang="scss" scoped>
@include go('title-xuncha') {
  position: relative;
  display: flex;
  align-items: center; 
  .img{
    position: absolute;
  }
  .divbox{
    display: flex;
    align-items: center; 
    position: absolute;
    left: 30%;
    .labelbox{
      color: v-bind('labelColor');
      font-size: v-bind('labelSize+"px"');
    }
    .valbox{
      margin-left: 12px;
      font-size: v-bind('valSize+"px"');
      font-weight: v-bind('valFlod');
      color: v-bind('valColor');
    }
    .unitbox{
      margin-top: 5px;
      color: v-bind('unitColor');
      font-size: v-bind('unitSize+"px"');
    }
  }
}
</style>
