<?php
$form->prepare();
$sectionNavs = [
    'user-information' => $this->translate('User Information'),
    'change-password' => $this->translate('Password'),
    'edit-keys' => $this->translate('API Keys')
];
$formElement = $this->plugin('formElement');
?>

<?php echo $this->pageTitle(sprintf($this->translate('Edit User: “%s”'), $user->email())); ?>
<?php $this->trigger('view.edit.before'); ?>
<?php echo $this->form()->openTag($form); ?>
<div id="page-actions">
    <button type="submit"><?php echo $this->translate('Save'); ?></button>
</div>
<?php echo $this->sectionNav($sectionNavs, 'view.edit.section_nav' ); ?>
<?php $this->trigger('view.edit.form.before', array('form' => $form)); ?>
<fieldset id="user-information" class="section active">
    <?php echo $this->formCollection($form->get('user-information'), false); ?>
</fieldset>
<fieldset id="change-password" class="section">
    <?php echo $this->formCollection($form->get('change-password'), false); ?>
</fieldset>
<fieldset id="edit-keys" class="section">
    <?php if ($keys): ?>
    <h3 id="keys-existing-heading"><?php echo $this->translate('Keys'); ?></h3>
    <table class="tablesaw tablesaw-stack" data-tablesaw-mode="stack">
        <thead>
            <tr>
                <th><?php echo $this->translate('Label'); ?></th>
                <th><?php echo $this->translate('ID'); ?></th>
                <th><?php echo $this->translate('Delete'); ?>?</th>
            </tr>
        </thead>
        <?php foreach ($keys as $id => $label): ?>
        <tr>
            <td><?php echo $this->escapeHtml($label); ?></td>
            <td><code><?php echo $this->escapeHtml($id); ?></code></td>
            <td>
                <input type="checkbox"
                    name="delete[]"
                    value="<?php echo $this->escapeHtml($id); ?>"
                    aria-label="Mark key &ldquo;<?php echo $this->escapeHtml($label); ?>&rdquo; for deletion">
            </td>
        </tr>
        <?php endforeach; ?>
    </table>
    <?php endif; ?>
    <h3><?php echo $this->translate('Add a New Key'); ?></h3>
    <?php echo $this->formCollection($form->get('edit-keys'), false); ?>
</fieldset>
<?php $this->trigger('view.edit.form.after', array('form' => $form)); ?>
 <?php echo $formElement($form->get('csrf')); ?>
<?php echo $this->form()->closeTag(); ?>
<?php $this->trigger('view.edit.after'); ?>
