<template>
  <div class="student-term-summary">
    <div class="student-term-summary__cover">
      <img v-if="term.coverUrl" :src="term.coverUrl" :alt="term.title" />
    </div>

    <div class="student-term-summary__info">
      <div class="student-term-summary__status" :class="`student-term-summary__status--${status}`">
        <span class="student-term-summary__status-label">وضعیت دوره :</span>
        <span class="student-term-summary__status-value">{{ statusLabel }}</span>
      </div>

      <p class="student-term-summary__title">{{ term.title || '—' }}</p>

      <div class="student-term-summary__teacher">
        <span class="student-term-summary__teacher-label">تعداد دوره ها:</span>
        <span class="student-term-summary__teacher-name">{{ courseCount }}</span>
      </div>
    </div>

    <div class="student-term-summary__dates">
      <div class="student-term-summary__date">
        <span class="student-term-summary__date-label">تاریخ پایان :</span>
        <span class="student-term-summary__date-value">{{ endDate }}</span>
      </div>
      <span class="student-term-summary__date-divider" />
      <div class="student-term-summary__date">
        <span class="student-term-summary__date-label">تاریخ شروع :</span>
        <span class="student-term-summary__date-value">{{ startDate }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { STUDENT_COURSE_STATUS } from '@/enums'
import { formatJalaaliDate } from '@/utils/date-utils'

const props = defineProps({
  enrollment: { type: Object, required: true },
})

const term = computed(() => props.enrollment.term ?? {})

const status = computed(() => props.enrollment.status || 'active')

const statusLabel = computed(() => STUDENT_COURSE_STATUS[status.value] || '—')

const courseCount = computed(() => term.value?.coursesCount ?? '—')

const startDate = computed(() => formatJalaaliDate(term.value.startsAt) || '—')

const endDate = computed(() => formatJalaaliDate(term.value.endsAt) || '—')
</script>

<style lang="scss" scoped>
.student-term-summary {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
  padding: 0.875rem 1.25rem;
  background: rgba(255, 255, 255, 40%);
  box-shadow: 0 6.75px 19.425px rgba(0, 0, 0, 4%);
  border-radius: 0.75rem;
  margin-bottom: 0.75rem;

  @media (min-width: 1024px) {
    flex-direction: row;
    align-items: center;
    min-height: 9.9rem;
    padding: 0.875rem 2.25rem;
  }

  &__cover {
    width: 100%;
    height: 8rem;
    border-radius: 0.75rem;
    background: #f4f4f4;
    overflow: hidden;
    order: 1;

    @media (min-width: 1024px) {
      width: 19rem;
      height: 8rem;
      flex-shrink: 0;
    }

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

  &__info {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 0.5rem;
    text-align: end;
    order: 2;
  }

  &__status {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 1rem;
    border-radius: 0.75rem;
    font-family: var(--font-family-fa);
    white-space: nowrap;

    &--active {
      background: rgba(0, 112, 116, 4%);
      color: #007074;
    }

    &--completed {
      background: rgba(0, 154, 18, 6%);
      color: #009a12;
    }
  }

  &__status-label {
    font-weight: 400;
    font-size: 0.65rem;
    color: inherit;
  }

  &__status-value {
    font-weight: 500;
    font-size: 0.75rem;
  }

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

  &__teacher {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-family: var(--font-family-fa);
    font-size: 0.75rem;
    color: #4b4b4b;
  }

  &__teacher-label {
    font-weight: 400;
  }

  &__teacher-name {
    font-weight: 400;
  }

  &__dates {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.375rem 1.125rem;
    border-radius: 1.375rem;
    background: rgba(107, 107, 107, 4%);
    white-space: nowrap;
    align-self: center;
    order: 3;

    @media (min-width: 1024px) {
      align-self: center;
    }
  }

  &__date {
    display: inline-flex;
    align-items: baseline;
    gap: 0.375rem;
  }

  &__date-label {
    font-family: var(--font-family-fa);
    font-weight: 400;
    font-size: 0.6rem;
    color: #535353;
  }

  &__date-value {
    font-family: var(--font-family-en);
    font-weight: 400;
    font-size: 0.75rem;
    color: #5d5d5d;
  }

  &__date-divider {
    width: 1px;
    height: 0.625rem;
    background: #dadada;
  }
}
</style>
