Files
saju-web/app/result/page.tsx
gahusb e233e18a55 feat: 카카오 앱 키 설정, 절기 기준 계산, 대운 정밀화
카카오 앱 키 설정:
- 환경 변수(.env.local)를 통한 안전한 키 관리
- NEXT_PUBLIC_KAKAO_APP_KEY 환경 변수 사용
- layout.tsx에서 환경 변수 읽어서 Kakao SDK 초기화
- .env.local 템플릿 파일 생성 (키 발급 가이드 포함)

음력 변환 정확도 개선:
- 24절기 계산 라이브러리 구현 (solar-terms.ts)
- 절기 기준 월주 계산으로 정확도 향상
- 입춘, 경칩, 청명 등 12개 월 절기 지원
- getSolarTermMonthBranch() - 절기 기준 월 지지 계산
- getCurrentSolarTerm() - 현재 절기 확인
- 사주 결과 페이지에 절기 정보 표시

대운 시작 나이 정밀 계산:
- 절기 기준 대운수 계산 구현
- 양남음녀(순행), 음남양녀(역행) 정확한 일수 계산
- 3일 = 1세 공식 적용
- calculateDaeunStartAge() 함수로 정밀 계산
- 이전 평균 8세 → 실제 계산값 (1~10세 범위)
- 대운 섹션에 시작 나이 계산 근거 표시

문서화:
- SETUP.md 생성
  - 카카오 앱 키 발급 및 설정 가이드
  - 절기 기준 사주 계산 설명
  - 대운 계산 원리 설명
  - 음력 변환 사용법
  - 기술 스택 및 개발 환경

사주 결과 페이지 개선:
- 절기 정보 표시 (녹색 박스)
- 대운 시작 나이 설명 추가
- 사용자에게 계산 원리 투명하게 공개

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-12 00:07:59 +09:00

382 lines
19 KiB
TypeScript

