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

const props = defineProps<{
  size?: number;
  progress?: number;
  active?: boolean;
}>();

const rotation = computed(() => (props.progress ?? 0) * 360);
const wrapperStyle = computed(() => {
  if (props.active) return {};
  return {
    transform: `rotate(${rotation.value}deg)`,
    transition: 'transform 0.05s linear',
  };
});
</script>

<template>
  <svg
    :class="['gold-spinner', { 'is-active': active }]"
    :width="size ?? 48"
    :height="size ?? 48"
    viewBox="0 0 48 48"
    fill="none"
    xmlns="http://www.w3.org/2000/svg"
    :style="!active ? wrapperStyle : undefined"
  >
    <defs>
      <linearGradient id="gs-track" x1="0%" y1="0%" x2="100%" y2="100%">
        <stop offset="0%" stop-color="#D4AF37" stop-opacity="0.18" />
        <stop offset="50%" stop-color="#F0D875" stop-opacity="0.25" />
        <stop offset="100%" stop-color="#D4AF37" stop-opacity="0.18" />
      </linearGradient>
      <linearGradient id="gs-arc" x1="0%" y1="0%" x2="100%" y2="100%">
        <stop offset="0%" stop-color="#FFF4C8" />
        <stop offset="22%" stop-color="#F0D875" />
        <stop offset="50%" stop-color="#D4AF37" />
        <stop offset="78%" stop-color="#B8942B" />
        <stop offset="100%" stop-color="#8B6914" />
      </linearGradient>
      <filter id="gs-glow">
        <feGaussianBlur stdDeviation="1.2" result="blur" />
        <feMerge>
          <feMergeNode in="blur" />
          <feMergeNode in="SourceGraphic" />
        </feMerge>
      </filter>
      <radialGradient id="gs-dot" cx="50%" cy="50%" r="50%">
        <stop offset="0%" stop-color="#FFF4C8" />
        <stop offset="60%" stop-color="#F0D875" />
        <stop offset="100%" stop-color="#D4AF37" />
      </radialGradient>
    </defs>
    <circle cx="24" cy="24" r="20" stroke="url(#gs-track)" stroke-width="3" fill="none" />
    <circle
      cx="24"
      cy="24"
      r="20"
      stroke="url(#gs-arc)"
      stroke-width="3"
      fill="none"
      stroke-linecap="round"
      stroke-dasharray="31.4 94.2"
      filter="url(#gs-glow)"
    />
    <circle cx="24" cy="4" r="2.5" fill="url(#gs-dot)" filter="url(#gs-glow)">
      <animate
        v-if="active"
        attributeName="r"
        values="2.5;3.2;2.5"
        dur="1.2s"
        repeatCount="indefinite"
      />
    </circle>
    <circle v-if="active" cx="36" cy="13.5" r="1.8" fill="#F0D875" opacity="0.6">
      <animate attributeName="opacity" values="0.6;0.15;0.6" dur="0.9s" repeatCount="indefinite" begin="0.15s" />
    </circle>
    <circle v-if="active" cx="34" cy="34" r="1.5" fill="#D4AF37" opacity="0.4">
      <animate attributeName="opacity" values="0.4;0.1;0.4" dur="1.1s" repeatCount="indefinite" begin="0.35s" />
    </circle>
    <circle v-if="active" cx="14" cy="34" r="1.5" fill="#D4AF37" opacity="0.4">
      <animate attributeName="opacity" values="0.4;0.1;0.4" dur="1s" repeatCount="indefinite" begin="0.55s" />
    </circle>
  </svg>
</template>

<style scoped>
.gold-spinner {
  display: block;
  will-change: transform;
}

.gold-spinner.is-active {
  animation: gs-spin 0.8s linear infinite;
}

@keyframes gs-spin {
  to { transform: rotate(360deg); }
}
</style>
