<template>
  <div class="student-exam-item">
    <p class="student-exam-item__title">{{ exam.title || '—' }}</p>

    <div class="student-exam-item__stats">
      <div class="student-exam-item__stat student-exam-item__stat--duration">
        <SvgIcon name="calendar" :size="11" color="#5d5d5d" />
        <span class="student-exam-item__stat-label">مدت آزمون :</span>
        <span class="student-exam-item__stat-value">{{ durationText }}</span>
      </div>
      <div class="student-exam-item__stat">
        <SvgIcon name="users-three" :size="11" color="#5d5d5d" />
        <span class="student-exam-item__stat-label">نمره قبولی :</span>
        <span class="student-exam-item__stat-value">{{ passingScoreText }}</span>
      </div>
      <div class="student-exam-item__stat">
        <SvgIcon name="file" :size="11" color="#5d5d5d" />
        <span class="student-exam-item__stat-label">تعداد سوال :</span>
        <span class="student-exam-item__stat-value">{{ questionsCountText }}</span>
      </div>
    </div>

    <div class="student-exam-item__actions">
      <BaseButton
        text="شروع آزمون"
        custom-class="student-exam-item__btn"
        @click="emit('start', exam)"
      >
        <template #appendIcon>
          <SvgIcon name="arrow-left" :size="14" color="#fff" />
        </template>
      </BaseButton>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import BaseButton from '@/components/BaseButton.vue'
import SvgIcon from '@/components/icons/SvgIcon.vue'

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

const emit = defineEmits(['start'])

const durationText = computed(() =>
  props.exam.durationMinutes == null ? '—' : `${props.exam.durationMinutes} دقیقه`
)
const passingScoreText = computed(() =>
  props.exam.minimumScore == null ? '—' : `${props.exam.minimumScore}`
)
const questionsCountText = computed(() =>
  props.exam.questionsCount == null ? '—' : `${props.exam.questionsCount}`
)
</script>

<style lang="scss" scoped>
.student-exam-item {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  background: rgba(255, 255, 255, 58%);
  box-shadow: 0 6.75px 19.425px rgba(0, 0, 0, 4%);
  border-radius: 0.75rem;
  margin-bottom: 0.625rem;

  @media (min-width: 1024px) {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
  }

  &__title {
    flex: 1 1 18%;
    font-family: var(--font-family-fa);
    font-weight: 400;
    font-size: 0.95rem;
    color: #4b4b4b;
    margin: 0;
    text-align: start;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    order: 3;

    @media (min-width: 1024px) {
      order: 0;
    }
  }

  &__stats {
    flex: 1 1 50%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
  }

  &__stat {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.875rem;
    border-radius: 0.75rem;
    background: rgba(107, 107, 107, 4%);
    font-family: var(--font-family-fa);
    white-space: nowrap;
  }

  &__stat--duration {
    border-radius: 1.375rem;
  }

  &__stat-label {
    font-weight: 300;
    font-size: 0.7rem;
    color: #535353;
  }

  &__stat-value {
    font-weight: 500;
    font-size: 0.75rem;
    color: #5d5d5d;
  }

  &__actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }

  &__btn {
    min-width: 6rem;
    padding: 0 1rem;
    height: 2rem;
  }
}
</style>