import { calculateSaju } from '@/lib/saju-calculator';
import Link from 'next/link';
import PDFButton from '../components/PDFButton';
import ShareButtons from '../components/ShareButtons';
import { calculateDaeun, getCurrentDaeun, getDaeunDescription } from '@/lib/daeun-calculator';
import { getCurrentSolarTerm, getSolarTermName, getSolarTermMonthBranch } from '@/lib/solar-terms';
import { EARTHLY_BRANCHES_KR } from '@/lib/saju-calculator';
interface PageProps {
searchParams: Promise<{
year: string;
month: string;
day: string;
hour?: string;
gender: 'male' | 'female';
calendarType: 'solar' | 'lunar';
}>;
}
export default async function ResultPage({ searchParams }: PageProps) {
const params = await searchParams;
const { year, month, day, hour, gender } = params;
const yearNum = parseInt(year);
const monthNum = parseInt(month);
const dayNum = parseInt(day);
const hourNum = hour ? parseInt(hour) : null;
const sajuData = calculateSaju(yearNum, monthNum, dayNum, hourNum, gender);
// 절기 정보
const solarTermIndex = getCurrentSolarTerm(yearNum, monthNum, dayNum);
const solarTermName = getSolarTermName(solarTermIndex);
const monthBranchIndex = getSolarTermMonthBranch(yearNum, monthNum, dayNum);
const monthBranchName = EARTHLY_BRANCHES_KR[monthBranchIndex];
// 대운 계산
const daeunList = calculateDaeun(
yearNum,
monthNum,
dayNum,
gender,
sajuData.month.stem,
sajuData.month.branch
);
const currentYear = new Date().getFullYear();
const currentDaeun = getCurrentDaeun(daeunList, currentYear);
return (
<div className="min-h-screen bg-gradient-to-br from-indigo-50 via-purple-50 to-pink-50">
{/* Navigation */}
<nav className="bg-white/80 backdrop-blur-md border-b border-gray-200 sticky top-0 z-50">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex justify-between items-center h-16">
<Link href="/" className="text-2xl font-bold bg-gradient-to-r from-indigo-600 to-purple-600 bg-clip-text text-transparent">
🔮
</Link>
<Link
href="/"
className="text-gray-700 hover:text-indigo-600 transition font-medium"
>
</Link>
</div>
</div>
</nav>
{/* Result Content */}
<div id="pdf-content" className="max-w-6xl mx-auto px-4 py-12">
{/* Header */}
<div className="text-center mb-12">
<h1 className="text-4xl md:text-5xl font-bold text-gray-900 mb-4">
</h1>
<p className="text-xl text-gray-600">
{yearNum} {monthNum} {dayNum} {hourNum !== null && `${hourNum}`}
{gender === 'male' ? ' 남성' : ' 여성'}
</p>
</div>
{/* 사주팔자 표 */}
<div className="bg-white rounded-3xl shadow-2xl p-8 md:p-12 mb-8">
<h2 className="text-3xl font-bold text-gray-900 mb-8 text-center"> ()</h2>
<div className="overflow-x-auto">
<table className="w-full border-collapse">
<thead>
<tr className="bg-gradient-to-r from-indigo-600 to-purple-600 text-white">
<th className="py-4 px-6 text-center font-bold text-lg"></th>
{sajuData.hour && <th className="py-4 px-6 text-center font-bold text-lg"> ()</th>}
<th className="py-4 px-6 text-center font-bold text-lg"> ()</th>
<th className="py-4 px-6 text-center font-bold text-lg"> ()</th>
<th className="py-4 px-6 text-center font-bold text-lg"> ()</th>
</tr>
</thead>
<tbody>
{/* 천간 */}
<tr className="border-b border-gray-200 hover:bg-indigo-50 transition">
<td className="py-4 px-6 text-center font-semibold text-gray-700"> ()</td>
{sajuData.hour && (
<td className="py-4 px-6 text-center">
<div className="text-3xl font-bold text-indigo-600">{sajuData.hour.stem}</div>
<div className="text-sm text-gray-600 mt-1">{sajuData.hour.stemKr}</div>
</td>
)}
<td className="py-4 px-6 text-center bg-blue-50">
<div className="text-3xl font-bold text-blue-600">{sajuData.day.stem}</div>
<div className="text-sm text-gray-600 mt-1">{sajuData.day.stemKr}</div>
<div className="text-xs text-blue-600 font-semibold mt-1"> ()</div>
</td>
<td className="py-4 px-6 text-center">
<div className="text-3xl font-bold text-indigo-600">{sajuData.month.stem}</div>
<div className="text-sm text-gray-600 mt-1">{sajuData.month.stemKr}</div>
</td>
<td className="py-4 px-6 text-center">
<div className="text-3xl font-bold text-indigo-600">{sajuData.year.stem}</div>
<div className="text-sm text-gray-600 mt-1">{sajuData.year.stemKr}</div>
</td>
</tr>
{/* 지지 */}
<tr className="border-b border-gray-200 hover:bg-purple-50 transition">
<td className="py-4 px-6 text-center font-semibold text-gray-700"> ()</td>
{sajuData.hour && (
<td className="py-4 px-6 text-center">
<div className="text-3xl font-bold text-purple-600">{sajuData.hour.branch}</div>
<div className="text-sm text-gray-600 mt-1">{sajuData.hour.branchKr}</div>
</td>
)}
<td className="py-4 px-6 text-center bg-blue-50">
<div className="text-3xl font-bold text-blue-600">{sajuData.day.branch}</div>
<div className="text-sm text-gray-600 mt-1">{sajuData.day.branchKr}</div>
</td>
<td className="py-4 px-6 text-center">
<div className="text-3xl font-bold text-purple-600">{sajuData.month.branch}</div>
<div className="text-sm text-gray-600 mt-1">{sajuData.month.branchKr}</div>
</td>
<td className="py-4 px-6 text-center">
<div className="text-3xl font-bold text-purple-600">{sajuData.year.branch}</div>
<div className="text-sm text-gray-600 mt-1">{sajuData.year.branchKr}</div>
</td>
</tr>
{/* 십성 */}
<tr className="border-b border-gray-200 hover:bg-emerald-50 transition">
<td className="py-4 px-6 text-center font-semibold text-gray-700"> ()</td>
{sajuData.hour && (
<td className="py-4 px-6 text-center">
<div className="text-lg font-semibold text-emerald-600">{sajuData.hour.tenGod}</div>
</td>
)}
<td className="py-4 px-6 text-center bg-blue-50">
<div className="text-lg font-semibold text-blue-600">{sajuData.day.tenGod}</div>
</td>
<td className="py-4 px-6 text-center">
<div className="text-lg font-semibold text-emerald-600">{sajuData.month.tenGod}</div>
</td>
<td className="py-4 px-6 text-center">
<div className="text-lg font-semibold text-emerald-600">{sajuData.year.tenGod}</div>
</td>
</tr>
{/* 십이운성 */}
<tr className="hover:bg-pink-50 transition">
<td className="py-4 px-6 text-center font-semibold text-gray-700"></td>
{sajuData.hour && (
<td className="py-4 px-6 text-center">
<div className="text-lg font-semibold text-pink-600">{sajuData.hour.fortune}</div>
</td>
)}
<td className="py-4 px-6 text-center bg-blue-50">
<div className="text-lg font-semibold text-blue-600">{sajuData.day.fortune}</div>
</td>
<td className="py-4 px-6 text-center">
<div className="text-lg font-semibold text-pink-600">{sajuData.month.fortune}</div>
</td>
<td className="py-4 px-6 text-center">
<div className="text-lg font-semibold text-pink-600">{sajuData.year.fortune}</div>
</td>
</tr>
</tbody>
</table>
</div>
<div className="mt-6 space-y-3">
<div className="p-4 bg-blue-50 rounded-xl">
<p className="text-sm text-gray-700">
<strong className="text-blue-600"> ():</strong> {sajuData.day.stem}({sajuData.day.stemKr}) - .
</p>
</div>
<div className="p-4 bg-green-50 rounded-xl">
<p className="text-sm text-gray-700">
<strong className="text-green-600"> ():</strong> {solarTermName} -
{monthBranchName}.
</p>
<p className="text-xs text-gray-600 mt-1">
* 24 .
</p>
</div>
</div>
</div>
{/* 사주 해석 */}
<div className="grid md:grid-cols-2 gap-8 mb-8">
{/* 성격 */}
<div className="bg-white rounded-2xl shadow-lg p-8">
<h3 className="text-2xl font-bold text-gray-900 mb-4 flex items-center">
<span className="text-3xl mr-3">👤</span>
</h3>
<div className="space-y-3 text-gray-700">
<p className="leading-relaxed">
<strong className="text-indigo-600">{sajuData.day.stem}({sajuData.day.stemKr})</strong>
{sajuData.day.element === '木' && ' 나무처럼 성장하고 발전하려는 의지가 강합니다. 창의적이고 진취적인 성향을 가지고 있습니다.'}
{sajuData.day.element === '火' && ' 불처럼 열정적이고 활동적입니다. 리더십이 있고 사교성이 뛰어납니다.'}
{sajuData.day.element === '土' && ' 흙처럼 안정적이고 신뢰감 있습니다. 포용력이 있고 책임감이 강합니다.'}
{sajuData.day.element === '金' && ' 금속처럼 강인하고 원칙적입니다. 결단력 있고 의리를 중시합니다.'}
{sajuData.day.element === '水' && ' 물처럼 유연하고 지혜롭습니다. 적응력이 뛰어나고 사려 깊습니다.'}
</p>
</div>
</div>
{/* 운세 */}
<div className="bg-white rounded-2xl shadow-lg p-8">
<h3 className="text-2xl font-bold text-gray-900 mb-4 flex items-center">
<span className="text-3xl mr-3">🌟</span>
</h3>
<div className="space-y-3 text-gray-700">
<p className="leading-relaxed">
<strong className="text-purple-600">{sajuData.day.fortune}</strong>,
{sajuData.day.fortune === '장생' && ' 새로운 시작과 성장의 시기입니다.'}
{sajuData.day.fortune === '목욕' && ' 정화와 준비의 시기입니다.'}
{sajuData.day.fortune === '관대' && ' 사회적으로 인정받는 시기입니다.'}
{sajuData.day.fortune === '건록' && ' 안정되고 왕성한 활동의 시기입니다.'}
{sajuData.day.fortune === '제왕' && ' 최고의 전성기를 맞이하는 시기입니다.'}
{sajuData.day.fortune === '쇠' && ' 조금씩 힘이 약해지는 시기입니다.'}
{sajuData.day.fortune === '병' && ' 어려움이 있을 수 있는 시기입니다.'}
{sajuData.day.fortune === '사' && ' 끝과 새 시작을 준비하는 시기입니다.'}
{sajuData.day.fortune === '묘' && ' 잠시 휴식이 필요한 시기입니다.'}
{sajuData.day.fortune === '절' && ' 극복과 인내가 필요한 시기입니다.'}
{sajuData.day.fortune === '태' && ' 새로운 기운이 싹트는 시기입니다.'}
{sajuData.day.fortune === '양' && ' 성장을 준비하는 시기입니다.'}
</p>
</div>
</div>
</div>
{/* 대운 (大運) */}
<div className="bg-white rounded-3xl shadow-2xl p-8 md:p-12 mb-8">
<h2 className="text-3xl font-bold text-gray-900 mb-8 text-center">
🔄 () - 10
</h2>
{/* 현재 대운 */}
{currentDaeun && (
<div className="bg-gradient-to-r from-indigo-500 to-purple-500 rounded-2xl p-6 mb-8 text-white">
<h3 className="text-2xl font-bold mb-4 text-center"> </h3>
<div className="text-center mb-4">
<div className="text-5xl font-bold mb-2">
{currentDaeun.stem}{currentDaeun.branch}
</div>
<div className="text-xl mb-2">
{currentDaeun.stemKr}{currentDaeun.branchKr}
</div>
<div className="text-lg opacity-90">
{currentDaeun.age} ~ {currentDaeun.age + 9} ({currentDaeun.startYear} ~ {currentDaeun.endYear})
</div>
</div>
<p className="text-center leading-relaxed">
{getDaeunDescription(currentDaeun, sajuData.day.stem)}
</p>
</div>
)}
{/* 전체 대운 목록 */}
<div className="grid md:grid-cols-2 lg:grid-cols-4 gap-4">
{daeunList.map((daeun, index) => {
const isCurrent = currentDaeun &&
daeun.startYear === currentDaeun.startYear &&
daeun.endYear === currentDaeun.endYear;
return (
<div
key={index}
className={`rounded-xl p-4 border-2 transition ${
isCurrent
? 'bg-indigo-50 border-indigo-400'
: 'bg-gray-50 border-gray-200 hover:border-indigo-300'
}`}
>
<div className="text-center">
<div className="text-3xl font-bold text-gray-900 mb-1">
{daeun.stem}{daeun.branch}
</div>
<div className="text-sm text-gray-600 mb-2">
{daeun.stemKr}{daeun.branchKr}
</div>
<div className="text-xs text-gray-500">
{daeun.age} ~ {daeun.age + 9}
</div>
<div className="text-xs text-gray-400">
{daeun.startYear} ~ {daeun.endYear}
</div>
{isCurrent && (
<div className="mt-2">
<span className="inline-block bg-indigo-600 text-white text-xs px-3 py-1 rounded-full font-semibold">
</span>
</div>
)}
</div>
</div>
);
})}
</div>
<div className="mt-6 p-4 bg-indigo-50 rounded-xl">
<p className="text-sm text-gray-700 mb-2">
<strong className="text-indigo-600">():</strong> 10 .
, .
</p>
{daeunList.length > 0 && (
<p className="text-xs text-gray-600">
* {daeunList[0].age} . (3 = 1)
</p>
)}
</div>
</div>
{/* 추가 기능 버튼 */}
<div className="grid md:grid-cols-2 lg:grid-cols-4 gap-6">
<Link
href={`/fortune?${new URLSearchParams(params as any).toString()}`}
className="bg-white rounded-xl p-6 shadow-lg hover:shadow-xl transition text-center group"
>
<div className="text-4xl mb-3">🌟</div>
<h3 className="text-xl font-bold text-gray-900 mb-2"> </h3>
<p className="text-gray-600 text-sm"> </p>
</Link>
<Link
href="/compatibility"
className="bg-white rounded-xl p-6 shadow-lg hover:shadow-xl transition text-center group"
>
<div className="text-4xl mb-3">💕</div>
<h3 className="text-xl font-bold text-gray-900 mb-2"> </h3>
<p className="text-gray-600 text-sm"> </p>
</Link>
<PDFButton
elementId="pdf-content"
filename={`사주팔자_${yearNum}${monthNum}${dayNum}.pdf`}
buttonText="사주 PDF 저장"
/>
<ShareButtons
title={`내 사주팔자 - ${yearNum}년생 ${gender === 'male' ? '남성' : '여성'}`}
description={`일간: ${sajuData.day.stem}(${sajuData.day.stemKr}) | ${sajuData.day.element}`}
/>
</div>
</div>
{/* Footer */}
<footer className="bg-gray-900 text-white py-12 px-4 mt-20">
<div className="max-w-7xl mx-auto text-center">
<div className="text-2xl font-bold mb-4 bg-gradient-to-r from-indigo-400 to-purple-400 bg-clip-text text-transparent">
🔮
</div>
<p className="text-gray-400 mb-6">
</p>
<div className="text-sm text-gray-500">
<p>문의: bgg8988@gmail.com | <a href="https://jaengseung-made.com" target="_blank" rel="noopener noreferrer" className="hover:text-indigo-400"></a></p>
<p className="mt-2">&copy; 2025 . All rights reserved.</p>
</div>
</div>
</footer>
</div>
);
}