<template>
  <div class="WuRenJiShiShiHuaMian">
    <div class="list">
      <div v-for="item in option.dataset" :key="item.key">
        <div class="item">
          <video
            style="border: 2px solid green; padding: 5px"
            preload="auto"
            crossOrigin="anonymous"
            playsinline
            autoplay
            :object-fit="option.dataset.fit"
            :loop="option.dataStyle.videoloop"
            :muted="option.dataStyle.videomuted"
            :width="`${option.dataStyle.videowidth}`"
            :height="`${option.dataStyle.videoheight}`"
            :src="item.videoUrl"
          />
          <Title class="title" :item="item" :dataStyle="option.dataStyle" />
        </div>
      </div>
    </div>
  </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 Title from './svg/title.vue';
  import dayjs from 'dayjs';

  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,
    dataStyle: props.chartConfig.option.dataStyle,
  });

  watch(
    () => option.dataStyle.videowidth,
    () => {
      option.dataStyle.titleWidth = option.dataStyle.videowidth;
      option.dataStyle.titleHeight = 30 * (option.dataStyle.titleWidth / 181);
    },
    {
      immediate: true,
      deep: true,
    },
  );
</script>

<style lang="scss" scoped>
  .WuRenJiShiShiHuaMian {
    overflow-y: auto;
    background: v-bind('`${option.dataStyle.backgroud}`');
    width: v-bind('`${w}px`');
    height: v-bind('`${h}px`');
  }

  .WuRenJiShiShiHuaMian::-webkit-scrollbar {
    display: none;
  }

  .WuRenJiShiShiHuaMian {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    margin-top: v-bind('`${option.dataStyle.margintop}px`');
    margin-left: v-bind('`${option.dataStyle.marginleft}px`');
  }

  .item {
    display: inline-block;
  }

  video {
    display: block;
    object-fit: v-bind('option.dataStyle.videofit');
  }

  .title {
    margin-top: v-bind('`${option.dataStyle.titleMarginTop}px`');
  }
</style>
