<?= $this->extend('layouts/enterprise') ?>

<?= $this->section('content') ?>

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'    => 'HRM',
    'workspaceCrumbCurrent' => 'Edit Document',
    'workspaceTitle'        => esc($document['type_name'] . ' — ' . $document['full_name']),
    'workspaceDesc'         => 'Update metadata or upload a new version.',
    'workspaceAction'       => [
        'href'  => base_url('documents/' . $document['id']),
        'label' => 'View Document',
        'icon'  => 'fa-solid fa-eye',
    ],
]) ?>

<article class="enterprise-settings-card" style="max-width:720px;">
    <div class="enterprise-settings-card__head">
        <i class="fa-solid fa-pen"></i>
        <h2 class="enterprise-settings-card__title">Edit Document</h2>
    </div>
    <p class="small text-muted px-3 pt-2 mb-0">Uploading a new file will create version <?= (int) $document['version_count'] + 1 ?> and preserve previous versions.</p>
    <?php if (session()->getFlashdata('errors')): ?>
        <div class="alert alert-danger py-2 small mx-3 mt-3">
            <ul class="mb-0 ps-3">
                <?php foreach ((array) session()->getFlashdata('errors') as $err): ?>
                    <li><?= esc(is_array($err) ? implode(', ', $err) : $err) ?></li>
                <?php endforeach; ?>
            </ul>
        </div>
    <?php endif; ?>
    <form action="<?= base_url('documents/' . $document['id']) ?>" method="post" enctype="multipart/form-data" novalidate>
        <?= csrf_field() ?>
        <?= $this->include('Modules\Documents\Views\records\_form', ['document' => $document]) ?>
        <div class="enterprise-settings-card__footer">
            <a href="<?= base_url('documents/' . $document['id']) ?>" class="btn btn-outline-secondary">Cancel</a>
            <button type="submit" class="btn btn-primary">Save Changes</button>
        </div>
    </form>
</article>

<?= $this->endSection() ?>
