<?php
$maxUploadFileBytes = (int) ($maxUploadFileBytes ?? \Core\RequestLimits::uploadMaxFileBytes());
$maxUploadFileLabel = (string) ($maxUploadFileLabel ?? \Core\RequestLimits::uploadMaxFileLabel());
$postMaxBytes = (int) ($postMaxBytes ?? \Core\RequestLimits::postMaxBytes());
$postMaxLabel = (string) ($postMaxLabel ?? \Core\RequestLimits::postMaxLabel());
$formTimeoutSeconds = (int) ($formTimeoutSeconds ?? \Core\RequestLimits::formTimeoutSeconds());
$formTimeoutMinutes = max(1, (int) ceil($formTimeoutSeconds / 60));
$formStartedAt = time();
?>
<div class="row justify-content-center">
    <div class="col-12 col-xl-11">
        <div class="hero-card mb-4">
            <div class="hero-card__content">
                <div>
                    <span class="badge text-bg-primary mb-3">RH / Admissão</span>
                    <h1 class="display-6 fw-bold mb-2">Ficha de Admissão de Colaborador</h1>
                    <p class="lead text-muted mb-0">Preencha os dados com atenção. Primeiro a ficha é enviada com os anexos principais; a foto de perfil fica para uma segunda etapa separada e mais leve.</p>
                </div>
                <div class="hero-card__aside">
                    <div class="hero-stat"><span>Etapas</span><strong>Ficha + Foto</strong></div>
                    <div class="hero-stat"><span>Tempo máximo</span><strong><?= e((string) $formTimeoutMinutes) ?> min</strong></div>
                    <div class="hero-stat"><span>Limite por arquivo</span><strong><?= e($maxUploadFileLabel) ?></strong></div>
                </div>
            </div>
        </div>

        <?php if (!empty($errors) || !empty($error)): ?>
            <div class="alert alert-danger shadow-sm form-alert">
                <strong><?= e($error ?? 'Revise o formulário. Existem campos obrigatórios ou inválidos.') ?></strong>
                <ul class="form-alert__list mb-0 mt-2">
                    <?php foreach ($errors as $message): ?>
                        <li><?= e($message) ?></li>
                    <?php endforeach; ?>
                </ul>
            </div>
        <?php endif; ?>

        <div class="card shadow-sm border-0"><div class="card-body p-3 p-lg-4">
            <form
                method="post"
                action="<?= e(baseUrl('admissoes')) ?>"
                enctype="multipart/form-data"
                novalidate
                autocomplete="off"
                data-mobile-wizard="true"
                data-upload-guard="true"
                data-form-time-limit-seconds="<?= e((string) $formTimeoutSeconds) ?>"
                data-max-file-size-bytes="<?= e((string) $maxUploadFileBytes) ?>"
                data-max-file-size-label="<?= e($maxUploadFileLabel) ?>"
                data-post-max-bytes="<?= e((string) $postMaxBytes) ?>"
                data-post-max-label="<?= e($postMaxLabel) ?>"
            >
                <?php $mode = 'create'; require dirname(__DIR__) . '/admissions/partials/form.php'; ?>
                <input type="hidden" name="form_started_at" value="<?= e((string) $formStartedAt) ?>">

                <div class="form-tips form-tips--limits mb-4">
                    <div><strong>Limite por arquivo:</strong> <?= e($maxUploadFileLabel) ?></div>
                    <div><strong>Limite total do envio:</strong> <?= e($postMaxLabel) ?></div>
                    <div><strong>Tempo máximo para envio:</strong> <?= e((string) $formTimeoutMinutes) ?> minutos</div>
                </div>

                <div class="form-actions-sticky wizard-final-actions d-flex flex-column flex-md-row gap-3 justify-content-end mt-4">
                    <button type="reset" class="btn btn-outline-secondary px-4">Limpar</button>
                    <button type="submit" class="btn btn-primary px-4">Enviar ficha e ir para foto</button>
                </div>
            </form>
        </div></div>
    </div>
</div>
