<template>
  <div class="activity-card">
    <SvgIcon name="card-corner-arrow" :size="'1.5rem'" class="activity-card__corner" />

    <div class="activity-card__thumb" :class="{ 'activity-card__thumb--circle': circle }">
      <img v-if="avatarUrl" :src="avatarUrl" :alt="title" class="activity-card__thumb-img" />
      <SvgIcon v-else :name="thumbIcon" :size="'1.5rem'" color="#848484" />
    </div>

    <div class="activity-card__body">
      <p class="activity-card__title">{{ title }}</p>

      <div class="activity-card__meta">
        <SvgIcon :name="metaIcon" :size="'0.875rem'" class="activity-card__meta-icon" />
        <div class="activity-card__rows">
          <p v-for="(row, i) in meta" :key="i" class="activity-card__row">
            <span class="activity-card__row-label">{{ row.label }}</span>
            <span
              class="activity-card__row-value"
              :class="{ 'activity-card__row-value--num': row.numeric }"
            >
              {{ row.value }}
            </span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import SvgIcon from '@/components/icons/SvgIcon.vue'

defineProps({
  title: { type: String, default: '' },
  /** rows of { label, value, numeric? } */
  meta: { type: Array, default: () => [] },
  /** @type {import('vue').PropType<import('@/components/icons/icon-names').IconName>} */
  metaIcon: { type: String, default: 'calendar' },
  /** thumbnail glyph shown when there is no avatarUrl */
  thumbIcon: { type: String, default: 'play' },
  /** render the thumbnail as a circular avatar instead of a rounded square */
  circle: { type: Boolean, default: false },
  avatarUrl: { type: String, default: '' },
})
</script>

<style lang="scss" scoped>
.activity-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  min-height: 5.9375rem;
  background: rgba(255, 255, 255, 58%);
  box-shadow: 0 6.75px 19.425px rgba(0, 0, 0, 4%);
  border-radius: 0.9375rem;

  &__corner {
    position: absolute;
    inset-block-start: 0.75rem;
    inset-inline-end: 1rem;
  }

  &__thumb {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3.6875rem;
    height: 3.6875rem;
    background: #f4f4f4;
    border-radius: 0.9375rem;
    overflow: hidden;

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

  &__thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  &__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.625rem;
    text-align: start;
    min-width: 0;
  }

  &__title {
    margin: 0;
    font-family: var(--font-family-fa);
    font-weight: 400;
    font-size: 0.875rem;
    color: #4b4b4b;
  }

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

  &__meta-icon {
    order: 2;
    margin-top: 0.125rem;
  }

  &__rows {
    order: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  &__row {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin: 0;
    font-family: var(--font-family-fa);
    font-weight: 400;
    font-size: 0.6875rem;
    color: #4b4b4b;
  }

  &__row-value {
    &--num {
      font-family: var(--font-family-number-fa);
      direction: ltr;
    }
  }
}
</style>
