<template>
  <q-card :class="['metric-card', `metric-card--${variant}`]" flat>
    <span class="metric-label">
      {{ label }}
    </span>

    <strong class="metric-value">
      {{ value }}
    </strong>

    <span
      :class="['metric-caption', { 'metric-caption--nowrap': nowrapCaption }]"
    >
      {{ caption }}
    </span>
  </q-card>
</template>

<script setup>
defineProps({
  caption: { type: String, default: "" },
  label: { type: String, required: true },
  nowrapCaption: { type: Boolean, default: false },
  value: { type: String, required: true },
  variant: { type: String, default: "primary" },
});
</script>

<style scoped lang="scss">
.metric-card {
  display: grid;
  grid-template-rows: 56px 34px 22px;
  align-items: start;
  gap: 6px;
  min-height: 106px;
  min-width: 0;
  padding: 12px 16px;
  border: 1px solid #d9e3e7;
  border-radius: 12px;
  background: #f0f3f5;
  vertical-align: middle;
}

.metric-card--primary {
  border-top: 3px solid #b7f35a;
}

.metric-card--secondary {
  border-top: 3px solid #84a8a6;
}

.metric-label {
  display: flex;
  align-self: stretch;
  align-items: center;
  font-size: 19px;
  font-weight: 400;
  color: #4d4e4e;
  overflow-wrap: anywhere;
}

.metric-value {
  align-self: start;
  font-size: 24px;
  line-height: 1.15;
  color: #111212;
  overflow-wrap: anywhere;
}

.metric-caption {
  align-self: start;
  font-size: 14px;
  color: #4d4e4e;
  overflow-wrap: anywhere;
}

.metric-caption--nowrap {
  font-size: 13px;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .metric-card {
    grid-template-rows: auto;
    min-height: 0;
    padding: 14px;
  }

  .metric-label {
    font-size: 16px;
  }

  .metric-value {
    font-size: 21px;
  }

  .metric-caption {
    font-size: 13px;
  }

  .metric-caption--nowrap {
    font-size: 12px;
  }
}
</style>
