'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { lunarToSolar } from '@/lib/lunar-utils'; export default function CompatibilityForm() { const router = useRouter(); // Person 1 const [year1, setYear1] = useState(''); const [month1, setMonth1] = useState(''); const [day1, setDay1] = useState(''); const [hour1, setHour1] = useState(''); const [gender1, setGender1] = useState<'male' | 'female'>('male'); const [calendarType1, setCalendarType1] = useState<'solar' | 'lunar'>('solar'); const [isLeapMonth1, setIsLeapMonth1] = useState(false); // Person 2 const [year2, setYear2] = useState(''); const [month2, setMonth2] = useState(''); const [day2, setDay2] = useState(''); const [hour2, setHour2] = useState(''); const [gender2, setGender2] = useState<'male' | 'female'>('female'); const [calendarType2, setCalendarType2] = useState<'solar' | 'lunar'>('solar'); const [isLeapMonth2, setIsLeapMonth2] = useState(false); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!year1 || !month1 || !day1) { alert('첫 번째 사람의 생년월일을 모두 입력해주세요.'); return; } if (!year2 || !month2 || !day2) { alert('두 번째 사람의 생년월일을 모두 입력해주세요.'); return; } let finalYear1 = year1, finalMonth1 = month1, finalDay1 = day1; let finalYear2 = year2, finalMonth2 = month2, finalDay2 = day2; // 음력인 경우 양력으로 변환 if (calendarType1 === 'lunar') { const solar = lunarToSolar(parseInt(year1), parseInt(month1), parseInt(day1), isLeapMonth1); finalYear1 = solar.year.toString(); finalMonth1 = solar.month.toString(); finalDay1 = solar.day.toString(); } if (calendarType2 === 'lunar') { const solar = lunarToSolar(parseInt(year2), parseInt(month2), parseInt(day2), isLeapMonth2); finalYear2 = solar.year.toString(); finalMonth2 = solar.month.toString(); finalDay2 = solar.day.toString(); } // URL 파라미터로 전달 const params = new URLSearchParams({ year1: finalYear1, month1: finalMonth1, day1: finalDay1, gender1, year2: finalYear2, month2: finalMonth2, day2: finalDay2, gender2, }); if (hour1) params.append('hour1', hour1); if (hour2) params.append('hour2', hour2); router.push(`/compatibility/result?${params.toString()}`); }; return (
{/* Person 1 */}

👤 첫 번째 사람

본인의 정보를 입력하세요

{/* 생년월일 */}
setYear1(e.target.value)} required /> setMonth1(e.target.value)} required /> setDay1(e.target.value)} required />
{/* 태어난 시간 */}
{/* 양력/음력 선택 */}
{calendarType1 === 'lunar' && (
)}
{/* 성별 선택 */}
{/* Person 2 */}

👤 두 번째 사람

상대방의 정보를 입력하세요

{/* 생년월일 */}
setYear2(e.target.value)} required /> setMonth2(e.target.value)} required /> setDay2(e.target.value)} required />
{/* 태어난 시간 */}
{/* 양력/음력 선택 */}
{calendarType2 === 'lunar' && (
)}
{/* 성별 선택 */}
{/* 제출 버튼 */}

* 태어난 시간을 정확히 아시면 더 정확한 궁합을 확인할 수 있습니다.

); }