<?php require __DIR__ . '/../../layouts/header.php'; ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="fw-bold mb-0"><?= e(trans('assign_permissions')) ?> — <?= e(role_label((string) $role['code'])) ?></h1>
    <a href="<?= e(base_path('admin/rbac')) ?>" class="btn ec-btn btn-outline-secondary rounded-3"><?= e(trans('back')) ?></a>
</div>

<div class="ec-card  ">
    <div class="ec-card-body p-4">
        <form method="post" action="<?= e(base_path('admin/rbac/edit-role?role_id=' . (int) $role['id'])) ?>">
            <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
            <input type="hidden" name="role_id" value="<?= e((string) $role['id']) ?>">

            <div class="row g-3">
                <?php foreach ($permissions as $permission): ?>
                    <div class="col-md-4">
                        <div class="form-check border rounded-3 p-3">
                            <input class="form-check-input" type="checkbox" name="permission_ids[]" value="<?= e((string) $permission['id']) ?>" id="perm_<?= e((string) $permission['id']) ?>" <?= in_array((int) $permission['id'], $assigned, true) ? 'checked' : '' ?>>
                            <label class="form-check-label" for="perm_<?= e((string) $permission['id']) ?>">
                                <strong><?= e((string) $permission['code']) ?></strong><br>
                                <span class="text-muted small"><?= e((string) $permission['name']) ?></span>
                            </label>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>

            <div class="mt-4">
                <button type="submit" class="btn ec-btn btn-success rounded-3"><?= e(trans('save')) ?></button>
            </div>
        </form>
    </div>
</div>

<?php require __DIR__ . '/../../layouts/footer.php'; ?>
