<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Customize School Name</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #2c3e50;
            text-align: center;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #34495e;
        }
        input[type="text"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            box-sizing: border-box;
        }
        button {
            background-color: #3498db;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #2980b9;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            border-radius: 5px;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .current-settings {
            background-color: #e8f4fd;
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1> Customize School Name</h1>
        
        <?php
        require_once 'config/database.php';
        require_once 'includes/site_settings.php';

        // Initialize variables
        $current_bn = get_setting($pdo, 'system_name', 'স্কুল ম্যানেজমেন্ট সিস্টেম');
        $current_en = get_setting($pdo, 'system_name_en', 'School Management System');
        
        $message = '';
        $message_type = '';

        // Process form submission
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $new_bn = trim($_POST['system_name_bn'] ?? '');
            $new_en = trim($_POST['system_name_en'] ?? '');
            
            if (!empty($new_bn) && !empty($new_en)) {
                try {
                    // Update the system names in the database
                    $result_bn = set_setting($pdo, 'system_name', $new_bn);
                    $result_en = set_setting($pdo, 'system_name_en', $new_en);
                    
                    if ($result_bn && $result_en) {
                        $message = "✅ School names updated successfully!";
                        $message_type = 'success';
                        $current_bn = $new_bn;
                        $current_en = $new_en;
                    } else {
                        $message = "❌ Failed to update school names.";
                        $message_type = 'error';
                    }
                } catch (Exception $e) {
                    $message = "❌ Error occurred while updating school names: " . htmlspecialchars($e->getMessage());
                    $message_type = 'error';
                }
            } else {
                $message = "❌ Please enter both Bengali and English school names.";
                $message_type = 'error';
            }
        }
        ?>
        
        <div class="current-settings">
            <h3>Current Settings:</h3>
            <p><strong>Bengali Name:</strong> <?php echo htmlspecialchars($current_bn); ?></p>
            <p><strong>English Name:</strong> <?php echo htmlspecialchars($current_en); ?></p>
        </div>
        
        <?php if ($message): ?>
            <div class="result <?php echo $message_type; ?>">
                <?php echo $message; ?>
            </div>
        <?php endif; ?>
        
        <form method="POST">
            <div class="form-group">
                <label for="system_name_bn">School Name (Bengali):</label>
                <input type="text" id="system_name_bn" name="system_name_bn" 
                       value="<?php echo htmlspecialchars($current_bn); ?>" required>
            </div>
            
            <div class="form-group">
                <label for="system_name_en">School Name (English):</label>
                <input type="text" id="system_name_en" name="system_name_en" 
                       value="<?php echo htmlspecialchars($current_en); ?>" required>
            </div>
            
            <button type="submit">Update School Name</button>
        </form>
        
        <div style="margin-top: 30px;">
            <h3>Instructions:</h3>
            <ol>
                <li>Enter your desired school/institution name in both Bengali and English fields</li>
                <li>Click "Update School Name" to save the changes</li>
                <li>The changes will be reflected throughout the application immediately</li>
                <li>Visit any page in your application to see the updated name in the header</li>
            </ol>
        </div>
    </div>
</body>
</html>