<template>
  <q-card
    class="stat-card"
    :class="{ 'stat-card--clickable': clickable }"
    @click="clickable && emit('click')"
  >
    <div class="flex justify-between items-start no-wrap">
      <span class="text-subtitle2 card-title">{{ title }}</span>
      <q-icon :name="icon" size="22px" class="card-icon" />
    </div>

    <div class="value-area">
      <span class="text-h5 value-text card-value">{{ value }}</span>

      <q-badge
        v-if="badge"
        :color="badgeColor"
        :label="badge"
        :style="customStyle"
        class="stat-badge"
      />
      <span
        v-else-if="subtitle"
        class="text-caption text-foreground card-subtitle"
        >{{ subtitle }}</span
      >
    </div>
  </q-card>
</template>

<script setup>
defineProps({
  title: { type: String, required: true },
  icon: { type: String, default: "mdi-information-outline" },
  value: { type: [String, Number], required: true },
  subtitle: { type: String, default: "" },
  badge: { type: String, default: "" },
  badgeColor: { type: String, default: "accent-1" },
  customStyle: { type: String, default: "padding: 4px" },
  clickable: { type: Boolean, default: false },
});

const emit = defineEmits(["click"]);
</script>

<style scoped lang="scss">
.stat-card {
  flex: 1 1 0;
  min-width: 0;
  height: 140px;
  border-radius: 12px;
  box-shadow: 0 0 0 1px #c0c0c0c0 !important;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition:
    background-color 0.2s,
    color 0.2s;

  .card-title {
    color: #1a1a1a;
    transition: color 0.2s;
  }
  .card-icon {
    color: #1a1a1a;
    transition: color 0.2s;
  }
  .card-value {
    color: $primary;
    transition: color 0.2s;
  }
  .card-subtitle {
    transition: color 0.2s;
  }
}

.stat-card--clickable {
  cursor: pointer;

  &:hover {
    background-color: $terciary !important;
    box-shadow: 0 0 0 1px $primary !important;
  }
}

.value-area {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.value-text {
  font-weight: 600;
  line-height: 1.2;
}

.stat-badge {
  font-size: 12px;
  border-radius: 8px;
  width: fit-content;
  color: $primary;
  transition:
    background-color 0.2s,
    color 0.2s;
}
</style>
