<template>
  <div class="student-lesson-item">
    <div class="student-lesson-item__head">
      <span class="student-lesson-item__decor" aria-hidden="true">
        <img
          v-if="lesson.coverUrl"
          :src="lesson.coverUrl"
          :alt="lesson.title || ''"
          class="student-lesson-item__cover"
        />
        <SvgIcon v-else name="users-three" :size="20" color="rgba(0, 112, 116, 0.31)" />
      </span>
      <div>
        <p class="student-lesson-item__title">{{ lesson.title || '—' }}</p>
        <Badge
          variant="primary"
          label="ظرفیت :"
          :value="capacityText"
          class="student-lesson-item__hours"
        >
          <template #prepend>
            <SvgIcon name="users-three" :size="11" color="#007074" />
          </template>
        </Badge>
      </div>
    </div>

    <div class="student-lesson-item__stats">
      <Badge
        variant="neutral"
        label="استاد :"
        :value="teacherText"
        class="student-lesson-item__stat"
      >
        <template #prepend>
          <SvgIcon name="user" :size="12" color="#5d5d5d" />
        </template>
      </Badge>

      <Badge
        variant="neutral"
        label="تعداد جلسات :"
        :value="sessionsText"
        class="student-lesson-item__stat"
      >
        <template #prepend>
          <SvgIcon name="list-bullets" :size="12" color="#5d5d5d" />
        </template>
      </Badge>
    </div>

    <div class="student-lesson-item__actions">
      <BaseButton
        text="جزئیات درس"
        custom-class="student-lesson-item__details-btn"
        @click="emit('show-details', lesson)"
      >
        <template #appendIcon>
          <SvgIcon name="arrow-left" :size="14" color="#fff" />
        </template>
      </BaseButton>
    </div>
  </div>
</template>

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

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

const emit = defineEmits(['show-details'])

const capacityText = computed(() =>
  props.lesson.capacity == null ? '—' : `${props.lesson.capacity} نفر`
)
const sessionsText = computed(() =>
  props.lesson.sessionsCount == null ? '—' : `${props.lesson.sessionsCount} جلسه`
)

const teacherText = computed(() => props.lesson.teacher?.name || '—')
</script>

<style lang="scss" scoped>
.student-lesson-item {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.625rem;
  padding: 0.875rem 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;
  }

  &__head {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex: 1 1 22%;
    min-width: 0;
    justify-content: flex-start;
  }

  &__decor {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.75rem;
    background: rgba(0, 112, 116, 4%);
    flex-shrink: 0;
    overflow: hidden;
  }

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

  &__title {
    font-family: var(--font-family-fa);
    font-weight: 400;
    font-size: 0.95rem;
    color: #4b4b4b;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

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

  &__hours.badge,
  &__stat.badge {
    padding: 0.375rem 0.875rem;

    :deep(.badge__label) {
      font-size: 0.7rem;
      opacity: 1;
    }
  }

  &__hours.badge {
    background: rgba(0, 112, 116, 4%);
    color: #007074;
  }

  &__stat.badge {
    background: rgba(107, 107, 107, 4%);
    color: #5d5d5d;
  }

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

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