<!DOCTYPE html>
<html lang="en" data-theme="light">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>All Jobs</title>
    <link href="https://cdn.jsdelivr.net/npm/daisyui@4.7.2/dist/full.min.css" rel="stylesheet" type="text/css" />
    <script src="https://cdn.tailwindcss.com"></script>
</head>

<body class="min-h-screen bg-base-200">
    <?php include 'navbar.php'; ?>

    <main class="container mx-auto px-4 py-8">
        <!-- Breadcrumb -->
        <div class="text-sm breadcrumbs mb-6">
            <ul>
                <li><a href="index.php">Home</a></li>
                <li class="text-primary">All Jobs</li>
            </ul>
        </div>

        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            <?php
            include 'connect.php';
            
            // Check if the user is logged in
            if (!isset($_SESSION['email'])) {
                // If not logged in, redirect to login page
                header("Location: login.php");
                exit();
            }


            // Query to get all jobs based on employer id
            $sql = "SELECT * FROM job_postings ORDER BY posted_date DESC";
            $stmt = $conn->prepare($sql);
            $stmt->execute();
            $result = $stmt->get_result();

            if ($result->num_rows > 0) {
                while ($job = $result->fetch_assoc()) {
                    ?>
                    <div class="lg:col-span-1">
                        <div class="card bg-base-100 shadow-xl">
                            <div class="card-body">
                                <!-- Job Overview -->
                                <h2 class="card-title text-xl mb-4"><?= htmlspecialchars($job['job_title']) ?></h2>

                                <div class="space-y-4">
                                    <div class="flex items-center gap-3">
                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-primary" viewBox="0 0 20 20"
                                            fill="currentColor">
                                            <path fill-rule="evenodd"
                                                d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z"
                                                clip-rule="evenodd" />
                                        </svg>
                                        <div>
                                            <div class="text-sm opacity-70">Location</div>
                                            <div class="font-medium"><?= htmlspecialchars($job['location']) ?></div>
                                        </div>
                                    </div>

                                    <div class="flex items-center gap-3">
                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-primary" viewBox="0 0 20 20"
                                            fill="currentColor">
                                            <path
                                                d="M8.433 7.418c.155-.103.346-.196.567-.267v1.698a2.305 2.305 0 01-.567-.267C8.07 8.34 8 8.114 8 8c0-.114.07-.34.433-.582zM11 12.849v-1.698c.22.071.412.164.567.267.364.243.433.468.433.582 0 .114-.07.34-.433.582a2.305 2.305 0 01-.567.267z" />
                                            <path fill-rule="evenodd"
                                                d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-13a1 1 0 10-2 0v.092a4.535 4.535 0 00-1.676.662C6.602 6.234 6 7.009 6 8c0 .99.602 1.765 1.324 2.246.48.32 1.054.545 1.676.662v1.941c-.391-.127-.68-.317-.843-.504a1 1 0 10-1.51 1.31c.562.649 1.413 1.076 2.353 1.253V15a1 1 0 102 0v-.092a4.535 4.535 0 001.676-.662C13.398 13.766 14 12.991 14 12c0-.99-.602-1.765-1.324-2.246A4.535 4.535 0 0011 9.092V7.151c.391.127.68.317.843.504a1 1 0 101.511-1.31c-.563-.649-1.413-1.076-2.354-1.253V5z"
                                                clip-rule="evenodd" />
                                        </svg>
                                        <div>
                                            <div class="text-sm opacity-70">Salary</div>
                                            <div class="font-medium"><?= htmlspecialchars($job['salary']) ?></div>
                                        </div>
                                    </div>

                                    <div class="flex items-center gap-3">
                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-primary" viewBox="0 0 20 20"
                                            fill="currentColor">
                                            <path fill-rule="evenodd"
                                                d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z"
                                                clip-rule="evenodd" />
                                        </svg>
                                        <div>
                                            <div class="text-sm opacity-70">Posted Date</div>
                                            <div class="font-medium"><?= date('F j, Y', strtotime($job['posted_date'])) ?></div>
                                        </div>
                                    </div>
                                </div>

                                <div class="divider"></div>

                                <a href="job_details.php?id=<?= $job['job_id'] ?>" class="btn btn-primary btn-block">
                                    View Details
                                </a>
                            </div>
                        </div>
                    </div>
                    <?php
                }
            } else {
                echo "<p>No jobs available.</p>";
            }
            $conn->close();
            ?>
        </div>
    </main>

    <?php include 'footer.php'; ?>
</body>

</html>