<template>
  <div class="muc">
    <div class="muc__profile">
      <div class="muc__avatar">
        <img v-if="avatar" :src="avatar" alt="" />
        <SvgIcon v-else name="user" :size="40" color="#c2c2c2" />
      </div>
      <div class="muc__profile-info">
        <div class="muc__level">
          <span class="muc__level-label">شماره تماس :</span>
          <span class="muc__level-value muc__level-value--numeric">{{ phone }}</span>
        </div>
        <p class="muc__name">{{ fullName }}</p>
        <div class="muc__location">
          <SvgIcon name="map-pin-simple-area" :size="12" />
          <span>{{ city }}</span>
        </div>
      </div>
    </div>

    <div class="muc__stats">
      <div class="muc__stat">
        <span class="muc__stat-label">مدت عضویت</span>
        <div class="muc__stat-value">
          <span class="muc__stat-num">{{ membershipDays }}</span>
          <span class="muc__stat-unit">روز</span>
        </div>
      </div>

      <span class="muc__divider" />

      <div class="muc__stat">
        <span class="muc__stat-label">تعداد درخواست‌ها</span>
        <div class="muc__stat-value">
          <span class="muc__stat-num">{{ requestsCount }}</span>
          <span class="muc__stat-unit">درخواست</span>
        </div>
      </div>
    </div>

    <div class="muc__actions">
      <BaseButton text="افزودن روایت" custom-class="muc__btn" @click="emit('add-narrative')">
        <template #appendIcon>
          <SvgIcon name="plus" :size="16" color="#fff" />
        </template>
      </BaseButton>
      <BaseButton text="تکمیل اطلاعات" custom-class="muc__btn" @click="emit('complete-info')">
        <template #appendIcon>
          <SvgIcon name="arrow-left" :size="16" 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({
  profile: { type: Object, default: () => ({}) },
})

const emit = defineEmits(['complete-info', 'settings', 'add-narrative'])

const fullName = computed(() => props.profile.fullName || '—')
const city = computed(() => props.profile.city || '—')
const phone = computed(() => props.profile.phone || '—')
const avatar = computed(() => props.profile.avatar || '')
const membershipDays = computed(() => props.profile.membershipDays ?? '—')
const requestsCount = computed(() => props.profile.requestsCount ?? '—')
</script>

<style lang="scss" scoped>
.muc {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  background: #fff;
  box-shadow: 0 6.75px 19.425px rgba(0, 0, 0, 4%);
  border-radius: 0.75rem;
  margin-bottom: 0.75rem;

  @media (min-width: 1024px) {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 2rem;
  }

  &__actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  &__btn {
    min-width: 9rem;
    height: 2.5rem;
    padding: 0 1.25rem;
  }

  &__icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    background: rgba(0, 112, 116, 4%);
    cursor: pointer;
    transition: background 0.15s ease;

    &:hover {
      background: rgba(0, 112, 116, 8%);
    }
  }

  &__stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;

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

  &__stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    min-width: 3rem;
  }

  &__stat-label {
    font-family: var(--font-family-fa);
    font-weight: 500;
    font-size: 0.7rem;
    color: #a7a7a7;
    white-space: nowrap;
  }

  &__stat-value {
    display: inline-flex;
    align-items: baseline;
    gap: 0.25rem;
  }

  &__stat-num {
    font-family: var(--font-family-en);
    font-weight: 400;
    font-size: 1.2rem;
    color: #818181;
    line-height: 1.4;
  }

  &__stat-unit {
    font-family: var(--font-family-fa);
    font-weight: 300;
    font-size: 0.6rem;
    color: #929292;
  }

  &__divider {
    width: 1px;
    height: 1.5rem;
    background: #eee;
  }

  &__profile {
    display: flex;
    align-items: center;
    gap: 0.875rem;
  }

  &__profile-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.375rem;
    text-align: center;
  }

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

  &__location {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-family: var(--font-family-fa);
    font-weight: 400;
    font-size: 0.7rem;
    color: #989898;
  }

  &__level {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.875rem;
    border-radius: 0.75rem;
    background: rgba(0, 112, 116, 4%);
    font-family: var(--font-family-fa);
    color: #007074;
  }

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

  &__level-value {
    font-weight: 500;
    font-size: 0.75rem;

    &--numeric {
      font-family: var(--font-family-en);
    }
  }

  &__avatar {
    width: 5.625rem;
    height: 5.625rem;
    border-radius: 9999px;
    background: #fff;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}
</style>
