
    <?php
    // Don't show this container when only rendering the widget section
    if (!($render_section ?? null) && !($is_ajax ?? null)) {
    ?>
    <div class="col-md-3">
        <?php echo ($navigation ?? null); ?>
    </div>
    <div class="col-md-9">
    <?php
    }
    ?>
        <div class="row">
            <div class="col-md-12">
                <?php echo ($message ?? null);?>

                <?php
                $link_buttons = [
                    ['name' => $this->_('ClientManagers.index.add_manager', true), 'attributes' => ['href' => $this->base_uri . 'managers/add/']]
                ];

                $this->WidgetClient->clear();
                $this->WidgetClient->setLinkButtons($link_buttons);
                $this->WidgetClient->create($this->_('ClientManagers.index.boxtitle_managers', true), ['id' => 'client_managers'], ($render_section ?? null));
                $this->WidgetClient->startBody();

                if (($managers ?? false) && (($num_managers = count($managers)) > 0)) {
                ?>
                <div class="table-responsive">
                    <table class="table table-curved table-striped" id="managers">
                        <thead>
                            <tr>
                                <th><a href="<?php echo $this->Html->safe($this->base_uri . 'managers/index/?sort=client_id_code&order=' . ($sort == 'client_id_code' ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == 'client_id_code' ? ' ' . $order : '');?>"><?php $this->_('ClientManagers.index.heading_client_id');?></a></th>
                                <th><a href="<?php echo $this->Html->safe($this->base_uri . 'managers/index/?sort=email&order=' . ($sort == 'email' ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == 'email' ? ' ' . $order : '');?>"><?php $this->_('ClientManagers.index.heading_email');?></a></th>
                                <th><a href="<?php echo $this->Html->safe($this->base_uri . 'managers/index/?sort=first_name&order=' . ($sort == 'first_name' ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == 'first_name' ? ' ' . $order : '');?>"><?php $this->_('ClientManagers.index.heading_name');?></a></th>
                                <th><?php $this->_('ClientManagers.index.heading_company');?></th>
                                <th><?php $this->_('ClientManagers.index.heading_status');?></th>
                                <th><?php $this->_('ClientManagers.index.heading_options');?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            // Loop through all managers
                            for ($i = 0; $i < $num_managers; $i++) {
                            ?>
                            <tr>
                                <td><?php echo ($managers[$i]->status == 'accepted') ? $this->Html->safe($managers[$i]->client_id_code ?? null) : '';?></td>
                                <td><?php echo $this->Html->safe($managers[$i]->email ?? null);?></td>
                                <td><?php echo ($managers[$i]->status == 'accepted') ? $this->Html->concat(' ', (isset($managers[$i]->first_name) ? $this->Html->safe($managers[$i]->first_name) : null), (isset($managers[$i]->last_name) ? $this->Html->safe($managers[$i]->last_name) : null)) : '';?></td>
                                <td><?php echo ($managers[$i]->status == 'accepted') ? $this->Html->safe($managers[$i]->company ?? null) : '';?></td>
                                <td><?php $this->_('ClientManagers.index.text_status_' . ($managers[$i]->status == 'accepted' ? 'accepted' : 'pending'));?></td>
                                <td>
                                    <?php
                                    $this->Form->create($this->base_uri . 'managers/revoke/');

                                    if ($managers[$i]->status == 'accepted') {
                                    $this->Form->fieldHidden('token', $managers[$i]->contact_id ?? ($managers[$i]->token ?? null));
                                    ?>
                                    <div class="btn-group">
                                        <a href="<?php echo $this->Html->safe($this->base_uri . 'managers/edit/' . (isset($managers[$i]->contact_id) ? $this->Html->safe($managers[$i]->contact_id) : null) . '/');?>" class="btn btn-xs btn-light">
                                            <i class="fas fa-edit fa-fw"></i> <?php $this->_('ClientManagers.index.option_edit');?>
                                        </a>
                                        <button class="btn btn-xs btn-light dropdown-toggle" data-toggle="dropdown" type="button">
                                            <span class="caret"></span>
                                        </button>
                                        <div class="dropdown-menu">
                                            <a class="dropdown-item" href="<?php echo $this->Html->safe($this->base_uri . 'managers/revoke/' . (isset($managers[$i]->contact_id) ? $this->Html->safe($managers[$i]->contact_id) : null) . '/');?>" rel="<?php echo $this->Html->safe($this->_('ClientManagers.index.confirm_revoke', true));?>">
                                                <i class="fas fa-ban fa-fw"></i> <?php $this->_('ClientManagers.index.option_revoke');?>
                                            </a>
                                        </div>
                                    </div>
                                    <?php
                                    } else {
                                    $this->Form->fieldHidden('token', ($managers[$i]->token ?? null));
                                    ?>
                                    <div class="btn-group">
                                        <a href="<?php echo $this->Html->safe($this->base_uri . 'managers/revoke/' . (isset($managers[$i]->token) ? $this->Html->safe($managers[$i]->token) : null) . '/');?>" rel="<?php echo $this->Html->safe($this->_('ClientManagers.index.confirm_revoke', true));?>" class="btn btn-xs btn-light">
                                            <i class="fas fa-ban fa-fw"></i> <?php $this->_('ClientManagers.index.option_revoke');?>
                                        </a>
                                    </div>
                                    <?php
                                    }

                                    $this->Form->end();
                                    ?>
                                </td>
                            </tr>
                            <?php
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
                <?php
                } else {
                ?>
                <div class="alert alert-info">
                    <p><?php $this->_('ClientManagers.index.no_results');?></p>
                </div>
                <?php
                }

                $this->WidgetClient->endBody();
                $this->WidgetClient->end();
                ?>
            </div>
        </div>
    <?php
    // Don't show this container when only rendering the widget section
    if (!(isset($render_section) ? $render_section : null) && !(isset($is_ajax) ? $is_ajax : null)) {
    ?>
    </div>
    <?php
    }
    ?>
<?php
$this->Javascript->setInline("
	$(document).ready(function() {
		// Handle confirmation on delete action
		$('#client_managers a[rel]').blestaModalConfirm({
			base_url: '" . $this->base_uri . "',
			submit: true
		});
	});
");
?>