<?php
/**
 * Installation Script - Homoeopathy System
 * WARNING: Delete this file after installation for security!
 */

error_reporting(E_ALL);
ini_set('display_errors', 1);

$step = $_GET['step'] ?? 1;
$error = '';
$success = '';

// Check if already installed
$configExists = file_exists('config/config.php') && file_exists('config/database.php');

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !$configExists) {
    $db_host = $_POST['db_host'] ?? 'localhost';
    $db_name = $_POST['db_name'] ?? 'drmdferdous_kent';
    $db_user = $_POST['db_user'] ?? 'root';
    $db_pass = $_POST['db_pass'] ?? '';
    $admin_user = $_POST['admin_user'] ?? 'admin';
    $admin_email = $_POST['admin_email'] ?? 'admin@drmdferdous.com';
    $admin_pass = $_POST['admin_pass'] ?? '';
    
    // Validate inputs
    if (empty($admin_pass)) {
        $error = 'Please enter admin password';
    } else {
        try {
            // Test database connection
            $pdo = new PDO("mysql:host=$db_host", $db_user, $db_pass);
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            
            // Create database if not exists
            $pdo->exec("CREATE DATABASE IF NOT EXISTS `$db_name` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
            $pdo->exec("USE `$db_name`");
            
            // Check if tables already exist
            $stmt = $pdo->query("SHOW TABLES LIKE 'users'");
            $tablesExist = $stmt->rowCount() > 0;
            
            if (!$tablesExist) {
                // Create tables only if they don't exist
                $sql = "
                -- Users table
                CREATE TABLE IF NOT EXISTS `users` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `username` VARCHAR(50) UNIQUE NOT NULL,
                    `password_hash` VARCHAR(255) NOT NULL,
                    `api_key` VARCHAR(64) NULL DEFAULT NULL,
                    `email` VARCHAR(100) UNIQUE NOT NULL,
                    `full_name` VARCHAR(100) NOT NULL,
                    `profile_picture` VARCHAR(255) NULL DEFAULT NULL,
                    `role` ENUM('admin', 'doctor') DEFAULT 'doctor',
                    `is_active` BOOLEAN DEFAULT TRUE,
                    `last_login` DATETIME NULL,
                    `last_sync` DATETIME NULL,
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                    INDEX(`role`, `is_active`)
                );
                
                -- Subscriptions table
                CREATE TABLE IF NOT EXISTS `subscriptions` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `user_id` INT NOT NULL,
                    `plan_type` ENUM('1month', '6month', '1year', 'unlimited') NOT NULL,
                    `start_date` DATE NOT NULL,
                    `end_date` DATE,
                    `amount` DECIMAL(10,2) DEFAULT 0,
                    `payment_id` VARCHAR(100),
                    `is_active` BOOLEAN DEFAULT TRUE,
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
                );
                
                -- Rubrics table
                CREATE TABLE IF NOT EXISTS `rubrics` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `parent_id` INT NULL,
                    `chapter_name` VARCHAR(100) NULL,
                    `rubric_name` VARCHAR(255) NOT NULL,
                    `full_path` VARCHAR(500) NOT NULL,
                    `level` TINYINT DEFAULT 1,
                    `sort_order` INT DEFAULT 0,
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                    FOREIGN KEY (`parent_id`) REFERENCES `rubrics`(`id`) ON DELETE CASCADE
                );
                
                -- Remedies table
                CREATE TABLE IF NOT EXISTS `remedies` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `name` VARCHAR(100) UNIQUE NOT NULL,
                    `abbreviation` VARCHAR(20),
                    `materia_medica_text` LONGTEXT,
                    `clinical_indications` TEXT,
                    `modalities` JSON,
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
                );
                
                -- Rubric-Remedy mapping
                CREATE TABLE IF NOT EXISTS `rubric_remedy` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `rubric_id` INT NOT NULL,
                    `remedy_id` INT NOT NULL,
                    `grade` TINYINT NOT NULL CHECK (grade IN (1,2,3,4)),
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    FOREIGN KEY (`rubric_id`) REFERENCES `rubrics`(`id`) ON DELETE CASCADE,
                    FOREIGN KEY (`remedy_id`) REFERENCES `remedies`(`id`) ON DELETE CASCADE,
                    UNIQUE KEY `unique_rubric_remedy` (`rubric_id`, `remedy_id`)
                );
                
                -- Cases table
                CREATE TABLE IF NOT EXISTS `cases` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `user_id` INT NOT NULL,
                    `patient_name` VARCHAR(100) NOT NULL,
                    `patient_mobile` VARCHAR(15) NOT NULL,
                    `patient_age` INT,
                    `patient_gender` ENUM('M', 'F', 'Other'),
                    `chief_complaint` TEXT NOT NULL,
                    `case_history` TEXT,
                    `physical_generals` TEXT,
                    `mental_emotional` TEXT,
                    `modalities` TEXT,
                    `selected_rubrics` JSON,
                    `repertorization_result` JSON,
                    `prescribed_remedy_id` INT,
                    `prescription_potency` VARCHAR(20),
                    `follow_up_date` DATE,
                    `status` ENUM('active', 'follow-up', 'closed') DEFAULT 'active',
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
                    FOREIGN KEY (`prescribed_remedy_id`) REFERENCES `remedies`(`id`) ON DELETE SET NULL
                );
                
                -- Follow-ups table
                CREATE TABLE IF NOT EXISTS `follow_ups` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `case_id` INT NOT NULL,
                    `follow_up_date` DATE NOT NULL,
                    `progress` TEXT,
                    `new_symptoms` TEXT,
                    `remedy_repeated` BOOLEAN DEFAULT FALSE,
                    `changed_remedy_id` INT NULL,
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    FOREIGN KEY (`case_id`) REFERENCES `cases`(`id`) ON DELETE CASCADE,
                    FOREIGN KEY (`changed_remedy_id`) REFERENCES `remedies`(`id`) ON DELETE SET NULL
                );
                
                -- Settings table
                CREATE TABLE IF NOT EXISTS `settings` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `setting_key` VARCHAR(100) UNIQUE NOT NULL,
                    `setting_value` TEXT,
                    `setting_type` ENUM('text', 'number', 'boolean', 'json') DEFAULT 'text',
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
                );
                
                -- AI cache table
                CREATE TABLE IF NOT EXISTS `ai_analysis_cache` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `case_text_hash` VARCHAR(64) UNIQUE NOT NULL,
                    `remedy_id` INT,
                    `analysis_result` TEXT NOT NULL,
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
                );
                
                -- Reminder logs table
                CREATE TABLE IF NOT EXISTS `reminder_logs` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `case_id` INT NOT NULL,
                    `type` ENUM('sms', 'email') NOT NULL,
                    `recipient` VARCHAR(100) NOT NULL,
                    `message` TEXT,
                    `status` ENUM('sent', 'failed', 'pending') DEFAULT 'sent',
                    `sent_at` DATETIME NOT NULL,
                    FOREIGN KEY (`case_id`) REFERENCES `cases`(`id`) ON DELETE CASCADE
                );
                
                -- AI history tables
                CREATE TABLE IF NOT EXISTS `ai_analysis_history` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `user_id` INT NOT NULL,
                    `case_text` TEXT NOT NULL,
                    `analysis_result` TEXT NOT NULL,
                    `remedy_name` VARCHAR(100),
                    `created_at` DATETIME NOT NULL,
                    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
                );
                
                CREATE TABLE IF NOT EXISTS `ai_remedy_suggestions` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `user_id` INT NOT NULL,
                    `symptoms` TEXT NOT NULL,
                    `suggestion_result` TEXT NOT NULL,
                    `created_at` DATETIME NOT NULL,
                    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
                );
                
                CREATE TABLE IF NOT EXISTS `ai_rubric_extractions` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `user_id` INT NOT NULL,
                    `case_text` TEXT NOT NULL,
                    `extracted_rubrics` TEXT NOT NULL,
                    `created_at` DATETIME NOT NULL,
                    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
                );
                
                -- User AI settings
                CREATE TABLE IF NOT EXISTS `user_ai_settings` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `user_id` INT NOT NULL UNIQUE,
                    `enable_ai` BOOLEAN DEFAULT TRUE,
                    `auto_analyze` BOOLEAN DEFAULT FALSE,
                    `include_repertorization` BOOLEAN DEFAULT TRUE,
                    `analysis_depth` ENUM('basic', 'standard', 'detailed') DEFAULT 'standard',
                    `preferred_model` ENUM('gemini', 'deepseek') DEFAULT 'gemini',
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
                );
                
                -- Remedy bookmarks
                CREATE TABLE IF NOT EXISTS `remedy_bookmarks` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `user_id` INT NOT NULL,
                    `remedy_id` INT NOT NULL,
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    UNIQUE KEY `unique_bookmark` (`user_id`, `remedy_id`),
                    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
                    FOREIGN KEY (`remedy_id`) REFERENCES `remedies`(`id`) ON DELETE CASCADE
                );
                
                -- User sessions table
                CREATE TABLE IF NOT EXISTS `user_sessions` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `user_id` INT NOT NULL,
                    `session_token` VARCHAR(128) NOT NULL UNIQUE,
                    `expires_at` DATETIME NOT NULL,
                    `ip_address` VARCHAR(45),
                    `user_agent` TEXT,
                    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
                );
                
                -- Migrations table
                CREATE TABLE IF NOT EXISTS `migrations` (
                    `id` INT PRIMARY KEY AUTO_INCREMENT,
                    `migration` VARCHAR(255) NOT NULL,
                    `executed_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
                );
                ";
                
                $pdo->exec($sql);
            }
            
            // Check if admin user already exists
            $stmt = $pdo->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
            $stmt->execute([$admin_user, $admin_email]);
            $adminExists = $stmt->fetch();
            
            if (!$adminExists) {
                // Create admin user only if not exists
                $adminHash = password_hash($admin_pass, PASSWORD_DEFAULT);
                $apiKey = 'hom_' . bin2hex(random_bytes(32));
                $stmt = $pdo->prepare("INSERT INTO users (username, email, full_name, password_hash, api_key, role, is_active) 
                                      VALUES (?, ?, ?, ?, ?, 'admin', 1)");
                $stmt->execute([$admin_user, $admin_email, 'System Administrator', $adminHash, $apiKey]);
            } else {
                // Update existing admin password if provided
                if (!empty($admin_pass)) {
                    $adminHash = password_hash($admin_pass, PASSWORD_DEFAULT);
                    $stmt = $pdo->prepare("UPDATE users SET password_hash = ? WHERE username = ? OR email = ?");
                    $stmt->execute([$adminHash, $admin_user, $admin_email]);
                }
            }
            
            // Insert default settings if not exists
            $defaultSettings = [
                ['app_name', 'Homoeopathy System', 'text'],
                ['app_version', '1.0.0', 'text'],
                ['timezone', 'Asia/Dhaka', 'text'],
                ['items_per_page', '20', 'number'],
                ['maintenance_mode', '0', 'boolean'],
                ['registration_enabled', '1', 'boolean'],
                ['email_notifications', '1', 'boolean'],
                ['date_format', 'd-m-Y', 'text'],
                ['time_format', 'H:i:s', 'text'],
                ['currency_symbol', '৳', 'text'],
                ['currency_code', 'BDT', 'text'],
                ['use_ai', '0', 'boolean']
            ];
            
            $checkStmt = $pdo->prepare("SELECT id FROM settings WHERE setting_key = ?");
            $insertStmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value, setting_type) VALUES (?, ?, ?)");
            
            foreach ($defaultSettings as $setting) {
                $checkStmt->execute([$setting[0]]);
                if (!$checkStmt->fetch()) {
                    $insertStmt->execute($setting);
                }
            }
            
            // Create config files
            $configContent = "<?php
/**
 * System Configuration
 * Generated: " . date('Y-m-d H:i:s') . "
 */

define('APP_NAME', 'Homoeopathy System');
define('APP_VERSION', '1.0.0');
define('APP_URL', 'http://' . \$_SERVER['HTTP_HOST']);
define('TIMEZONE', 'Asia/Dhaka');
define('DEBUG_MODE', true);

define('GRADE_WEIGHTS', [1 => 2, 2 => 4, 3 => 7, 4 => 10]);
define('GRADE_CSS', [1 => 'grade-1', 2 => 'grade-2', 3 => 'grade-3', 4 => 'grade-4']);
define('SUBSCRIPTION_PLANS', ['1month' => 30, '6month' => 180, '1year' => 365, 'unlimited' => null]);
define('ITEMS_PER_PAGE', 20);
define('SESSION_LIFETIME', 7200);
define('PASSWORD_MIN_LENGTH', 6);

define('USE_AI', false);
define('GEMINI_API_KEY', '');
define('DEEPSEEK_API_KEY', '');
";
            
            $databaseContent = "<?php
/**
 * Database Configuration
 * Generated: " . date('Y-m-d H:i:s') . "
 */

define('DB_HOST', '$db_host');
define('DB_NAME', '$db_name');
define('DB_USER', '$db_user');
define('DB_PASS', '$db_pass');
define('DB_CHARSET', 'utf8mb4');

function getDB() {
    try {
        \$pdo = new PDO(
            \"mysql:host=\" . DB_HOST . \";dbname=\" . DB_NAME . \";charset=\" . DB_CHARSET,
            DB_USER,
            DB_PASS,
            [
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                PDO::ATTR_EMULATE_PREPARES => false
            ]
        );
        return \$pdo;
    } catch(PDOException \$e) {
        die(\"Connection failed: \" . \$e->getMessage());
    }
}
";
            
            file_put_contents('config/config.php', $configContent);
            file_put_contents('config/database.php', $databaseContent);
            
            // Create auth.php if not exists
            if (!file_exists('config/auth.php')) {
                $authContent = "<?php
/**
 * Authentication Functions
 */

session_name('homoeopathy_session');
session_start();

require_once __DIR__ . '/database.php';
require_once __DIR__ . '/constants.php';

function login(\$username, \$password) {
    \$pdo = getDB();
    \$stmt = \$pdo->prepare(\"SELECT * FROM users WHERE username = ? OR email = ? LIMIT 1\");
    \$stmt->execute([\$username, \$username]);
    \$user = \$stmt->fetch();
    
    if (\$user && password_verify(\$password, \$user['password_hash'])) {
        if (!\$user['is_active']) {
            return ['success' => false, 'error' => 'Account is deactivated'];
        }
        
        \$_SESSION['user_id'] = \$user['id'];
        \$_SESSION['username'] = \$user['username'];
        \$_SESSION['role'] = \$user['role'];
        \$_SESSION['full_name'] = \$user['full_name'];
        
        return ['success' => true, 'role' => \$user['role']];
    }
    
    return ['success' => false, 'error' => 'Invalid credentials'];
}

function isLoggedIn() {
    return isset(\$_SESSION['user_id']);
}

function isAdmin() {
    return isset(\$_SESSION['role']) && \$_SESSION['role'] == 'admin';
}

function requireLogin() {
    if (!isLoggedIn()) {
        header('Location: /login.php');
        exit;
    }
}

function requireAdmin() {
    requireLogin();
    if (!isAdmin()) {
        die('Access denied. Admin only.');
    }
}

function logout() {
    session_destroy();
    header('Location: /login.php');
    exit;
}
";
                file_put_contents('config/auth.php', $authContent);
            }
            
            // Create constants.php if not exists
            if (!file_exists('config/constants.php')) {
                $constantsContent = "<?php
/**
 * System Constants
 */

define('GRADE_WEIGHTS', [1 => 2, 2 => 4, 3 => 7, 4 => 10]);
define('GRADE_CSS', [1 => 'grade-1', 2 => 'grade-2', 3 => 'grade-3', 4 => 'grade-4']);
define('SUBSCRIPTION_PLANS', ['1month' => 30, '6month' => 180, '1year' => 365, 'unlimited' => null]);
define('ITEMS_PER_PAGE', 20);
define('DISPLAY_DATE_FORMAT', 'd-m-Y');
define('DISPLAY_DATE_TIME_FORMAT', 'd-m-Y H:i:s');
define('SESSION_LIFETIME', 7200);
define('PASSWORD_MIN_LENGTH', 6);
";
                file_put_contents('config/constants.php', $constantsContent);
            }
            
            $success = "Installation completed successfully!";
            $configExists = true;
            
        } catch (PDOException $e) {
            $error = "Database error: " . $e->getMessage();
        } catch (Exception $e) {
            $error = "Error: " . $e->getMessage();
        }
    }
}

// Check if we can proceed
$configWritable = is_writable('config/');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Installation - Homoeopathy System</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 50px 0;
        }
        .install-card {
            border-radius: 20px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            overflow: hidden;
            max-width: 800px;
            margin: 0 auto;
        }
        .install-header {
            background: #2c3e50;
            color: white;
            padding: 30px;
            text-align: center;
        }
        .install-body {
            padding: 40px;
            background: white;
        }
        .step-indicator {
            display: flex;
            justify-content: space-between;
            margin-bottom: 30px;
        }
        .step {
            flex: 1;
            text-align: center;
            padding: 10px;
            background: #f0f0f0;
            border-radius: 5px;
            margin: 0 5px;
        }
        .step.active {
            background: #667eea;
            color: white;
        }
        .step.completed {
            background: #28a745;
            color: white;
        }
    </style>
</head>
<body>
    <div class="install-card">
        <div class="install-header">
            <h2>🏥 Homoeopathy System Installation</h2>
            <p>Kent's Repertory | Classical Homeopathy</p>
        </div>
        <div class="install-body">
            <?php if ($error): ?>
                <div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
            <?php endif; ?>
            
            <?php if ($success): ?>
                <div class="alert alert-success">
                    <?php echo htmlspecialchars($success); ?>
                    <hr>
                    <p class="mb-0">
                        <strong>Admin Login:</strong> <?php echo $admin_user; ?> / (password you set)<br>
                        <a href="login.php" class="btn btn-success mt-2">Go to Login →</a>
                    </p>
                </div>
                <div class="alert alert-warning mt-3">
                    <strong>⚠️ Security Notice:</strong><br>
                    Please delete the <code>install.php</code> file immediately for security reasons!
                </div>
            <?php elseif ($configExists): ?>
                <div class="alert alert-info">
                    <strong>System Already Installed!</strong><br>
                    <a href="login.php">Go to Login →</a>
                </div>
                <div class="alert alert-warning">
                    <strong>Security Notice:</strong><br>
                    Please delete the <code>install.php</code> file for security!
                </div>
            <?php elseif (!$configWritable): ?>
                <div class="alert alert-danger">
                    <strong>Permission Error!</strong><br>
                    The <code>config/</code> directory is not writable.<br>
                    Please run: <code>chmod 755 config/</code> or <code>chmod 777 config/</code>
                </div>
            <?php else: ?>
                <div class="step-indicator">
                    <div class="step active">Step 1: Database</div>
                    <div class="step">Step 2: Admin</div>
                    <div class="step">Step 3: Complete</div>
                </div>
                
                <form method="POST" action="">
                    <h5>Database Configuration</h5>
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label>Database Host</label>
                            <input type="text" name="db_host" class="form-control" value="localhost" required>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label>Database Name</label>
                            <input type="text" name="db_name" class="form-control" value="drmdferdous_kent" required>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label>Database Username</label>
                            <input type="text" name="db_user" class="form-control" value="root" required>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label>Database Password</label>
                            <input type="password" name="db_pass" class="form-control">
                        </div>
                    </div>
                    
                    <h5 class="mt-3">Admin Account</h5>
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label>Admin Username</label>
                            <input type="text" name="admin_user" class="form-control" value="admin" required>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label>Admin Email</label>
                            <input type="email" name="admin_email" class="form-control" value="admin@drmdferdous.com" required>
                        </div>
                        <div class="col-md-12 mb-3">
                            <label>Admin Password</label>
                            <input type="password" name="admin_pass" class="form-control" required>
                            <small class="text-muted">Minimum 6 characters</small>
                        </div>
                    </div>
                    
                    <div class="alert alert-info">
                        <i class="fas fa-info-circle"></i> 
                        <strong>Note:</strong> If tables or admin user already exist, they will be preserved and only missing data will be added.
                    </div>
                    
                    <button type="submit" class="btn btn-primary btn-lg w-100 mt-3">
                        Install System →
                    </button>
                </form>
            <?php endif; ?>
        </div>
    </div>
</body>
</html>