<template>
  <div class="bg-[#f5f7fa] flex flex-col h-screen overflow-hidden">
    <TopNavBar class="shrink-0" :title="`房间相册(${albumList.length})`" backgroundColor="transparent" />

    <div
      class="scroll-container min-h-0 flex-1 overflow-auto scrollbar-none [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden">
      <div class="pb-[24px]">
        <div class="grid-container">
          <div class="album-item" v-for="(item, index) in albumList" :key="index">
            <div class="album-image-wrapper">
              <img class="album-image" :src="item.photoUrl" @click="handlePreview(item.photoUrl)">

              <div class="album-title">{{ item.name }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from "vue";
import { usePictureStore } from "@/store";
import { showImagePreview } from 'vant';
import TopNavBar from "@/components/TopNavBar/index.vue";

const pictureStore = usePictureStore();

const albumList = computed(() =>
  Array.isArray(pictureStore.previewImageData) ? pictureStore.previewImageData : [],
);

// 处理图片预览
const handlePreview = (photoUrl) => {
  showImagePreview({
    images: albumList.value.map((item) => item.photoUrl)
  });
};
</script>

<style scoped lang="scss">
.grid-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr); // 每行2列
  grid-gap: 8px;
  padding: 12px;
}

.album-item {
  position: relative;
  width: 100%;
}

.album-image-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1; // 保持宽高1:1
  border-radius: 8px;
  overflow: hidden;
}

.album-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.album-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: linear-gradient(180deg,
      rgba(0, 0, 0, 0) 0%,
      rgba(0, 0, 0, 0.6) 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  span-overflow: ellipsis;
  border-radius: 0 0 8px 8px;
}
</style>
