<?php
$canvasId = 'sigpad-' . bin2hex(random_bytes(4));
$fieldKey = $fieldKey ?? null;
?>
<div class="signature-pad" data-signable-type="<?= esc($signableType) ?>" data-signable-id="<?= (int) $signableId ?>" data-role="<?= esc($role) ?>" data-upload-url="<?= esc($uploadUrl) ?>" <?= $fieldKey ? 'data-field-key="' . esc($fieldKey) . '"' : '' ?>>
    <div class="grid grid-2">
        <div>
            <label>Nombre de quien firma</label>
            <input type="text" class="sig-name" value="<?= esc($currentName ?? '') ?>">
        </div>
        <div>
            <label>Firma (dibuja con el dedo o el mouse)</label>
            <div class="sig-canvas-wrap">
                <canvas id="<?= esc($canvasId) ?>" width="600" height="180" class="sig-canvas"></canvas>
            </div>
            <div class="actions-row" style="margin-top:.5rem">
                <button type="button" class="btn btn-secondary sig-clear">Limpiar</button>
                <button type="button" class="btn btn-primary sig-save">Guardar firma</button>
            </div>
            <small class="muted sig-status">
                <?php if (! empty($currentPath)): ?>
                    Firma registrada: <a href="<?= base_url($currentPath) ?>" target="_blank">ver</a>
                <?php endif; ?>
            </small>
        </div>
    </div>
</div>
