<?php
require_once __DIR__ . '/includes/functions.php';

$message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    try {
        $dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET;
        $pdo = new PDO($dsn, DB_USER, DB_PASS, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
        $sql = file_get_contents(__DIR__ . '/database.sql');
        if (!$sql) {
            throw new RuntimeException('database.sql okunamadi.');
        }
        $pdo->exec($sql);
        $message = 'Kurulum tamamlandi. Guvenlik icin install.php dosyasini silin. Admin paneline admin / Admin123! bilgileriyle girebilirsiniz.';
    } catch (Throwable $e) {
        $message = 'Kurulum hatasi: ' . $e->getMessage();
    }
}
$meta = pageMeta(['title' => 'Atakoy Su Sporlari Kurulum', 'canonical' => url('install.php')]);
require __DIR__ . '/includes/header.php';
?>
<section class="page-hero compact"><div><span class="eyebrow">cPanel kurulum</span><h1>Atakoy Su Sporlari Kurulum</h1><p>Mevcut cPanel MySQL veritabani icine tablolar ve baslangic icerikleri yuklenir.</p></div></section>
<section class="section contact-band">
    <?php if ($message): ?><div class="flash"><?= e($message) ?></div><?php endif; ?>
    <form class="lead-form glass-card" method="post">
        <button class="btn btn-primary" type="submit">Veritabanini Kur ve Seed Et</button>
        <p>DB: <?= e(DB_NAME) ?>, Kullanici: <?= e(DB_USER) ?>, Host: <?= e(DB_HOST) ?></p>
    </form>
</section>
<?php require __DIR__ . '/includes/footer.php'; ?>
