<?php use PHPCensor\Helper\Lang; ?>
<div class="clearfix"  style="margin-bottom: 20px;">
    <a class="btn btn-success pull-right" href="<?php print APP_URL . 'group/edit'; ?>">
        <?php Lang::out('group_add'); ?>
    </a>
</div>

<div class="box">
    <table class="table table-hover">
        <thead>
        <tr>
            <th><?php Lang::out('group_title'); ?></th>
            <th><?php Lang::out('group_count'); ?></th>
            <th></th>
        </tr>
        </thead>
        <tbody>
            <?php foreach($groups as $group): ?>
            <tr>
                <td><?php print $group['title']; ?></td>
                <td><?php print count($group['projects']); ?></td>
                <td>
                    <div class="btn-group btn-group-right">
                        <a class="btn btn-default btn-sm" href="<?php echo APP_URL ?>group/edit/<?php print $group['id']; ?>"><?php Lang::out('group_edit'); ?></a>
                        <?php if($this->User()->getIsAdmin() && (!count($group['projects']))): ?>
                            <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li><a href="<?php echo APP_URL ?>group/delete/<?php print $group['id']; ?>" class="delete-group"><?php Lang::out('group_delete'); ?></a></li>
                            </ul>
                        <?php endif; ?>
                    </div>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>

<script>
    $(document).ready(function() {
        $('.delete-group').on('click', function (e) {
            e.preventDefault();
            confirmDelete(e.target.href).onCloseConfirmed = function () {window.location = window.location.href};
        });
    });
</script>