<template>
  <div class="student-session-item">
    <div>
      <p class="student-session-item__title">{{ session.title || '—' }}</p>
      <div class="student-session-item__hours">
        <SvgIcon name="calendar" :size="9" color="#007074" />
        <span class="student-session-item__hours-label">مهلت :</span>
        <span class="student-session-item__hours-value">{{ deadlineText }}</span>
      </div>
    </div>

    <div class="student-session-item__badges">
      <Badge v-if="isComplete" variant="success">تکمیل شده</Badge>
      <Badge v-if="session.isSeen" variant="success">دیده شده</Badge>
      <Badge v-if="session.grade != null" variant="primary" label="نمره" :value="session.grade" />
      <Badge v-if="session.homeworksCount > 0" icon="paper-plane">دارای تکلیف</Badge>
      <Badge v-if="session.examsCount > 0" icon="file">دارای آزمون</Badge>
      <Badge v-if="isOnline" icon="users-three">جلسه آنلاین</Badge>
    </div>

    <div class="student-session-item__actions">
      <BaseButton
        text="شروع یادگیری"
        custom-class="student-session-item__btn"
        @click="emit('start', session)"
      >
        <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'
import { formatJalaaliDate } from '@/utils/date-utils'

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

const emit = defineEmits(['start'])

const deadlineText = computed(
  () => formatJalaaliDate(props.session.deadline || props.session.endDate) || '—'
)

const isOnline = computed(() => props.session.type === 'online')
const isComplete = computed(() => props.session.isComplete === true)
</script>

<style lang="scss" scoped>
.student-session-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;
  }

  &__title {
    flex: 1 1 22%;
    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: 4;

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

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

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

  &__hours-label {
    font-weight: 300;
    font-size: 0.65rem;
    color: #007074;
  }

  &__hours-value {
    font-weight: 500;
    font-size: 0.75rem;
    color: #007074;
  }

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

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