<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tours — Admin</title>
    <link rel="stylesheet" href="<?= base_url('css/uno.css') ?>">
</head>
<body class="font-sans bg-light p-5">
    <div class="max-w-7xl mx-auto bg-white rounded-xl shadow-md p-6">
        <a href="<?= base_url('admin/dashboard') ?>" class="inline-block mb-6 text-primary font-semibold hover:underline">
            ← Back to Dashboard
        </a>
        
        <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
            <h1 class="text-2xl font-bold text-primary">Tours</h1>
            <a 
                href="<?= base_url('admin/tours/create') ?>" 
                class="bg-primary text-white font-semibold px-4 py-2 rounded-lg hover:bg-primary-dark transition inline-flex items-center gap-2"
            >
                <span>+ Create Tour</span>
            </a>
        </div>

        <?php if (session()->getFlashdata('success')): ?>
            <div class="bg-green-50 text-green-800 px-4 py-3 rounded-lg mb-6">
                <?= session()->getFlashdata('success') ?>
            </div>
        <?php endif; ?>

        <?php if (session()->getFlashdata('info')): ?>
            <div class="bg-blue-50 text-blue-800 px-4 py-3 rounded-lg mb-6">
                <?= session()->getFlashdata('info') ?>
            </div>
        <?php endif; ?>

        <?php if (empty($tours)): ?>
            <p class="text-gray-600 py-8 text-center">No tours found.</p>
        <?php else: ?>
            <div class="overflow-x-auto">
                <table class="w-full">
                    <thead>
                        <tr class="text-left text-gray-600 border-b">
                            <th class="pb-3 font-semibold">Title</th>
                            <th class="pb-3 font-semibold">Route</th>
                            <th class="pb-3 font-semibold">Duration</th>
                            <th class="pb-3 font-semibold">Price (USD)</th>
                            <th class="pb-3 font-semibold">Status</th>
                            <th class="pb-3 font-semibold">Actions</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-100">
                        <?php foreach ($tours as $tour): ?>
                            <tr>
                                <td class="py-4"><?= esc($tour['title']) ?></td>
                                <td class="py-4"><?= esc($tour['route']) ?></td>
                                <td class="py-4"><?= esc($tour['duration_days']) ?> days</td>
                                <td class="py-4"><?= number_format($tour['price_usd'], 2) ?></td>
                                <td class="py-4">
                                    <?php if ($tour['is_active']): ?>
                                        <span class="text-green-600 font-medium">Active</span>
                                    <?php else: ?>
                                        <span class="text-gray-400 font-medium">Inactive</span>
                                    <?php endif; ?>
                                </td>
                                <td class="py-4 space-x-4">
                                    <a 
                                        href="<?= base_url("admin/tours/edit/{$tour['id']}") ?>" 
                                        class="text-primary hover:underline font-medium"
                                    >
                                        Edit
                                    </a>
                                    <a 
                                        href="<?= base_url("admin/tours/delete/{$tour['id']}") ?>" 
                                        class="text-red-600 hover:underline font-medium"
                                        onclick="return confirm('Are you sure?')"
                                    >
                                        Delete
                                    </a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php endif; ?>
    </div>
</body>
</html>