<?php
// sellbazar/install.php
// Run this file once to verify installation and create sample data

include 'includes/config.php';

$installed = false;

// Check if installation is complete
$stmt = $pdo->query("SELECT COUNT(*) FROM settings");
$settingsCount = $stmt->fetchColumn();

if ($settingsCount > 0) {
    $installed = true;
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SellBazar Installation</title>
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h3 class="mb-0">SellBazar Installation</h3>
                </div>
                <div class="card-body">
                    <?php if ($installed): ?>
                        <div class="alert alert-success">
                            <h4>Installation Complete!</h4>
                            <p>The database has been set up successfully.</p>
                        </div>
                        <div class="mt-3">
                            <h5>Admin Login Details:</h5>
                            <ul>
                                <li><strong>Email:</strong> admin@sellbazar.com</li>
                                <li><strong>Password:</strong> admin123</li>
                            </ul>
                            <a href="admin/" class="btn btn-primary">Go to Admin Panel</a>
                            <a href="index.php" class="btn btn-secondary">Go to Website</a>
                        </div>
                    <?php else: ?>
                        <div class="alert alert-info">
                            <h4>Database is being set up...</h4>
                            <p>Please wait while we create the necessary tables and data.</p>
                        </div>
                        <div class="text-center">
                            <a href="?run=setup" class="btn btn-primary">Run Installation</a>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>

<?php if (isset($_GET['run']) && $_GET['run'] == 'setup'): ?>
<script>
    window.location.href = '?';
</script>
<?php endif; ?>
</body>
</html>