<script setup lang="ts">
import { Close } from '@element-plus/icons-vue'

interface FileItem {
  name: string
  url: string
  upload_time?: string
}
interface Props {
  modelValue: boolean
  index: number
  items: FileItem[]
}
withDefaults(defineProps<Props>(), {
  modelValue: false,
  index: 0
})
</script>

<template>
  <div class="image-viewer" v-if="modelValue">
    <div class="image-viewer__close" @click="$emit('update:modelValue', false)">
      <el-icon><Close /></el-icon>
    </div>
    <el-carousel :autoplay="false" :initial-index="index" arrow="always" height="100vh">
      <el-carousel-item v-for="item in items" :key="item.url">
        <div class="image-viewer__pic"><img :src="item.url" /></div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<style lang="scss">
.image-viewer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  background-color: rgba(0, 0, 0, 0.5);
}
.image-viewer__close {
  position: absolute;
  right: 40px;
  top: 40px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  opacity: 0.8;
  cursor: pointer;
  box-sizing: border-box;
  user-select: none;
  width: 44px;
  height: 44px;
  font-size: 24px;
  color: #fff;
  background-color: var(--el-text-color-regular);
  border-color: #fff;
}
.image-viewer__pic {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  img {
    max-width: 100%;
    max-height: 100%;
  }
}
</style>
