<script setup>
definePageMeta({
  layout: 'admin'
})

const route = useRoute()
const memberId = computed(() => String(route.params.id || ''))

const { data: member, error } = await useFetch(() => `/admin/api/members/${memberId.value}`, {
  default: () => null
})

/**
 * 저장된 회원 정보로 화면 상태를 갱신한다.
 * @param {Object} savedMember - 저장된 회원
 * @returns {void}
 */
const handleMemberSaved = (savedMember) => {
  member.value = savedMember
}
</script>

<template>
  <AdminMemberForm
    v-if="member"
    :member="member"
    mode="edit"
    @saved="handleMemberSaved"
  />
  <section v-else class="admin-member-detail bg-paper p-6">
    <div class="rounded-xl border border-line bg-white px-5 py-8 text-sm text-muted">
      {{ error?.data?.message || '회원 정보를 불러올 수 없습니다.' }}
    </div>
  </section>
</template>
