<template>
  <div  class="go-title-03">
    <img :width="w" :height="h" src="@/assets/images/chart/equipment/zhishengjibg.png" />
    <div class="titlebox">{{ title }}</div>
    <div class="valuebox">{{dataset}}<span class="unitbox">{{unit}}</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 {
  colors,
  title,
  unit,
  dataset,
  titleSize,
  unitSize,
  dataSize,
} = toRefs(props.chartConfig.option)

 // 数据callback处理（预览时触发）
 useChartDataFetch(props.chartConfig, useChartEditStore, (resData: any[]) => {
  props.chartConfig.option.dataset = resData;
});
</script>

<style lang="scss" scoped>
@include go('title-03') {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center; 

  .titlebox{
    position: absolute;
    top: 15%;
    height: 13%;
    display: flex;
    align-items: center;
    color: v-bind('colors[0]');
    font-size: v-bind('titleSize+"px"');
  }
  .valuebox{
    position: absolute;
    top: 33%;
    height: 15%;
    display: flex;
    align-items: end;
    color: v-bind('colors[1]');
    font-size: v-bind('dataSize+"px"');
    .unitbox{
      color: v-bind('colors[2]');
      font-size: v-bind('unitSize+"px"');
      margin-left: 3px;
      margin-bottom: 4px;
    }
  }
}
</style>
