<template>
  <div class="skeleton-card" :class="[variant, { animated }]">
    <div v-if="showTitle" class="skeleton-title"></div>

    <div
      v-for="i in lines"
      :key="i"
      class="skeleton-line"
      :style="{ width: lineWidths[(i - 1) % lineWidths.length] }"
    ></div>

    <div v-if="showActions" class="skeleton-actions">
      <div class="skeleton-btn skeleton-btn--short"></div>
      <div class="skeleton-btn skeleton-btn--long"></div>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  lines: {
    type: Number,
    default: 3
  },
  variant: {
    type: String,
    default: 'default',
    validator: (val) => ['default', 'compact', 'detailed'].includes(val)
  },
  showTitle: {
    type: Boolean,
    default: true
  },
  showActions: {
    type: Boolean,
    default: false
  },
  animated: {
    type: Boolean,
    default: true
  }
})

const lineWidths = ['85%', '95%', '78%', '90%', '82%', '88%', '92%', '75%', '87%', '96%']
</script>

<style scoped>
.skeleton-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-sizing: border-box;
}

.skeleton-card.default {
  padding: 16px;
}

.skeleton-card.compact {
  padding: 12px;
}

.skeleton-card.detailed {
  padding: 20px;
}

.skeleton-title {
  border-radius: 4px;
}

.skeleton-card.default .skeleton-title {
  height: 18px;
  width: 60%;
  margin-bottom: 12px;
}

.skeleton-card.compact .skeleton-title {
  height: 14px;
  width: 45%;
  margin-bottom: 8px;
}

.skeleton-card.detailed .skeleton-title {
  height: 22px;
  width: 70%;
  margin-bottom: 16px;
}

.skeleton-line {
  border-radius: 4px;
}

.skeleton-card.default .skeleton-line {
  height: 14px;
  margin-bottom: 8px;
}

.skeleton-card.compact .skeleton-line {
  height: 11px;
  margin-bottom: 6px;
}

.skeleton-card.detailed .skeleton-line {
  height: 16px;
  margin-bottom: 10px;
}

.skeleton-line:last-child {
  margin-bottom: 0;
}

.skeleton-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #f3f4f6;
}

.skeleton-btn {
  border-radius: 6px;
  height: 30px;
}

.skeleton-btn--short {
  width: 70px;
}

.skeleton-btn--long {
  width: 110px;
}

.skeleton-title,
.skeleton-line,
.skeleton-btn {
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
}

.skeleton-card.animated .skeleton-title,
.skeleton-card.animated .skeleton-line,
.skeleton-card.animated .skeleton-btn {
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@media (prefers-color-scheme: dark) {
  .skeleton-card {
    background: #1f2937;
    border-color: #374151;
  }

  .skeleton-title,
  .skeleton-line,
  .skeleton-btn {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
  }

  .skeleton-actions {
    border-top-color: #374151;
  }
}
</style>
