<?= $this->include('partials/html') ?>

<head>
    <?php echo view("partials/title-meta", array("title" => $title)) ?>
    <?= $this->include('partials/head-css') ?>
</head>

<body>
    <div class="wrapper">
        <?= $this->include('partials/menu') ?>

        <div class="page-content">
            <div class="page-container">
                <div class="row">
                    <div class="col-12">
                        <div class="page-title-box">
                            <h4 class="page-title"><?= esc($title) ?></h4>
                        </div>
                    </div>
                </div>

                <?php if (session()->has('message')): ?>
                    <div class="alert alert-success"><?= session('message') ?></div>
                <?php endif; ?>
                <?php if (session()->has('errors')): ?>
                    <?php foreach (session('errors') as $error): ?>
                        <div class="alert alert-danger"><?= $error ?></div>
                    <?php endforeach; ?>
                <?php endif; ?>

                <div class="row">
                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="header-title">Nouvelle permission</h4>
                                <form action="/admin/roles/permissions/store" method="post">
                                    <?= csrf_field() ?>

                                    <div class="mb-3">
                                        <label class="form-label">Nom</label>
                                        <input type="text" name="name" class="form-control" required>
                                    </div>

                                    <div class="mb-3">
                                        <label class="form-label">Slug</label>
                                        <input type="text" name="slug" class="form-control" required placeholder="users.create">
                                    </div>

                                    <div class="mb-3">
                                        <label class="form-label">Description</label>
                                        <textarea name="description" class="form-control" rows="2"></textarea>
                                    </div>

                                    <button type="submit" class="btn btn-primary">Ajouter</button>
                                </form>
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="header-title">Permissions existantes</h4>
                                <div class="table-responsive">
                                    <table class="table table-striped">
                                        <thead>
                                            <tr>
                                                <th>Nom</th>
                                                <th>Slug</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php foreach ($permissions as $permission): ?>
                                                <tr>
                                                    <td><?= esc($permission['name']) ?></td>
                                                    <td><code><?= esc($permission['slug']) ?></code></td>
                                                    <td>
                                                        <a href="/admin/roles/permissions/delete/<?= $permission['id'] ?>" class="btn btn-sm btn-danger" onclick="return confirm('Confirmer ?')">Supprimer</a>
                                                    </td>
                                                </tr>
                                            <?php endforeach; ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row mt-3">
                    <div class="col-12">
                        <a href="/admin/roles" class="btn btn-secondary">Retour aux rôles</a>
                    </div>
                </div>

            </div>
        </div>

    </div>

    <?= $this->include('partials/footer-scripts') ?>
</body>

</html>
