<template>
  <div class="ZhiChu_ModalFrameClose">
    <n-button text @click="clickBtn">
      <Button :w="w" :h="h" :dataStyle="option.dataStyle" />
    </n-button>
  </div>
</template>

<script setup lang="ts">
  import { computed, PropType, toRefs, watch, reactive, ref } 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 Button from './svg/button.vue';

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

  const { w, h } = toRefs(props.chartConfig.attr);
  const option = reactive({
    dataStyle: props.chartConfig.option.dataStyle,
    status: props.chartConfig.status,
  });

  // 单击交互
  const clickBtn = (val) => {
    closeModalFrame();
    eventHandlerHook(
      chartEditStore.getComponentList,
      props.chartConfig.events.interactConfigEvents,
      'click',
      val,
    );
  };

  // 默认点击隐藏弹窗及其所在分组的内容
  function closeModalFrame() {
    if (option.dataStyle.defaultCloseModal) {
      chartEditStore.getComponentList.forEach((element) => {
        if (element.isGroup && element?.groupList?.some((li) => li.key == 'ZhiChu_ModalFrame')) {
          element.status.hide = true;
        } else if (element.key == 'ZhiChu_ModalFrame') {
          element.status.hide = true;
          option.status.hide = true;
        }
      });
    }
  }
</script>

<style lang="scss" scoped>
  .ZhiChu_ModalFrameClose {
    display: flex;
    justify-content: center;
    text-align: center;
    width: v-bind('`${w}px`');
    height: v-bind('`${h}px`');
  }
</style>
