<?php $lead = $lead ?? []; ?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field">
        <label class="enterprise-field-label">First Name <span class="text-danger">*</span></label>
        <input type="text" name="first_name" class="form-control" value="<?= esc(old('first_name', $lead['first_name'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Last Name <span class="text-danger">*</span></label>
        <input type="text" name="last_name" class="form-control" value="<?= esc(old('last_name', $lead['last_name'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Company</label>
        <input type="text" name="company_name" class="form-control" value="<?= esc(old('company_name', $lead['company_name'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Job Title</label>
        <input type="text" name="job_title" class="form-control" value="<?= esc(old('job_title', $lead['job_title'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Email</label>
        <input type="email" name="email" class="form-control" value="<?= esc(old('email', $lead['email'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Phone</label>
        <input type="text" name="phone" class="form-control" value="<?= esc(old('phone', $lead['phone'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Lead Source</label>
        <select name="lead_source_id" class="form-select">
            <option value="">— Select —</option>
            <?php foreach ($sources as $s): ?>
                <option value="<?= $s['id'] ?>" <?= (string) old('lead_source_id', $lead['lead_source_id'] ?? '') === (string) $s['id'] ? 'selected' : '' ?>>
                    <?= esc($s['name']) ?> (<?= esc($s['code']) ?>)
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Assigned To</label>
        <select name="assigned_to" class="form-select">
            <option value="">— Auto-assign —</option>
            <?php foreach ($users as $u): ?>
                <option value="<?= $u->id ?>" <?= (string) old('assigned_to', $lead['assigned_to'] ?? '') === (string) $u->id ? 'selected' : '' ?>>
                    <?= esc($u->getFullName()) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Priority</label>
        <select name="priority" class="form-select">
            <?php foreach (['low', 'medium', 'high'] as $p): ?>
                <option value="<?= $p ?>" <?= old('priority', $lead['priority'] ?? 'medium') === $p ? 'selected' : '' ?>><?= ucfirst($p) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Status</label>
        <select name="status" class="form-select">
            <?php foreach (['new', 'contacted', 'qualified', 'unqualified'] as $s): ?>
                <option value="<?= $s ?>" <?= old('status', $lead['status'] ?? 'new') === $s ? 'selected' : '' ?>><?= ucfirst($s) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Estimated Value</label>
        <input type="number" name="estimated_value" class="form-control" step="0.01" min="0"
               value="<?= esc(old('estimated_value', $lead['estimated_value'] ?? '')) ?>">
    </div>
    <div class="enterprise-field enterprise-settings-fields--full">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $lead['notes'] ?? '')) ?></textarea>
    </div>
</div>
