<?php /* @var \dokuwiki\plugin\bez\meta\Tpl $tpl */ ?>
<?php if ($tpl->get('error')): ?>
<div class="error" style="background: #f8d7da; border: 1px solid #f5c6cb; color: #721c24; padding: 12px 15px; border-radius: 5px; margin-bottom: 15px;">
    <strong>Error:</strong> <?php echo $tpl->get('error') ?>
</div>
<?php endif; ?>
<form action="<?php echo $tpl->url('types') ?>" method="POST">
<table>
<tr>
    <th>Nombre/Raz&oacute;n social</th>
    <th>NIT</th>
    <th>DV</th>
    <th>Cantidad</th>
    <th colspan="2">Acciones</th>
</tr>
<?php foreach ($tpl->get('labels') as $label): ?>
<tr>
    <?php if (in_array($tpl->param('action'), array('edit', 'update')) &&
                $tpl->param('id') == $label->id): ?>
            <td>
                <input type="hidden" name="id" value="<?php echo $label->id ?>" />
                <input name="name" value="<?php echo $tpl->value('name') ?>" />
            </td>
            <td>
                <input name="nit" value="<?php echo $tpl->value('nit') ?>" style="width: 120px;"
                       pattern="[0-9]*" inputmode="numeric" maxlength="20"
                       title="Solo se permiten números"
                       oninput="this.value = this.value.replace(/[^0-9]/g, '')" />
            </td>
            <td>
                <input name="codigo_verificacion" value="<?php echo $tpl->value('codigo_verificacion') ?>" style="width: 40px;"
                       pattern="[0-9]" inputmode="numeric" maxlength="1"
                       title="Solo un dígito (0-9)"
                       oninput="this.value = this.value.replace(/[^0-9]/g, '').substring(0,1)" />
            </td>
            <td>
                <a href="<?php echo $tpl->url('threads', 'label_id', $label->id) ?>">
                    <?php echo $label->count ?>
                </a>
            </td>
            <td colspan="2">
                <button name="action" value="update"><?php echo $tpl->getLang('save') ?></button>
                <a href="<?php echo $tpl->url('types') ?>">
                    <?php echo $tpl->getLang('cancel') ?>
                </a>
            </td>
    <?php else: ?>
        <td><?php echo $label->name ?></td>
        <td><?php echo $label->nit ?></td>
        <td><?php echo $label->codigo_verificacion ?></td>
        <td>
            <a href="<?php echo $tpl->url('threads', 'label_id', $label->id) ?>">
                <?php echo $label->count ?>
            </a>
        </td>
        <td>
            <a href="<?php echo $tpl->url('types', 'action', 'edit', 'id', $label->id) ?>">
                <?php echo $tpl->getLang('edit') ?>
            </a>
        </td>
        <?php if ($label->count == 0): ?>
            <td>
                <a onclick="return confirm('<?php echo $tpl->getLang('js')['remove_confirm'] ?>')"
                    href="<?php echo $tpl->url('types', 'action', 'remove', 'id', $label->id) ?>">
                    <?php echo $tpl->getLang('delete') ?>
                </a>
            </td>
        <?php else: ?>
            <td></td>
        <?php endif ?>
    <?php endif ?>
</tr>
<?php endforeach ?>

<?php if ($tpl->param('action') !== 'edit' && $tpl->param('action') !== 'update'): ?>
<tr>
    <td><input name="name" value="<?php echo $tpl->value('name') ?>" placeholder="Nombre/Raz&oacute;n social" /></td>
    <td><input name="nit" value="<?php echo $tpl->value('nit') ?>" style="width: 120px;" placeholder="NIT"
               pattern="[0-9]*" inputmode="numeric" maxlength="20"
               title="Solo se permiten números"
               oninput="this.value = this.value.replace(/[^0-9]/g, '')" /></td>
    <td><input name="codigo_verificacion" value="<?php echo $tpl->value('codigo_verificacion') ?>" style="width: 40px;" placeholder="DV"
               pattern="[0-9]" inputmode="numeric" maxlength="1"
               title="Solo un dígito (0-9)"
               oninput="this.value = this.value.replace(/[^0-9]/g, '').substring(0,1)" /></td>
    <td></td>
    <td colspan="2">
        <button name="action" value="add"><?php echo $tpl->getLang('save') ?></button>
    </td>
</tr>
<?php endif ?>
</table>
</form>
