<?= $this->extend('layouts/app') ?>

<?= $this->section('content') ?>
<div class="row g-4">
    <div class="col-lg-7">
        <div class="core-card p-4">
            <h2 class="h5 mb-3">Connexions enregistrées</h2>
            <table class="table align-middle">
                <thead><tr><th>Nom</th><th>Base</th><th>Hôte</th><th></th></tr></thead>
                <tbody>
                <?php foreach ($connections as $connection): ?>
                    <tr>
                        <td><?= esc($connection['name']) ?></td>
                        <td><?= esc($connection['database_name']) ?></td>
                        <td><?= esc($connection['host']) ?>:<?= esc((string) $connection['port']) ?></td>
                        <td class="text-end"><a class="btn btn-outline-primary btn-sm" href="<?= site_url('/database-connections/' . $connection['id']) ?>">Explorer</a></td>
                    </tr>
                <?php endforeach; ?>
                <?php if ($connections === []): ?>
                    <tr><td colspan="4" class="text-muted">Aucune connexion pour le moment.</td></tr>
                <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="col-lg-5">
        <div class="core-card p-4">
            <h2 class="h5 mb-3">Ajouter une connexion SQL</h2>
            <form method="post" action="<?= site_url('/database-connections') ?>">
                <?= csrf_field() ?>
                <div class="mb-3"><label class="form-label">Nom</label><input class="form-control" name="name" required></div>
                <div class="mb-3"><label class="form-label">Hôte</label><input class="form-control" name="host" value="localhost" required></div>
                <div class="mb-3"><label class="form-label">Port</label><input class="form-control" name="port" value="3306"></div>
                <div class="mb-3"><label class="form-label">Base</label><input class="form-control" name="database_name" required></div>
                <div class="mb-3"><label class="form-label">Utilisateur</label><input class="form-control" name="username" required></div>
                <div class="mb-3"><label class="form-label">Mot de passe</label><input class="form-control" name="password" type="password"></div>
                <button class="btn btn-primary w-100" type="submit">Enregistrer</button>
            </form>
        </div>
    </div>
</div>
<?= $this->endSection() ?>
