<template>
  <view class="skeleton-list" :class="layout">
    <!-- 网格布局骨架屏 -->
    <template v-if="layout === 'grid'">
      <view v-for="i in count" :key="i" class="skeleton-grid-item">
        <view class="skeleton-cover"></view>
        <view class="skeleton-info">
          <view class="skeleton-title"></view>
          <view class="skeleton-meta"></view>
        </view>
      </view>
    </template>

    <!-- 列表布局骨架屏 -->
    <template v-else-if="layout === 'list'">
      <view v-for="i in count" :key="i" class="skeleton-list-item">
        <view class="skeleton-avatar"></view>
        <view class="skeleton-content">
          <view class="skeleton-title"></view>
          <view class="skeleton-desc"></view>
        </view>
      </view>
    </template>

    <!-- 搜索结果骨架屏 -->
    <template v-else-if="layout === 'search-result'">
      <view v-for="i in count" :key="i" class="skeleton-result-item">
        <view class="skeleton-cover"></view>
        <view class="skeleton-content">
          <view class="skeleton-title"></view>
          <view class="skeleton-title short"></view>
          <view class="skeleton-meta"></view>
        </view>
      </view>
    </template>

    <!-- 历史记录骨架屏 -->
    <template v-else-if="layout === 'history'">
      <view v-for="i in count" :key="i" class="skeleton-history-card">
        <view class="skeleton-cover">
          <view class="skeleton-duration"></view>
        </view>
        <view class="skeleton-info">
          <view class="skeleton-title"></view>
          <view class="skeleton-meta"></view>
        </view>
      </view>
    </template>
  </view>
</template>

<script setup lang="ts">
interface Props {
  layout?: 'grid' | 'list' | 'search-result' | 'history';
  count?: number;
}

withDefaults(defineProps<Props>(), {
  layout: 'grid',
  count: 6,
});
</script>

<style scoped>
/* 通用骨架屏动画 */
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-list {
  padding: 24rpx;
}

/* 网格布局骨架屏 - 用于 albums/index.vue */
.skeleton-list.grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20rpx;
}

.skeleton-grid-item {
  width: calc(50% - 10rpx);
  background: #ffffff;
  border-radius: 16rpx;
  overflow: hidden;
}

.skeleton-grid-item .skeleton-cover {
  width: 100%;
  height: 200rpx;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.skeleton-grid-item .skeleton-info {
  padding: 20rpx;
}

.skeleton-grid-item .skeleton-title {
  height: 28rpx;
  width: 80%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;
  margin-bottom: 12rpx;
}

.skeleton-grid-item .skeleton-meta {
  height: 22rpx;
  width: 50%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;
}

/* 列表布局骨架屏 */
.skeleton-list.list {
  display: flex;
  flex-direction: column;
  gap: 16rpx;
}

.skeleton-list-item {
  display: flex;
  align-items: center;
  gap: 20rpx;
  padding: 20rpx;
  background: #ffffff;
  border-radius: 12rpx;
}

.skeleton-avatar {
  width: 100rpx;
  height: 100rpx;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 12rpx;
  flex-shrink: 0;
}

.skeleton-content {
  flex: 1;
}

.skeleton-list-item .skeleton-title {
  height: 28rpx;
  width: 60%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;
  margin-bottom: 12rpx;
}

.skeleton-list-item .skeleton-desc {
  height: 22rpx;
  width: 40%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;
}

/* 搜索结果骨架屏 - 用于 search/index.vue */
.skeleton-list.search-result {
  display: flex;
  flex-direction: column;
  gap: 16rpx;
}

.skeleton-result-item {
  display: flex;
  gap: 20rpx;
  padding: 20rpx;
  background: #ffffff;
  border-radius: 16rpx;
}

.skeleton-result-item .skeleton-cover {
  width: 100rpx;
  height: 100rpx;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 12rpx;
  flex-shrink: 0;
}

.skeleton-result-item .skeleton-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.skeleton-result-item .skeleton-title {
  height: 28rpx;
  width: 80%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;
  margin-bottom: 8rpx;
}

.skeleton-result-item .skeleton-title.short {
  width: 50%;
  margin-bottom: 8rpx;
}

.skeleton-result-item .skeleton-meta {
  height: 20rpx;
  width: 30%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;
}

/* 历史记录骨架屏 - 用于 history/index.vue */
.skeleton-list.history {
  display: flex;
  flex-wrap: wrap;
  gap: 20rpx;
}

.skeleton-history-card {
  width: calc(50% - 10rpx);
  background: #ffffff;
  border-radius: 16rpx;
  overflow: hidden;
}

.skeleton-history-card .skeleton-cover {
  position: relative;
  width: 100%;
  height: 240rpx;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.skeleton-duration {
  position: absolute;
  bottom: 12rpx;
  right: 12rpx;
  width: 60rpx;
  height: 24rpx;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;
}

.skeleton-history-card .skeleton-info {
  padding: 20rpx;
}

.skeleton-history-card .skeleton-title {
  height: 28rpx;
  width: 80%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;
  margin-bottom: 12rpx;
}

.skeleton-history-card .skeleton-meta {
  height: 22rpx;
  width: 50%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;
}
</style>
