<script setup lang="ts">
import { ref } from 'vue'

interface Emits {
  (e: 'close'): void
  (e: 'submit', payload: { name: string; campaignName: string }): void
}

const emit = defineEmits<Emits>()

const form = ref({
  name: '',
  campaignName: ''
})

const onClose = () => {
  emit('close')
}

const onSubmit = () => {
  const name = form.value.name.trim()
  const campaignName = form.value.campaignName.trim()

  if (!name || !campaignName) {
    return
  }

  emit('submit', { name, campaignName })
  form.value = { name: '', campaignName: '' }
}
</script>

<template>
  <div class="fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4" role="dialog" aria-modal="true">
    <div class="w-full max-w-lg rounded-2xl border border-indigo-400/20 bg-slate-950 p-6 shadow-2xl shadow-black/60">
      <div class="flex items-center justify-between">
        <h2 class="text-2xl font-bold text-white">새 프로젝트 만들기</h2>
        <button
          type="button"
          @click="onClose"
          class="rounded-md border border-slate-700/70 px-2 py-1 text-xs font-semibold text-slate-300"
        >
          닫기
        </button>
      </div>

      <p class="mt-2 text-sm text-slate-400">프로젝트 기본 정보만 입력해도 바로 저장됩니다.</p>

      <div class="mt-5 space-y-4">
        <label class="block space-y-2">
          <span class="text-sm text-slate-300">프로젝트명</span>
          <input
            v-model="form.name"
            type="text"
            placeholder="예: 여름 프로모션 캠페인"
            class="w-full rounded-xl border border-indigo-500/25 bg-slate-900 px-4 py-3 text-slate-100 outline-none focus:border-cyan-300"
          />
        </label>

        <label class="block space-y-2">
          <span class="text-sm text-slate-300">캠페인 표시명</span>
          <input
            v-model="form.campaignName"
            type="text"
            placeholder="예: 캠페인 1"
            class="w-full rounded-xl border border-indigo-500/25 bg-slate-900 px-4 py-3 text-slate-100 outline-none focus:border-cyan-300"
          />
        </label>
      </div>

      <div class="mt-6 flex justify-end gap-2">
        <button
          type="button"
          @click="onClose"
          class="rounded-md border border-slate-700 px-4 py-2 text-sm text-slate-300"
        >
          취소
        </button>
        <button
          type="button"
          @click="onSubmit"
          class="rounded-md bg-gradient-to-r from-indigo-500 to-cyan-500 px-4 py-2 text-sm font-semibold text-white"
        >
          생성
        </button>
      </div>
    </div>
  </div>
</template>
