<template>
  <div class="mnar" @click="emit('show-details', narrative)">
    <div class="mnar__heading">
      <span class="mnar__code">{{ narrative.code }}</span>
      <div class="mnar__title-wrap">
        <p class="mnar__title">{{ narrative.title }}</p>
        <p class="mnar__subtitle">تاریخ ثبت: {{ narrative.submittedAt }}</p>
      </div>
    </div>

    <div class="mnar__meta">
      <div class="mnar__pill" :class="`mnar__pill--${narrative.kindTone}`">
        <span class="mnar__pill-label">روایت :</span>
        <span class="mnar__pill-value">{{ narrative.kindLabel }}</span>
      </div>
    </div>

    <div class="mnar__actions" @click.stop>
      <CircleButton
        tooltip="ویرایش روایت"
        bg-color="rgba(107, 107, 107, 0.04)"
        @click="emit('edit', narrative)"
      >
        <template #icon>
          <SvgIcon name="pencil" :size="18" color="#535353" />
        </template>
      </CircleButton>
      <CircleButton
        tooltip="حذف روایت"
        bg-color="rgba(243, 102, 117, 0.06)"
        @click="emit('delete', narrative)"
      >
        <template #icon>
          <SvgIcon name="trash" :size="18" color="var(--color-error)" />
        </template>
      </CircleButton>
    </div>
  </div>
</template>

<script setup>
import SvgIcon from '@/components/icons/SvgIcon.vue'
import CircleButton from '@/components/CircleButton.vue'

defineProps({
  narrative: { type: Object, required: true },
})

const emit = defineEmits(['show-details', 'edit', 'delete'])
</script>

<style lang="scss" scoped>
.mnar {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  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;

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

  &__heading {
    display: flex;
    align-items: center;
    gap: 0.625rem;

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

  &__title-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: end;
    gap: 0.2rem;
  }

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

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

  &__code {
    font-family: var(--font-family-en);
    font-weight: 800;
    font-size: 2.75rem;
    line-height: 1;
    color: #f0f0f0;
  }

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

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

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

  &__pill-label {
    font-weight: 400;
    font-size: 0.65rem;
  }

  &__pill-value {
    font-weight: 400;
    font-size: 0.75rem;
  }

  &__pill--pink {
    background: rgba(243, 102, 117, 7%);

    .mnar__pill-label,
    .mnar__pill-value {
      color: #f55d6d;
    }
  }

  &__pill--gold {
    background: rgba(116, 102, 0, 4%);

    .mnar__pill-label,
    .mnar__pill-value {
      color: #b6842d;
    }
  }

  &__actions {
    display: flex;
    justify-content: center;
    gap: 6px;

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