<template>
  <component
    :is="to ? RouterLink : 'div'"
    :to="to || undefined"
    class="stat-card"
    :class="{ 'stat-card--linked': to }"
  >
    <SvgIcon name="card-corner-arrow" :size="'1.5rem'" class="stat-card__corner" />

    <div class="stat-card__head">
      <SvgIcon :name="icon" :size="'1.0625rem'" class="stat-card__head-icon" />
      <span class="stat-card__label">{{ label }}</span>
    </div>

    <div class="stat-card__body">
      <span class="stat-card__value">{{ value }}</span>
      <div class="stat-card__meta">
        <span class="stat-card__unit">{{ unit }}</span>
        <span class="stat-card__subtitle">{{ subtitle }}</span>
      </div>
    </div>
  </component>
</template>

<script setup>
import { RouterLink } from 'vue-router'
import SvgIcon from '@/components/icons/SvgIcon.vue'

defineProps({
  /** @type {import('vue').PropType<import('@/components/icons/icon-names').IconName>} */
  icon: { type: String, required: true },
  label: { type: String, default: '' },
  value: { type: [String, Number], default: '' },
  unit: { type: String, default: '' },
  subtitle: { type: String, default: '' },
  to: { type: [String, Object], default: null },
})
</script>

<style lang="scss" scoped>
.stat-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.125rem 1.25rem;
  min-height: 8.75rem;
  background: rgba(255, 255, 255, 58%);
  box-shadow: 0 6.75px 19.425px rgba(0, 0, 0, 4%);
  border-radius: 0.9375rem;
  color: inherit;
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;

  &--linked {
    cursor: pointer;

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 9px 24px rgba(0, 0, 0, 7%);
    }

    &:focus-visible {
      outline: 2px solid var(--color-primary);
      outline-offset: 3px;
    }
  }

  &__corner {
    position: absolute;
    inset-block-start: 0.875rem;
    inset-inline-end: 1.125rem;
  }

  &__head {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.375rem;
  }

  &__head-icon {
    order: 2;
  }

  &__label {
    order: 1;
    font-family: var(--font-family-fa);
    font-weight: 500;
    font-size: 1.125rem;
    color: #4b4b4b;
  }

  &__body {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.625rem;
    margin-top: auto;
  }

  &__value {
    font-family: var(--font-family-number-fa);
    font-weight: 700;
    font-size: 4rem;
    line-height: 1;
    color: var(--color-primary);
    text-shadow: 0 5.25px 8.625px rgba(243, 102, 117, 18%);
  }

  &__meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.125rem;
  }

  &__unit {
    font-family: var(--font-family-fa);
    font-weight: 300;
    font-size: 1.125rem;
    color: #6e6e6e;
  }

  &__subtitle {
    font-family: var(--font-family-fa);
    font-weight: 500;
    font-size: 1.25rem;
    color: #6e6e6e;
  }
}
</style>
