<template>
  <div
    class="ZhiGan_WuRenJiImage"
    @click="clickBtn"
    @dblclick="dblclickBtn"
    @contextmenu="rightclickBtn"
    @mouseenter="mouseenterBtn"
    @mouseleave="mouseleaveBtn"
  >
    <n-image :width="w" :height="h" :src="option.dataset.value" preview-disabled />
    <img
      class="Tupian"
      :width="w"
      :height="h"
      src="@/assets/images/chart/zhigan/component/ZhiGan_WuRenJiImage.png"
    />
  </div>
</template>

<script setup lang="ts">
  import { computed, PropType, toRefs, watch, reactive, ref, onMounted } from 'vue';
  import { CreateComponentType } from '@/packages/index.d';
  import { icon } from '@/plugins';
  import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore';
  import { useChartDataFetch } from '@/hooks';
  import { eventHandlerHook } from '@/hooks/eventHandler.hook';
  import { EventBus } from '@/utils/eventBus';

  const chartEditStore = useChartEditStore();
  const props = defineProps({
    chartConfig: {
      type: Object as PropType<CreateComponentType>,
      required: true,
    },
  });
  const { w, h } = toRefs(props.chartConfig.attr);

  const option = reactive({
    dataset: props.chartConfig.option.dataset,
  });

  const clickBtn = (val) => {
    eventHandlerHook(
      chartEditStore.getComponentList,
      props.chartConfig.events.interactConfigEvents,
      'click',
      val,
    );
  };
  const dblclickBtn = (val) => {
    eventHandlerHook(
      chartEditStore.getComponentList,
      props.chartConfig.events.interactConfigEvents,
      'dblclick',
      val,
    );
  };
  const rightclickBtn = (event) => {
    event.preventDefault(); // 阻止默认的右键菜单
    eventHandlerHook(
      chartEditStore.getComponentList,
      props.chartConfig.events.interactConfigEvents,
      'rightclick',
    );
  };
  const mouseenterBtn = (val) => {
    eventHandlerHook(
      chartEditStore.getComponentList,
      props.chartConfig.events.interactConfigEvents,
      'mousein',
      val,
    );
  };
  const mouseleaveBtn = (val) => {
    eventHandlerHook(
      chartEditStore.getComponentList,
      props.chartConfig.events.interactConfigEvents,
      'mouseout',
      val,
    );
  };
  onMounted(() => {
    // 获取eventBus传过来的值
    EventBus.on(props.chartConfig.id + 'click', (data) => {
      console.log('data', data);
    });
  });
</script>

<style lang="scss" scoped>
  .ZhiGan_WuRenJiImage {
    width: v-bind('`${w}px`');
    height: v-bind('`${h}px`');
    cursor: pointer;
  }
  .Tupian {
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 1;
  }
</style>
