<?php 
session_start(); 
require 'db_connect.php';

try {
    $horoscopes = $users_db->query("SELECT * FROM horoscope ORDER BY id ASC")->fetchAll(PDO::FETCH_ASSOC);
    $numerology = $users_db->query("SELECT * FROM numerology ORDER BY number ASC")->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $horoscopes = [];
    $numerology = [];
}

$page_title = "Horoscope & Numerology | Astro Subhajit";
include 'header.php'; 
?>

<style>
    .tab-content { display: none; animation: fadeIn 0.5s ease-in-out; }
    .tab-content.active { display: block; }
    @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
</style>

<div class="bg-emerald-900 py-12 border-b-4 border-yellow-400 text-center">
    <h1 class="text-4xl font-extrabold text-white mb-2">Vedic Astrology Insights</h1>
    <p class="text-lg text-emerald-200">Discover what the stars and numbers hold for your future.</p>
</div>

<main class="max-w-7xl mx-auto px-4 py-10 w-full">
    <div class="flex flex-wrap justify-center gap-4 mb-12 border-b border-gray-300 pb-4">
        <button onclick="switchTab('weekly')" id="btn-weekly" class="tab-btn px-8 py-3 rounded-full font-bold text-lg transition-all bg-[#064e3b] text-white shadow-md">
            <i class="fa-solid fa-calendar-week me-2"></i> Weekly Horoscope
        </button>
        <button onclick="switchTab('yearly')" id="btn-yearly" class="tab-btn px-8 py-3 rounded-full font-bold text-lg transition-all bg-gray-200 text-gray-600">
            <i class="fa-solid fa-calendar-days me-2"></i> Yearly Horoscope
        </button>
        <button onclick="switchTab('numerology')" id="btn-numerology" class="tab-btn px-8 py-3 rounded-full font-bold text-lg transition-all bg-gray-200 text-gray-600">
            <i class="fa-solid fa-hashtag me-2"></i> Numerology Report
        </button>
    </div>

    <div id="weekly" class="tab-content active">
        <h2 class="text-3xl font-bold text-center text-emerald-900 mb-8">Weekly Outlook</h2>
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
            <?php foreach ($horoscopes as $sign): ?>
                <div class="bg-white rounded-xl shadow-lg border border-gray-200 p-6 hover:shadow-xl transition">
                    <div class="flex items-center mb-4 border-b pb-3">
                        <div class="w-12 h-12 bg-emerald-100 rounded-full flex items-center justify-center text-emerald-800 text-xl font-bold me-4">
                            <i class="fa-regular fa-star"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800"><?= htmlspecialchars($sign['sign_name']) ?></h3>
                    </div>
                    <p class="text-gray-600 leading-relaxed text-sm"><?= nl2br(htmlspecialchars($sign['weekly_content'] ?? '...')) ?></p>
                </div>
            <?php endforeach; ?>
        </div>
    </div>

    <div id="yearly" class="tab-content">
        <h2 class="text-3xl font-bold text-center text-emerald-900 mb-8">Yearly Forecast</h2>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
            <?php foreach ($horoscopes as $sign): ?>
                <div class="bg-white rounded-xl shadow-lg border-t-4 border-[#064e3b] p-6">
                    <h3 class="text-2xl font-bold text-gray-800 mb-3"><i class="fa-solid fa-sun text-yellow-500 me-3"></i> <?= htmlspecialchars($sign['sign_name']) ?></h3>
                    <p class="text-gray-600 leading-relaxed"><?= nl2br(htmlspecialchars($sign['yearly_content'] ?? '...')) ?></p>
                </div>
            <?php endforeach; ?>
        </div>
    </div>

    <div id="numerology" class="tab-content">
        <h2 class="text-3xl font-bold text-center text-emerald-900 mb-8">Numerological Guidance</h2>
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
            <?php foreach ($numerology as $num): ?>
                <div class="bg-gradient-to-br from-emerald-50 to-white rounded-xl shadow border border-emerald-100 p-6 text-center">
                    <div class="w-16 h-16 mx-auto bg-[#064e3b] text-white rounded-full flex items-center justify-center text-3xl font-extrabold mb-4"><?= htmlspecialchars($num['number']) ?></div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">Destiny <?= htmlspecialchars($num['number']) ?></h3>
                    <p class="text-gray-600 text-sm"><?= nl2br(htmlspecialchars($num['prediction'] ?? '...')) ?></p>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</main>

<script>
    function switchTab(tabId) {
        document.querySelectorAll('.tab-content').forEach(el => el.classList.remove('active'));
        document.querySelectorAll('.tab-btn').forEach(btn => {
            btn.classList.remove('bg-[#064e3b]', 'text-white', 'shadow-md');
            btn.classList.add('bg-gray-200', 'text-gray-600');
        });
        document.getElementById(tabId).classList.add('active');
        let activeBtn = document.getElementById('btn-' + tabId);
        activeBtn.classList.remove('bg-gray-200', 'text-gray-600');
        activeBtn.classList.add('bg-[#064e3b]', 'text-white', 'shadow-md');
    }
</script>
<?php include 'footer.php'; ?>