<?php
    /**
     * @var \App\View\AppView $this
     * @var Icing\Model\Entity\UserGroup[]|\Cake\Collection\CollectionInterface $userGroups
     * @var Icing\Model\Entity\UserGroup $blankUserGroup
     */

    $this->assign('title', 'User Groups');

    $this->Breadcrumbs->prepend('Users', ['controller' => 'Users', 'action' => 'index']);

    $this->PageActions->group('top-right')
        ->link(
            '<i class="fa-solid fa-users fa-fw"></i> Users',
            ['controller' => 'Users', 'action' => 'index'],
            ['class' => 'btn btn-primary']
        )
        ->link(
            '<i class="fa-solid fa-user-lock fa-fw"></i> Manage Roles',
            ['controller' => 'Roles', 'action' => 'index'],
            ['class' => 'btn btn-primary'],
        )
        ->link(
            '<i class="fa-solid fa-unlock-keyhole fa-fw"></i> Manage Permissions',
            ['controller' => 'Permissions', 'action' => 'index'],
            ['class' => 'btn btn-primary']
        );


?>

<div class="card">
    <div class="card-header">
        <?= $this->element('Icing.quick_search', ['advanced' => '#UserGroupsFilter']) ?>
    </div>

    <div class="table-responsive">
        <table class="table table-sm table-hover m-0">
            <thead class="thead-light table-nowrap">
            <tr>
                <th><?= $this->Paginator->sort('name') ?></th>
                <th><?= $this->Paginator->sort('homepage') ?></th>
                <th><?= $this->Paginator->sort('default_user_group') ?></th>
                <th><?= $this->Paginator->sort('created') ?></th>
                <th><?= $this->Paginator->sort('modified') ?></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($userGroups as $userGroup): ?>

                <tr
                    data-fetch="link"
                    data-url="<?= $this->Url->build(['action' => 'edit', $userGroup->id]) ?>"
                >
                    <td><?= h($userGroup->name) ?></td>
                    <td><?= h($userGroup->homepage) ?></td>
                    <td><?= $this->Html->checkmark($userGroup->default_user_group) ?></td>
                    <td><?= h($userGroup->created) ?></td>
                    <td><?= h($userGroup->modified) ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <div class="card-footer">
        <?= $this->element('Icing.pagination') ?>
    </div>
</div>


<?= $this->Form->create(
    $blankUserGroup,
    [
        'type'         => 'get',
        'valueSources' => 'query',
        'novalidate'   => true,
        'floating'     => true,
    ]
) ?>

<div
    class="offcanvas offcanvas-end"
    tabindex="-1"
    id="UserGroupsFilter"
    aria-labelledby="UsersGroupsFilterLabel"
    aria-modal="true"
    role="dialog"
>
    <div class="offcanvas-header">
        <h3
            class="offcanvas-title"
            id="userGroupsFilterLabel"
            tabindex="0"
        >
            Advanced Search
        </h3>
        <div class="d-flex align-items-start">
            <a
                href="<?= $this->Url->build(['?' => array_intersect_key($this->getRequest()->getQuery(), $this->Paginator->params())]) ?>"
                class="p-2 text-body"
                data-bs-toggle="tooltip"
                title="Reset Form"
                data-bs-placement="left"
            >
                <i class="fa-solid fa-rotate-left fa-lg"></i>
            </a>
            <a
                href="javascript: void"
                data-bs-dismiss="offcanvas"
                aria-label="Close"
                class="p-2 text-body"
                data-bs-toggle="tooltip"
                title="Close"
                data-bs-placement="left"
            >
                <i class="fa fa-times fa-lg"></i>
            </a>
        </div>
    </div>

    <div class="offcanvas-body scrollbar">

        <?php
            echo $this->Form->control('search', ['label' => 'Quick Search']);
            echo $this->Form->control('name');
            echo $this->Form->control(
                'default_user_group',
                [
                    'options' => [0 => 'No', 1 => 'Yes'],
                    'empty'   => true,
                ]
            );
        ?>

    </div>

    <div class="offcanvas-body flex-grow-0 border-top">
        <div class="d-grid">
            <button
                type="submit"
                class="btn btn-primary"
            >
                Submit
            </button>
        </div>
    </div>
</div>
<?= $this->Form->end() ?>

<?php
    $this->PageActions
        ->group('bottom-right')
        ->link(
            '<i class="fa fa-user-plus fa-fw"></i> New User Group',
            ['action' => 'add'],
            ['class' => 'btn btn-success', 'data-fetch' => 'modal']
        );
?>





