<template>
  <view class="skeleton" :style="style" :class="[variant]"></view>
</template>

<script setup lang="ts">
import { computed } from 'vue'

const props = withDefaults(defineProps<{
  width?: string
  height?: string
  variant?: 'text' | 'rect' | 'circle'
}>(), { variant: 'rect' })

const style = computed(() => ({
  width: props.width || (props.variant === 'circle' ? props.height : '100%'),
  height: props.height || '32rpx',
}))
</script>

<style lang="scss" scoped>
.skeleton {
  background: linear-gradient(90deg, $border 25%, $surface-warm 50%, $border 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8rpx;

  &.text {
    border-radius: 4rpx;
  }

  &.circle {
    border-radius: 50%;
  }
}

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

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