<template>
  <div class="ecommerce-banner" :style="{ height: height }">
    <el-carousel height="height" motion-blur :indicator-position="indicatorPos" :arrow="arrow">
      <el-carousel-item v-for="(item, index) in list" :key="index">
        <costomImg :url="item" :preview-list="srcList" :is-view="isViewVal"></costomImg>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>
<script setup>
import { ref, reactive, onMounted, watch, computed } from 'vue';
import { isEmpty, getAssetsFile } from '@/utils';
import costomImg from '@/components/costomImg.vue';

const props = defineProps({
  height: { type: String, default: '320px' },
  name: { type: String, default: 'agricultural' },
  imglist: {
    type: Array,
    default: () => {
      return [];
    },
  },
  indicatorPos: {
    type: String,
    default: '',
  },
  arrow: {
    type: String,
    default: 'hover',
  },
  isView: {
    type: Boolean,
    default: false,
  },
});

let nameVal = ref(props.name);
let list = reactive(props.imglist);

let srcList = computed(() => {
  let list = [];
  list = props.imglist.map((m) => {
    return getAssetsFile(m);
  });
  return list;
});

let isViewVal = ref(props.isView);

watch(
  () => (props.list, props.imglist, props.isView),
  () => {
    nameVal.value = props.name;
    list = props.imglist;
    isViewVal.value = props.isView;
  },
  {
    immediate: true,
  }
);
</script>
<style lang="scss" scoped>
.ecommerce-banner {
  width: 100%;
  ::v-deep() {
    .el-image {
      width: 100%;
      height: 100%;
    }
    .el-carousel__item {
      border-radius: 16px !important;
    }
  }
}
</style>
