/home3/bmscom/jupiter.bms69.com/admin_slots.php
<?php
// admin_slots.php
require_once 'includes/db.php';
if (!isAdmin()) redirect('admin_login.php');

$message = '';
// Handle New Slot
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_slot'])) {
    $ground_id = (int)$_POST['ground_id'];
    $day = $_POST['day_of_week'];
    $start = $_POST['start_time'];
    $end = $_POST['end_time'];
    $price = $_POST['price'];
    
    $stmt = $pdo->prepare("INSERT INTO slots (ground_id, day_of_week, start_time, end_time, price) VALUES (?, ?, ?, ?, ?)");
    $stmt->execute([$ground_id, $day, $start, $end, $price]);
    $message = ['type' => 'success', 'text' => 'New slot added successfully.'];
}

// Fetch Grounds and their slots
$grounds_stmt = $pdo->query("SELECT * FROM grounds");
$grounds = $grounds_stmt->fetchAll();

require_once 'includes/header.php';
?>

<div class="space-y-10">
    <div class="flex flex-col md:flex-row md:items-center justify-between gap-6">
        <div>
            <h1 class="text-3xl font-black text-white">Slot Management</h1>
            <p class="text-slate-400 mt-1">Configure recurring booking availability.</p>
        </div>
        <button onclick="document.getElementById('slotModal').classList.remove('hidden')" class="px-8 py-4 bg-blue-600 hover:bg-blue-700 text-white font-black rounded-2xl shadow-xl transition-all active:scale-[0.98]">
            + Create New Slot
        </button>
    </div>

    <?php if($message): ?>
        <div class="p-4 bg-green-900/20 border border-green-500/50 text-green-400 rounded-2xl flex items-center gap-3">
            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
            <?php echo $message['text']; ?>
        </div>
    <?php endif; ?>

    <div class="space-y-8">
        <?php foreach($grounds as $g): 
            $s_stmt = $pdo->prepare("SELECT * FROM slots WHERE ground_id = ? ORDER BY FIELD(day_of_week, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'), start_time");
            $s_stmt->execute([$g['id']]);
            $slots = $s_stmt->fetchAll();
        ?>
            <div class="glass p-8 rounded-[2.5rem] shadow-2xl relative overflow-hidden">
                <div class="absolute -right-4 -top-4 w-24 h-24 bg-blue-600/5 rounded-full blur-2xl"></div>
                <h2 class="text-xl font-black text-white mb-8 border-b border-white/5 pb-4 flex items-center justify-between">
                    <span><?php echo $g['name']; ?></span>
                    <span class="text-xs font-black text-slate-500 uppercase tracking-widest"><?php echo count($slots); ?> Recurring Slots</span>
                </h2>
                
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
                    <?php if(empty($slots)): ?>
                        <div class="col-span-full py-10 text-center text-slate-500 italic">No slots defined.</div>
                    <?php else: ?>
                        <?php foreach($slots as $s): ?>
                            <div class="bg-slate-900/50 border border-slate-800 p-5 rounded-2xl group hover:border-blue-500/50 transition-all">
                                <p class="text-blue-500 font-black text-sm uppercase tracking-widest mb-1"><?php echo $s['day_of_week']; ?></p>
                                <p class="text-white font-bold text-lg mb-2"><?php echo date('g:ia', strtotime($s['start_time'])); ?> - <?php echo date('g:ia', strtotime($s['end_time'])); ?></p>
                                <div class="flex justify-between items-center pt-2 border-t border-white/5">
                                    <span class="text-xs font-black text-slate-500 uppercase">Rate</span>
                                    <span class="text-white font-black text-sm"><?php echo number_format($s['price']); ?> PKR</span>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
</div>

<!-- Add Slot Modal -->
<div id="slotModal" class="fixed inset-0 z-[100] hidden flex items-center justify-center p-4 bg-slate-950/90 backdrop-blur-xl animate-in fade-in">
    <div class="glass w-full max-w-md rounded-[2.5rem] shadow-2xl overflow-hidden scale-in-center">
        <div class="p-8 border-b border-white/5 flex justify-between items-center">
            <h3 class="text-2xl font-black text-white">New Recurring Slot</h3>
            <button onclick="document.getElementById('slotModal').classList.add('hidden')" class="text-slate-400 hover:text-white text-3xl font-light">&times;</button>
        </div>
        <form method="POST" class="p-8 space-y-6">
            <input type="hidden" name="add_slot" value="1">
            
            <div class="grid grid-cols-2 gap-4">
                <div>
                    <label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-2 ml-1">Ground</label>
                    <select name="ground_id" class="w-full bg-slate-900 border border-slate-700 rounded-2xl px-5 py-4 text-white focus:ring-4 focus:ring-blue-500/20 outline-none">
                        <?php foreach($grounds as $g): ?>
                            <option value="<?php echo $g['id']; ?>"><?php echo $g['name']; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div>
                    <label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-2 ml-1">Day</label>
                    <select name="day_of_week" class="w-full bg-slate-900 border border-slate-700 rounded-2xl px-5 py-4 text-white focus:ring-4 focus:ring-blue-500/20 outline-none">
                        <?php foreach(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] as $day): ?>
                            <option value="<?php echo $day; ?>"><?php echo $day; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="grid grid-cols-2 gap-4">
                <div>
                    <label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-2 ml-1">Start Time</label>
                    <input type="time" name="start_time" required class="w-full bg-slate-900 border border-slate-700 rounded-2xl px-5 py-4 text-white focus:ring-4 focus:ring-blue-500/20 outline-none">
                </div>
                <div>
                    <label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-2 ml-1">End Time</label>
                    <input type="time" name="end_time" required class="w-full bg-slate-900 border border-slate-700 rounded-2xl px-5 py-4 text-white focus:ring-4 focus:ring-blue-500/20 outline-none">
                </div>
            </div>

            <div>
                <label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-2 ml-1">Slot Rate (PKR)</label>
                <input type="number" name="price" required placeholder="5000" class="w-full bg-slate-900 border border-slate-700 rounded-2xl px-5 py-4 text-white focus:ring-4 focus:ring-blue-500/20 outline-none">
            </div>

            <button type="submit" class="w-full py-5 bg-blue-600 hover:bg-blue-700 text-white font-black text-lg rounded-2xl transition-all shadow-xl shadow-blue-500/20 active:scale-[0.98]">
                Schedule Slot
            </button>
        </form>
    </div>
</div>

<?php require_once 'includes/footer.php'; ?>