<?php
require_once __DIR__ . '/config.php';
$settings = getSiteSettings();
$flash = getFlash();
$csrf = generateCSRF();
$currentUser = isUserLoggedIn() ? getCurrentUser() : null;
$currentLawyer = isLawyerLoggedIn() ? getCurrentLawyer() : null;
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description"
        content="<?= $metaDescription ?? 'MeeVakeel - Connect with Expert Lawyers Online across India. Get legal advice for Property, Criminal, Family, Divorce, Corporate law and more.' ?>">
    <meta name="keywords"
        content="<?= $metaKeywords ?? 'lawyer online, legal consultation, property lawyer, criminal lawyer, family lawyer, Hyderabad lawyer, Telangana advocate' ?>">
    <meta property="og:title" content="<?= $pageTitle ?? 'MeeVakeel - Connect with Expert Lawyers Online' ?>">
    <meta property="og:description"
        content="<?= $metaDescription ?? 'India\'s trusted online legal consultation platform' ?>">
    <meta property="og:image" content="<?= SITE_URL ?>/assets/images/og-image.jpg">
    <meta property="og:url" content="<?= SITE_URL . $_SERVER['REQUEST_URI'] ?>">
    <meta name="twitter:card" content="summary_large_image">
    <title><?= $pageTitle ?? 'MeeVakeel - Connect with Expert Lawyers Online' ?></title>

    <!-- Canonical URL -->
    <link rel="canonical" href="<?= SITE_URL . $_SERVER['REQUEST_URI'] ?>">

    <!-- Bootstrap 5 -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <!-- Google Fonts -->
    <link
        href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700;800&family=DM+Sans:wght@300;400;500;600;700&display=swap"
        rel="stylesheet">
    <!-- Select2 -->
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet">
    <!-- Fav Icon -->
    <link rel="icon" type="image/x-icon" href="<?= SITE_URL ?>/assets/images/fav.png">
    <!-- Custom CSS -->
    <link rel="stylesheet" href="<?= SITE_URL ?>/assets/css/style.css">

    <!-- Schema Markup -->
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "LegalService",
        "name": "MeeVakeel",
        "description": "Online Legal Consultation Platform",
        "url": "<?= SITE_URL ?>",
        "telephone": "<?= $settings['site_phone'] ?? '' ?>",
        "address": {
            "@type": "PostalAddress",
            "addressLocality": "Hyderabad",
            "addressRegion": "Telangana",
            "addressCountry": "IN"
        }
    }
    </script>
</head>

<body>

    <!-- Top Bar -->
    <div class="top-bar">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-6">
                    <!-- <span><i class="fas fa-phone-alt me-1"></i> <?= $settings['site_phone'] ?? '+91 9876543210' ?></span> -->
                    <span class="ms-3">
                        <i class="fas fa-envelope me-1"></i>
                        <a href="mailto:<?= $settings['site_email'] ?? 'enquiry@meevakeel.com' ?>"
                            class="text-decoration-none text-white">
                            <?= $settings['site_email'] ?? 'enquiry@meevakeel.com' ?>
                        </a>
                    </span>
                </div>
                <div class="col-md-6 text-end">
                    <!-- <a href="https://wa.me/<?= $settings['site_whatsapp'] ?? '9876543210' ?>" target="_blank" class="me-3">
                    <i class="fab fa-whatsapp me-1"></i> WhatsApp
                </a> -->
                    <?php if ($currentUser): ?>
                    <a href="<?= SITE_URL ?>/client/dashboard.php">My Account</a>
                    <?php elseif ($currentLawyer): ?>
                    <a href="<?= SITE_URL ?>/lawyer/dashboard.php">Lawyer Dashboard</a>
                    <?php else: ?>
                    <a href="<?= SITE_URL ?>/login.php" class="me-2"><i class="fas fa-user-circle"></i> Login</a>
                    <a href="<?= SITE_URL ?>/register.php"><i class="fas fa-edit"></i> Register</a>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Navbar -->
    <nav class="navbar navbar-expand-lg navbar-dark main-navbar sticky-top">
        <div class="container">
            <a class="navbar-brand" href="<?= SITE_URL ?>/">
                <!-- <span class="brand-icon"><i class="fas fa-balance-scale"></i></span>
            <span class="brand-text">Nyaya <span class="brand-accent">Guru</span></span> -->
                <img src="<?= SITE_URL ?>/assets/images/meevakeel.png" alt="" />
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainNav">
                <span class="navbar-toggler-icon"><i class="fas fa-bars"></i></span>
            </button>
            <div class="collapse navbar-collapse" id="mainNav">
                <ul class="navbar-nav mx-auto">
                    <li class="nav-item"><a class="nav-link" href="<?= SITE_URL ?>/">Home</a></li>

                    <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#"
                            data-bs-toggle="dropdown">Legal Services</a>
                        <div class="dropdown-menu mega-menu">
                            <?php
