<?php
require_once 'auth.php';

// Require admin login
requireAdminLogin();

$page_title = 'Tatkal Management Panel';
$current_page = 'tatkal_management_panel.php';

// Get database connection
require_once '../config/database.php';
$pdo = getDBConnection();

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    try {
        $action = $_POST['action'] ?? '';
        error_log("Tatkal Management Action: " . $action);
        error_log("POST Data: " . print_r($_POST, true));
        
        if ($action === 'toggle_tatkal') {
            $tatkalEnabled = $_POST['tatkal_enabled'] === '1' ? '1' : '0';
            $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
            $stmt->execute(['tatkal_enabled', $tatkalEnabled, $tatkalEnabled]);
            
            $success_message = $tatkalEnabled === '1' ? "Tatkal booking enabled successfully!" : "Tatkal booking disabled successfully!";
        }
        
        if ($action === 'update_price') {
            $tatkalPrice = $_POST['tatkal_price'] ?? '1500';
            error_log("Updating tatkal price to: " . $tatkalPrice);
            
            $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
            $stmt->execute(['tatkal_price', $tatkalPrice, $tatkalPrice]);
            error_log("Settings table updated");
            
            // Also update consultation types table and ensure it's active
            $stmt = $pdo->prepare("UPDATE consultation_types SET base_price = ?, is_active = 1 WHERE type_code = 'tatkal_booking'");
            $result = $stmt->execute([$tatkalPrice]);
            $affectedRows = $stmt->rowCount();
            error_log("Consultation types update result: " . ($result ? 'success' : 'failed') . ", affected rows: " . $affectedRows);
            
            // If no rows were affected, create the consultation type
            if ($affectedRows == 0) {
                $stmt = $pdo->prepare("
                    INSERT INTO consultation_types (type_name, type_code, base_price, description, is_active) VALUES
                    ('Tatkal Booking', 'tatkal_booking', ?, 'Emergency/urgent consultation booking', 1)
                ");
                $stmt->execute([$tatkalPrice]);
                error_log("Created new tatkal consultation type");
            }
            
            $success_message = "Tatkal price updated successfully!";
        }
        
        if ($action === 'update_days') {
            $tatkalDays = $_POST['tatkal_days'] ?? [];
            $daySettings = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
            error_log("Updating tatkal days: " . print_r($tatkalDays, true));
            
            foreach ($daySettings as $day) {
                $isEnabled = in_array($day, $tatkalDays) ? '1' : '0';
                $settingKey = 'tatkal_' . $day . '_enabled';
                error_log("Setting $settingKey to $isEnabled");
                
                $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
                $stmt->execute([$settingKey, $isEnabled, $isEnabled]);
            }
            
            $success_message = "Tatkal days updated successfully!";
        }
        
        if ($action === 'update_slots') {
            $maxSlots = $_POST['max_slots'] ?? '10';
            $advanceDays = $_POST['advance_days'] ?? '7';
            
            $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
            $stmt->execute(['tatkal_slots', $maxSlots, $maxSlots]);
            
            $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
            $stmt->execute(['tatkal_advance_days', $advanceDays, $advanceDays]);
            
            $success_message = "Tatkal slots and advance days updated successfully!";
        }
        
        if ($action === 'add_tatkal_consultation') {
            // Check if tatkal_booking exists
            $stmt = $pdo->query("SELECT COUNT(*) FROM consultation_types WHERE type_code = 'tatkal_booking'");
            $count = $stmt->fetchColumn();
            
            if ($count == 0) {
                // Add tatkal_booking to consultation_types
                $stmt = $pdo->prepare("
                    INSERT INTO consultation_types (type_name, type_code, base_price, description, is_active) VALUES
                    ('Tatkal Booking', 'tatkal_booking', 1500.00, 'Emergency/urgent consultation booking', 1)
                ");
                $stmt->execute();
                
                $success_message = "Tatkal Booking consultation type added successfully!";
            } else {
                // Update existing tatkal_booking to be active with proper price
                $stmt = $pdo->prepare("UPDATE consultation_types SET is_active = 1, base_price = 1500.00 WHERE type_code = 'tatkal_booking'");
                $stmt->execute();
                
                $success_message = "Tatkal Booking consultation type activated and price updated!";
            }
        }
        
    } catch (Exception $e) {
        error_log("Tatkal Management Error: " . $e->getMessage());
        error_log("Stack trace: " . $e->getTraceAsString());
        $error_message = "Error updating settings: " . $e->getMessage();
    }
}

// Get current settings
$tatkalEnabled = false;
$tatkalPrice = '1500';
$maxSlots = '10';
$advanceDays = '7';
$tatkalDays = [];

// Get tatkal enabled status
$stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'tatkal_enabled'");
$stmt->execute();
$tatkalEnabled = $stmt->fetchColumn() === '1';

// Get tatkal price
$stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'tatkal_price'");
$stmt->execute();
$tatkalPrice = $stmt->fetchColumn() ?: '1500';

// Get max slots
$stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'tatkal_slots'");
$stmt->execute();
$maxSlots = $stmt->fetchColumn() ?: '10';

// Get advance days
$stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'tatkal_advance_days'");
$stmt->execute();
$advanceDays = $stmt->fetchColumn() ?: '7';

// Get tatkal days
$daySettings = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
foreach ($daySettings as $day) {
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = ?");
    $stmt->execute(['tatkal_' . $day . '_enabled']);
    if ($stmt->fetchColumn() === '1') {
        $tatkalDays[] = $day;
    }
}

// Get tatkal statistics
$stmt = $pdo->prepare("SELECT COUNT(*) FROM appointments WHERE time_slot = 'tatkal'");
$stmt->execute();
$totalTatkalBookings = $stmt->fetchColumn();

$stmt = $pdo->prepare("SELECT COUNT(*) FROM appointments WHERE time_slot = 'tatkal' AND DATE(created_at) = CURDATE()");
$stmt->execute();
$todayTatkalBookings = $stmt->fetchColumn();

$stmt = $pdo->prepare("SELECT SUM(amount) FROM appointments WHERE time_slot = 'tatkal' AND status = 'confirmed'");
$stmt->execute();
$totalTatkalRevenue = $stmt->fetchColumn() ?: 0;

$days = [
    'monday' => 'Monday',
    'tuesday' => 'Tuesday', 
    'wednesday' => 'Wednesday',
    'thursday' => 'Thursday',
    'friday' => 'Friday',
    'saturday' => 'Saturday',
    'sunday' => 'Sunday'
];

ob_start();
?>

<style>
/* Main Container */
.tatkal-panel {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #ec4899 100%);
    min-height: 100vh;
    padding: 25px;
}

/* Panel Cards */
.panel-card {
    background: linear-gradient(145deg, #ffffff 0%, #f8f9fa 100%);
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 25px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 2px solid transparent;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.panel-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #4f46e5 0%, #7c3aed 50%, #ec4899 100%);
}

.panel-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
}

.panel-card.enabled {
    border-color: #10b981;
    background: linear-gradient(145deg, #f0fdf4 0%, #dcfce7 100%);
}

.panel-card.disabled {
    border-color: #ef4444;
    background: linear-gradient(145deg, #fef2f2 0%, #fee2e2 100%);
}

/* Status Toggle */
.status-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.toggle-switch {
    position: relative;
    width: 70px;
    height: 35px;
    background: #e5e7eb;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.toggle-switch.active {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 29px;
    height: 29px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.toggle-switch.active .toggle-slider {
    transform: translateX(35px);
}

/* Statistics Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #ec4899 100%);
    color: white;
    padding: 25px;
    border-radius: 20px;
    text-align: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    transition: all 0.3s ease;
    transform: scale(0);
}

.stat-card:hover::before {
    transform: scale(1);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(79, 70, 229, 0.3);
}

.stat-number {
    font-size: 2.8em;
    font-weight: bold;
    margin-bottom: 10px;
    position: relative;
    z-index: 2;
}

.stat-label {
    font-size: 1.1em;
    opacity: 0.95;
    position: relative;
    z-index: 2;
}

/* Form Elements */
.form-group {
    margin-bottom: 25px;
}

.form-label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: #374151;
    font-size: 1rem;
}

.form-control {
    width: 100%;
    padding: 15px 20px;
    border: 2px solid #e5e7eb;
    border-radius: 15px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Day Checkboxes */
.day-checkbox {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    padding: 15px 20px;
    background: linear-gradient(145deg, #f9fafb 0%, #f3f4f6 100%);
    border-radius: 15px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    cursor: pointer;
}

.day-checkbox:hover {
    background: linear-gradient(145deg, #e0e7ff 0%, #c7d2fe 100%);
    border-color: #4f46e5;
    transform: translateX(5px);
}

.day-checkbox input[type="checkbox"] {
    margin-right: 15px;
    transform: scale(1.3);
    accent-color: #4f46e5;
}

.day-checkbox input[type="checkbox"]:checked + label {
    color: #4f46e5;
    font-weight: 600;
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    border: none;
    padding: 15px 35px;
    border-radius: 25px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(79, 70, 229, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: none;
    padding: 15px 35px;
    border-radius: 25px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.btn-danger:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(239, 68, 68, 0.4);
}

/* Alerts */
.alert {
    padding: 20px 25px;
    border-radius: 15px;
    margin-bottom: 25px;
    border: none;
    font-weight: 500;
}

.alert-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.alert-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

/* Grid Layouts */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
}

.days-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

/* Summary Section */
.summary-section {
    background: linear-gradient(145deg, #f8fafc 0%, #e2e8f0 100%);
    padding: 25px;
    border-radius: 15px;
    border-left: 5px solid #4f46e5;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-label {
    font-weight: 600;
    color: #374151;
}

.summary-value {
    color: #4f46e5;
    font-weight: 600;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .tatkal-panel {
        padding: 15px;
    }
    
    .panel-card {
        padding: 20px;
        margin-bottom: 20px;
    }
    
    .status-toggle {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .stat-number {
        font-size: 2.2em;
    }
    
    .settings-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .days-grid {
        grid-template-columns: 1fr;
    }
    
    .day-checkbox {
        padding: 12px 15px;
    }
    
    .form-control {
        padding: 12px 15px;
        font-size: 16px;
    }
    
    .btn-primary,
    .btn-danger {
        padding: 12px 25px;
        font-size: 0.9rem;
        width: 100%;
    }
}

@media (max-width: 576px) {
    .tatkal-panel {
        padding: 10px;
    }
    
    .panel-card {
        padding: 15px;
        border-radius: 15px;
    }
    
    .stat-card {
        padding: 20px 15px;
    }
    
    .stat-number {
        font-size: 2em;
    }
    
    .stat-label {
        font-size: 1em;
    }
    
    .toggle-switch {
        width: 60px;
        height: 30px;
    }
    
    .toggle-slider {
        width: 24px;
        height: 24px;
    }
    
    .toggle-switch.active .toggle-slider {
        transform: translateX(30px);
    }
}
</style>

<div class="tatkal-panel">
    <div class="container">
        <h1 style="color: white; text-align: center; margin-bottom: 30px; font-size: 2.5em;">
            🚀 Tatkal Management Panel
        </h1>
        
        <?php if (isset($success_message)): ?>
            <div class="alert alert-success">
                <strong>Success!</strong> <?php echo htmlspecialchars($success_message); ?>
            </div>
        <?php endif; ?>
        
        <?php if (isset($error_message)): ?>
            <div class="alert alert-danger">
                <strong>Error!</strong> <?php echo htmlspecialchars($error_message); ?>
            </div>
        <?php endif; ?>
        
        <!-- Statistics -->
        <div class="stats-grid">
            <div class="stat-card">
                <div class="stat-number"><?php echo $totalTatkalBookings; ?></div>
                <div class="stat-label">Total Tatkal Bookings</div>
            </div>
            <div class="stat-card">
                <div class="stat-number"><?php echo $todayTatkalBookings; ?></div>
                <div class="stat-label">Today's Tatkal Bookings</div>
            </div>
            <div class="stat-card">
                <div class="stat-number">₹<?php echo number_format($totalTatkalRevenue); ?></div>
                <div class="stat-label">Total Tatkal Revenue</div>
            </div>
        </div>
        
        <!-- Tatkal Enable/Disable -->
        <div class="panel-card <?php echo $tatkalEnabled ? 'enabled' : 'disabled'; ?>">
            <div class="status-toggle">
                <h3 style="margin: 0; color: #333;">
                    <?php echo $tatkalEnabled ? '✅ Tatkal Booking Enabled' : '❌ Tatkal Booking Disabled'; ?>
                </h3>
                <form method="POST" style="display: inline;">
                    <input type="hidden" name="action" value="toggle_tatkal">
                    <input type="hidden" name="tatkal_enabled" value="<?php echo $tatkalEnabled ? '0' : '1'; ?>">
                    <div class="toggle-switch <?php echo $tatkalEnabled ? 'active' : ''; ?>" onclick="this.parentElement.submit()">
                        <div class="toggle-slider"></div>
                    </div>
                </form>
            </div>
            <p style="color: #666; margin: 10px 0;">
                <?php echo $tatkalEnabled ? 'Tatkal booking is currently active and available to users.' : 'Tatkal booking is currently disabled. Users cannot book tatkal appointments.'; ?>
            </p>
        </div>
        
        <!-- Price Management -->
        <div class="panel-card">
            <h3 style="color: #374151; margin-bottom: 25px; display: flex; align-items: center; gap: 10px;">
                <i class="fas fa-rupee-sign" style="color: #4f46e5;"></i>
                Price Management
            </h3>
            <p style="color: #6b7280; margin-bottom: 20px;">Set the price for Tatkal (urgent) appointment bookings</p>
            <form method="POST">
                <input type="hidden" name="action" value="update_price">
                <div class="form-group">
                    <label class="form-label">
                        <i class="fas fa-tag" style="margin-right: 8px; color: #4f46e5;"></i>
                        Tatkal Price (₹)
                    </label>
                    <div style="position: relative;">
                        <span style="position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: #6b7280; font-weight: 600;">₹</span>
                        <input type="number" name="tatkal_price" value="<?php echo htmlspecialchars($tatkalPrice); ?>" 
                               class="form-control" min="0" step="10" required 
                               style="padding-left: 40px;" placeholder="Enter price">
                    </div>
                    <small style="color: #6b7280; margin-top: 5px; display: block;">Price charged for emergency/urgent appointments</small>
                </div>
                <button type="submit" class="btn-primary">
                    <i class="fas fa-save" style="margin-right: 8px;"></i>
                    Update Price
                </button>
            </form>
        </div>
        
        <!-- Days Management -->
        <div class="panel-card">
            <h3 style="color: #374151; margin-bottom: 25px; display: flex; align-items: center; gap: 10px;">
                <i class="fas fa-calendar-week" style="color: #4f46e5;"></i>
                Available Days
            </h3>
            <p style="color: #6b7280; margin-bottom: 20px;">Select which days of the week Tatkal booking should be available</p>
            <form method="POST">
                <input type="hidden" name="action" value="update_days">
                <div class="days-grid">
                    <?php foreach ($days as $dayKey => $dayName): ?>
                        <div class="day-checkbox">
                            <input type="checkbox" name="tatkal_days[]" value="<?php echo $dayKey; ?>" 
                                   id="day_<?php echo $dayKey; ?>" 
                                   <?php echo in_array($dayKey, $tatkalDays) ? 'checked' : ''; ?>>
                            <label for="day_<?php echo $dayKey; ?>" style="margin: 0; cursor: pointer; flex: 1;">
                                <i class="fas fa-calendar-day" style="margin-right: 8px; color: #6b7280;"></i>
                                <?php echo $dayName; ?>
                            </label>
                        </div>
                    <?php endforeach; ?>
                </div>
                <button type="submit" class="btn-primary" style="margin-top: 25px;">
                    <i class="fas fa-save" style="margin-right: 8px;"></i>
                    Update Days
                </button>
            </form>
        </div>
        
        <!-- Slots Management -->
        <div class="panel-card">
            <h3 style="color: #374151; margin-bottom: 25px; display: flex; align-items: center; gap: 10px;">
                <i class="fas fa-clock" style="color: #4f46e5;"></i>
                Slots & Advance Booking
            </h3>
            <p style="color: #6b7280; margin-bottom: 20px;">Configure maximum slots per day and advance booking period</p>
            <form method="POST">
                <input type="hidden" name="action" value="update_slots">
                <div class="settings-grid">
                    <div class="form-group">
                        <label class="form-label">
                            <i class="fas fa-list-ol" style="margin-right: 8px; color: #4f46e5;"></i>
                            Max Slots Per Day
                        </label>
                        <input type="number" name="max_slots" value="<?php echo htmlspecialchars($maxSlots); ?>" 
                               class="form-control" min="1" max="50" required 
                               placeholder="Enter maximum slots">
                        <small style="color: #6b7280; margin-top: 5px; display: block;">Maximum number of Tatkal appointments per day</small>
                    </div>
                    <div class="form-group">
                        <label class="form-label">
                            <i class="fas fa-calendar-plus" style="margin-right: 8px; color: #4f46e5;"></i>
                            Advance Booking Days
                        </label>
                        <input type="number" name="advance_days" value="<?php echo htmlspecialchars($advanceDays); ?>" 
                               class="form-control" min="1" max="30" required 
                               placeholder="Enter advance days">
                        <small style="color: #6b7280; margin-top: 5px; display: block;">How many days in advance users can book</small>
                    </div>
                </div>
                <button type="submit" class="btn-primary">
                    <i class="fas fa-cog" style="margin-right: 8px;"></i>
                    Update Settings
                </button>
            </form>
        </div>
        
        <!-- API Integration Status -->
        <div class="panel-card">
            <h3 style="color: #374151; margin-bottom: 25px; display: flex; align-items: center; gap: 10px;">
                <i class="fas fa-code" style="color: #4f46e5;"></i>
                API Integration Status
            </h3>
            <div class="summary-section">
                <div class="summary-item">
                    <span class="summary-label">
                        <i class="fas fa-mobile-alt" style="margin-right: 8px;"></i>
                        App Integration
                    </span>
                    <span class="summary-value" style="color: #10b981;">
                        <i class="fas fa-check-circle" style="margin-right: 5px;"></i>
                        Active
                    </span>
                </div>
                
                <div class="summary-item">
                    <span class="summary-label">
                        <i class="fas fa-server" style="margin-right: 8px;"></i>
                        API Endpoint
                    </span>
                    <span class="summary-value">get_tatkal_settings.php</span>
                </div>
                
                <div class="summary-item">
                    <span class="summary-label">
                        <i class="fas fa-database" style="margin-right: 8px;"></i>
                        Database Tables
                    </span>
                    <span class="summary-value">settings + consultation_types</span>
                </div>
            </div>
            
            <div style="margin-top: 20px; padding: 15px; background: linear-gradient(145deg, #f0f9ff 0%, #e0f2fe 100%); border-radius: 10px; border-left: 4px solid #0ea5e9;">
                <p style="margin: 0; color: #0c4a6e; font-weight: 600;">
                    <i class="fas fa-info-circle" style="margin-right: 8px;"></i>
                    Changes made here will instantly reflect in the mobile app
                </p>
            </div>
        </div>
        
        <!-- Debug Section -->
        <div class="panel-card">
            <h3 style="color: #374151; margin-bottom: 25px; display: flex; align-items: center; gap: 10px;">
                <i class="fas fa-tools" style="color: #4f46e5;"></i>
                Debug & Maintenance
            </h3>
            <div style="background: linear-gradient(145deg, #fef3c7 0%, #fde68a 100%); padding: 20px; border-radius: 15px; border-left: 4px solid #f59e0b;">
                <form method="POST">
                    <input type="hidden" name="action" value="add_tatkal_consultation">
                    <p style="margin: 0 0 15px 0; color: #92400e; font-weight: 600;">
                        <i class="fas fa-wrench" style="margin-right: 8px;"></i>
                        Add Tatkal Booking to Consultation Types Table
                    </p>
                    <p style="margin: 0 0 15px 0; color: #92400e; font-size: 14px;">
                        Use this if Tatkal option is missing from consultation types
                    </p>
                    <button type="submit" class="btn-primary">
                        <i class="fas fa-plus" style="margin-right: 8px;"></i>
                        Add Tatkal Consultation Type
                    </button>
                </form>
            </div>
        </div>
        
        <!-- Current Settings Summary -->
        <div class="panel-card">
            <h3 style="color: #374151; margin-bottom: 25px; display: flex; align-items: center; gap: 10px;">
                <i class="fas fa-chart-line" style="color: #4f46e5;"></i>
                Current Settings Summary
            </h3>
            <div class="summary-section">
                <div class="summary-item">
                    <span class="summary-label">
                        <i class="fas fa-power-off" style="margin-right: 8px;"></i>
                        Status
                    </span>
                    <span class="summary-value" style="color: <?php echo $tatkalEnabled ? '#10b981' : '#ef4444'; ?>;">
                        <i class="fas fa-<?php echo $tatkalEnabled ? 'check-circle' : 'times-circle'; ?>" style="margin-right: 5px;"></i>
                        <?php echo $tatkalEnabled ? 'Enabled' : 'Disabled'; ?>
                    </span>
                </div>
                
                <div class="summary-item">
                    <span class="summary-label">
                        <i class="fas fa-rupee-sign" style="margin-right: 8px;"></i>
                        Price per Person
                    </span>
                    <span class="summary-value">₹<?php echo number_format($tatkalPrice); ?></span>
                </div>
                
                <div class="summary-item">
                    <span class="summary-label">
                        <i class="fas fa-list-ol" style="margin-right: 8px;"></i>
                        Max Slots per Day
                    </span>
                    <span class="summary-value"><?php echo $maxSlots; ?> slots</span>
                </div>
                
                <div class="summary-item">
                    <span class="summary-label">
                        <i class="fas fa-calendar-plus" style="margin-right: 8px;"></i>
                        Advance Booking Period
                    </span>
                    <span class="summary-value"><?php echo $advanceDays; ?> days</span>
                </div>
                
                <div class="summary-item">
                    <span class="summary-label">
                        <i class="fas fa-calendar-week" style="margin-right: 8px;"></i>
                        Available Days
                    </span>
                    <span class="summary-value">
                        <?php 
                        $enabledDays = array_intersect_key($days, array_flip($tatkalDays));
                        if (empty($enabledDays)) {
                            echo '<span style="color: #ef4444;">None Selected</span>';
                        } else {
                            echo '<span style="color: #10b981;">' . implode(', ', $enabledDays) . '</span>';
                        }
                        ?>
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>

<?php
$content = ob_get_clean();
include 'layout.php';
?>
