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

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

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'    => 'Transport',
    'workspaceCrumbCurrent' => 'Map Contract',
    'workspaceTitle'        => 'Map Contract to Site',
    'workspaceDesc'         => 'Tell the AI planner where a contract\'s employees must be transported.',
]) ?>

<article class="enterprise-settings-card" style="max-width:860px;">
    <div class="enterprise-settings-card__head">
        <i class="fa-solid fa-building-flag"></i>
        <h2 class="enterprise-settings-card__title">Contract Site Mapping</h2>
    </div>

    <?= $this->include('Modules\Transport\Views\partials\form_errors') ?>

    <form action="<?= base_url('transport/ai/contract-sites') ?>" method="post" novalidate>
        <?= csrf_field() ?>
        <div class="enterprise-settings-fields">
            <div class="enterprise-field enterprise-field--full">
                <label class="enterprise-field-label">Contract <span class="text-danger">*</span></label>
                <select name="contract_id" class="form-select" required>
                    <option value="">Select contract…</option>
                    <?php foreach ($contracts as $contract): ?>
                        <option value="<?= (int) $contract['id'] ?>" <?= old('contract_id') == $contract['id'] ? 'selected' : '' ?>>
                            <?= esc(($contract['number'] ? $contract['number'] . ' — ' : '') . $contract['title']) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
                <div class="form-text">Only active contracts without an existing site mapping are listed.</div>
            </div>
            <?= $this->include('Modules\Transport\Views\ai\contract_sites\_form') ?>
        </div>
        <div class="enterprise-settings-card__footer">
            <a href="<?= base_url('transport/ai/contract-sites') ?>" class="btn btn-outline-secondary">Cancel</a>
            <button type="submit" class="btn btn-primary">Save Mapping</button>
        </div>
    </form>
</article>

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