$db = getDB();

$cats = $db->query("
    SELECT *
    FROM legal_categories
    WHERE status = 1
    ORDER BY sort_order
")->fetchAll();
?>
                            <div class="row">
                                <!-- Left Column -->
                                <div class="col-lg-6">
                                    <h6 class="mega-title mb-3">Targeted Services</h6>

                                    <?php foreach($cats as $cat): ?>
                                    <?php if($cat['sort_order'] >= 1 && $cat['sort_order'] <= 20): ?>
                                    <a href="<?= SITE_URL ?>/lawyers.php?category=<?= $cat['id'] ?>"
                                        class="dropdown-item">
                                        <i class="<?= $cat['icon'] ?> me-2 text-gold"></i>
                                        <?= $cat['name'] ?>
                                    </a>
                                    <?php endif; ?>
                                    <?php endforeach; ?>
                                </div>

                                <!-- Right Column -->
                                <div class="col-lg-6">
                                    <h6 class="mega-title mb-3">Advocate Services</h6>

                                    <?php foreach($cats as $cat): ?>
                                    <?php if($cat['sort_order'] >= 21): ?>
                                    <a href="<?= SITE_URL ?>/lawyers.php?category=<?= $cat['id'] ?>"
                                        class="dropdown-item">
                                        <i class="<?= $cat['icon'] ?> me-2 text-gold"></i>
                                        <?= $cat['name'] ?>
                                    </a>
                                    <?php endif; ?>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">Opportunities</a>
                        <div class="dropdown-menu mega-menu" style="width:auto">
                            <div class="mb-2">
                                <a href="<?= SITE_URL ?>/pages/careers.php" class="dropdown-item">
                                    <i class="fas fa-user-graduate me-2 text-gold"></i>Internship
                                </a>
                            </div>
                            <div class="mb-2">
                                <a href="<?= SITE_URL ?>/pages/careers.php" class="dropdown-item">
                                    <i class="fas fa-compass me-2 text-gold"></i>Career Guidance
                                </a>
                            </div>
                            <div class="mb-2">
                                <a href="<?= SITE_URL ?>/pages/careers.php" class="dropdown-item">
                                    <i class="fas fa-briefcase me-2 text-gold"></i>Job Notifications
                                </a>
                            </div>
                        </div>
                    </li>
                    <li class="nav-item"><a class="nav-link" href="<?= SITE_URL ?>/newsletter.php">Newsletter</a></li>
                    <li class="nav-item"><a class="nav-link"
                            href="<?= SITE_URL ?>/pages/student-internship.php">Judgements</a></li>

                    <li class="nav-item"><a class="nav-link" href="<?= SITE_URL ?>/pages/contact.php">Contact</a></li>
                    <li class="nav-item"><a class="nav-link" href="<?= SITE_URL ?>/pages/about.php">About</a></li>
                </ul>
                <div class="navbar-actions my-lg-0 my-3">
                    <?php if ($currentUser): ?>
                    <div class="dropdown">
                        <button class="btn btn-outline-gold dropdown-toggle" data-bs-toggle="dropdown">
                            <i class="fas fa-user-circle me-1"></i> <?= $currentUser['name'] ?>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="<?= SITE_URL ?>/client/dashboard.php"><i
                                        class="fas fa-tachometer-alt me-2"></i>Dashboard</a></li>
                            <li><a class="dropdown-item" href="<?= SITE_URL ?>/client/consultations.php"><i
                                        class="fas fa-calendar me-2"></i>My Consultations</a></li>
                            <li><a class="dropdown-item" href="<?= SITE_URL ?>/client/profile.php"><i
                                        class="fas fa-user me-2"></i>Profile</a></li>
                            <li>
                                <hr class="dropdown-divider">
                            </li>
                            <li><a class="dropdown-item text-danger" href="<?= SITE_URL ?>/logout.php"><i
                                        class="fas fa-sign-out-alt me-2"></i>Logout</a></li>
                        </ul>
                    </div>
                    <?php elseif ($currentLawyer): ?>
                    <a href="<?= SITE_URL ?>/lawyer/dashboard.php" class="btn btn-outline-gold me-2">Dashboard</a>
                    <a href="<?= SITE_URL ?>/lawyer/logout.php" class="btn btn-gold">Logout</a>
                    <?php else: ?>
                    <a href="<?= SITE_URL ?>/login.php" class="btn btn-gold" title="Talk to Lawyer">
                        <i class="fas fa-user-tie"></i> <span>Talk to Lawyer</span>
                    </a>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </nav>

    <?php if ($flash): ?>
    <div class="alert alert-<?= $flash['type'] === 'success' ? 'success' : ($flash['type'] === 'error' ? 'danger' : $flash['type']) ?> alert-dismissible fade show m-0 rounded-0"
        role="alert">
        <div class="container"><?= $flash['message'] ?></div>
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    <?php endif; ?>