<template>
  <div class="skeleton-loader" :class="type">
    <div v-if="type === 'card'" class="skeleton-card">
      <div class="skeleton-header">
        <div class="skeleton-circle"></div>
        <div class="skeleton-lines">
          <div class="skeleton-line short"></div>
          <div class="skeleton-line medium"></div>
        </div>
      </div>
      <div class="skeleton-content">
        <div class="skeleton-line long"></div>
        <div class="skeleton-line medium"></div>
        <div class="skeleton-line short"></div>
      </div>
    </div>

    <div v-else-if="type === 'table'" class="skeleton-table">
      <div v-for="i in 5" :key="i" class="skeleton-row">
        <div class="skeleton-cell"></div>
        <div class="skeleton-cell"></div>
        <div class="skeleton-cell"></div>
        <div class="skeleton-cell"></div>
      </div>
    </div>

    <div v-else-if="type === 'chart'" class="skeleton-chart">
      <div class="skeleton-chart-header">
        <div class="skeleton-line medium"></div>
        <div class="skeleton-line short"></div>
      </div>
      <div class="skeleton-chart-body">
        <div class="skeleton-bars">
          <div v-for="i in 6" :key="i" class="skeleton-bar" :style="{ height: Math.random() * 80 + 20 + '%' }"></div>
        </div>
      </div>
    </div>

    <div v-else class="skeleton-default">
      <div class="skeleton-line long"></div>
      <div class="skeleton-line medium"></div>
      <div class="skeleton-line short"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SkeletonLoader',
  props: {
    type: {
      type: String,
      default: 'default',
      validator: (value) => ['default', 'card', 'table', 'chart'].includes(value)
    }
  }
}
</script>

<style scoped>
.skeleton-loader {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.skeleton-card {
  background: rgba(30, 41, 59, 0.6);
  border-radius: 16px;
  padding: 1.5rem;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.skeleton-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.skeleton-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.2);
}

.skeleton-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.skeleton-content {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.skeleton-line {
  height: 12px;
  background: rgba(59, 130, 246, 0.2);
  border-radius: 6px;
}

.skeleton-line.short { width: 30%; }
.skeleton-line.medium { width: 60%; }
.skeleton-line.long { width: 90%; }

.skeleton-table {
  background: rgba(30, 41, 59, 0.6);
  border-radius: 16px;
  padding: 1rem;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.skeleton-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.skeleton-cell {
  height: 16px;
  background: rgba(59, 130, 246, 0.2);
  border-radius: 4px;
}

.skeleton-chart {
  background: rgba(30, 41, 59, 0.6);
  border-radius: 16px;
  padding: 1.5rem;
  border: 1px solid rgba(59, 130, 246, 0.2);
  height: 300px;
}

.skeleton-chart-header {
  margin-bottom: 2rem;
}

.skeleton-chart-body {
  height: 200px;
  display: flex;
  align-items: end;
}

.skeleton-bars {
  display: flex;
  align-items: end;
  gap: 1rem;
  width: 100%;
  height: 100%;
}

.skeleton-bar {
  flex: 1;
  background: rgba(59, 130, 246, 0.2);
  border-radius: 4px 4px 0 0;
  min-height: 20px;
}

.skeleton-default {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-loader {
    animation: none;
  }
}
</style>