<template>
  <div class="cns" @click="emit('show-details', consultant)">
    <div class="cns__heading">
      <p class="cns__title">{{ consultant.title }}</p>
      <p class="cns__subtitle">شماره درخواست : {{ consultant.requestNumber }}</p>
    </div>

    <div class="cns__meta">
      <Badge
        variant="neutral"
        size="sm"
        icon="calendar"
        :label="`زمان :`"
        :value="`${consultant.timeLabel} | ${consultant.dateLabel}`"
      />
      <Badge :variant="tone" size="sm" dot :value="consultant.statusLabel" />
    </div>
  </div>
</template>

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

// Backend statuses are open/answered/closed. Legacy keys stay in place for any
// pre-migration cached data.
const TONE_MAP = {
  approved: 'success',
  rejected: 'danger',
  pending: 'neutral',
  open: 'neutral',
  answered: 'success',
  closed: 'info',
}

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

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

const tone = computed(() => TONE_MAP[props.consultant.status] || 'neutral')
</script>

<style lang="scss" scoped>
.cns {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  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;
  cursor: pointer;
  transition: background 0.15s ease;

  &:hover {
    background: rgba(255, 255, 255, 75%);
  }

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

  &__heading {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: end;
    gap: 0.125rem;

    @media (min-width: 1024px) {
      min-width: 7rem;
    }
  }

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

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

  &__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;

    @media (min-width: 1024px) {
      flex: 1;
      justify-content: center;
    }
  }
}
</style>
