@php $isEdit = $isEdit ?? false; $compact = (bool) ($compact ?? false); $lead = $lead ?? null; $labelClass = 'block text-sm font-medium text-gray-700'; $inputClass = $compact ? 'mt-1 block w-full rounded-lg border-gray-300 text-sm py-2 focus:border-red-500 focus:ring-red-500' : 'mt-1 block w-full rounded-lg border-gray-300 focus:border-red-500 focus:ring-red-500'; $selectWrapClass = $compact ? 'mt-1 block w-full max-w-md min-h-[2.25rem]' : 'mt-1 block w-full max-w-md'; $gridGap = $compact ? 'gap-3' : 'gap-4'; $sectionClass = $compact ? 'space-y-4 border-t border-gray-100 pt-4 first:border-t-0 first:pt-0' : 'rounded-xl border border-gray-200 bg-white p-5 space-y-5'; $sectionHeadingClass = $compact ? 'text-sm font-semibold text-gray-900' : 'text-sm font-semibold text-gray-900'; $hintClass = $compact ? 'mt-1 text-xs text-gray-500' : 'mt-2 text-sm text-gray-600'; $val = static function (string $field, mixed $default = '') use ($isEdit, $lead): mixed { if (old($field) !== null) { return old($field); } if ($isEdit && $lead !== null) { return $lead->{$field} ?? $default; } return $default; }; $customerSelectOptions = [['value' => '', 'label' => 'None']]; foreach (($customers ?? collect()) as $cust) { $customerSelectOptions[] = ['value' => (string) $cust->id, 'label' => $cust->displayName()]; } $customerSelected = (string) old('customer_id', ''); $selectedCustomerRecord = (! $isEdit && filled($customerSelected)) ? ($customers ?? collect())->firstWhere('id', (int) $customerSelected) : null; $leadType = (string) old('lead_type', $isEdit ? ($lead?->lead_type ?? 'individual') : ($selectedCustomerRecord?->lead_type ?? 'individual')); $leadTypeSelectOptions = [ ['value' => 'individual', 'label' => 'Individual'], ['value' => 'business', 'label' => 'Business'], ]; $bt = old('business_type'); if ($bt === null || $bt === '') { $bt = $isEdit ? (string) ($lead?->business_type ?? '') : (string) ($selectedCustomerRecord?->business_type ?? ''); } $businessTypeLabels = [ 'Private Company' => 'private_company', 'Closed Corporation' => 'closed_corporation', 'Public Company' => 'public_company', 'Trust' => 'trust', ]; if (isset($businessTypeLabels[$bt])) { $bt = $businessTypeLabels[$bt]; } $businessTypeSelectOptions = [ ['value' => '', 'label' => 'Select…'], ['value' => 'private_company', 'label' => 'Private Company'], ['value' => 'closed_corporation', 'label' => 'Closed Corporation'], ['value' => 'public_company', 'label' => 'Public Company'], ['value' => 'trust', 'label' => 'Trust'], ]; $leadSourceSelectOptions = [['value' => '', 'label' => 'Select Source', 'disabled' => true]]; foreach (\App\Http\Requests\Leads\StoreLeadRequest::leadSourceLabels() as $value => $label) { $leadSourceSelectOptions[] = ['value' => $value, 'label' => $label]; } $leadSourceSelected = (string) ($leadSourceSelected ?? old('lead_source', '')); $statusValue = (string) ($statusValue ?? old('status', 'new')); $statusSelectOptions = collect(\App\Support\LeadStatuses::all()) ->map(fn ($s) => ['value' => $s, 'label' => ucfirst($s)]) ->all(); $salesmanSelectOptions = ($salesmen ?? collect()) ->map(function ($u) { $uName = trim(($u->name ?? '').' '.($u->surname ?? '')); return [ 'value' => (string) $u->id, 'label' => $uName !== '' ? $uName : 'User #'.$u->id, ]; }) ->values() ->all(); $customerLocked = ! $isEdit && filled($customerSelected); $lifecycleStageCreate = old('lifecycle_stage', $lifecycleStageValue ?? 'prospect'); $lifecycleStageFormOptions = [ ['value' => 'prospect', 'label' => 'Prospect'], ['value' => 'lead', 'label' => 'Lead'], ]; $purchaseIntentSelected = $purchaseIntentSelected ?? old('purchase_intent', \App\Support\PurchaseIntent::READY_NOW); $purchaseIntentOptions = [ ['value' => \App\Support\PurchaseIntent::READY_NOW, 'label' => 'Ready now'], ['value' => \App\Support\PurchaseIntent::FUTURE_PURCHASE, 'label' => 'Future purchase'], ]; $futurePurchaseDateValue = $futurePurchaseDateValue ?? old('future_purchase_date', ''); $assignedSelected = (string) ($assignedUserId ?? old('assigned_user_id', ($salesmen->first()->id ?? ''))); @endphp @if ($compact && ! $isEdit) @include('leads.partials.form-body-capture') @else

Lead Details

@if ($isEdit)

Record type: {{ $lead?->isProspect() ? 'Prospect' : 'Active lead' }}

@else

Contact details are filled from the selected customer and cannot be edited here.

@endif

Company information

Representative information

@error('lead_source')

{{ $message }}

@enderror
@if ($isEdit)
@endif
@if (($canAssignLeads ?? false) === true) @if (($salesmen ?? collect())->isNotEmpty()) @else
No Salesman users are available. This lead will be assigned to you automatically.
@endif @elseif ($isEdit)
{{ trim(($lead?->assignedUser?->name ?? '').' '.($lead?->assignedUser?->surname ?? '')) ?: '—' }}
@else
This lead will be assigned to you automatically.
@endif
@unless ($isEdit)
Purchase Intent
@foreach ($purchaseIntentOptions as $option) @endforeach
@unless ($compact)

Future purchase leads are parked automatically with this follow-up date.

@endunless
@endunless
@include('leads.partials.vehicle-interest-fields', ['lead' => $lead, 'compact' => $compact]) @include('leads.partials.communication-preferences-fields', [ 'communicationPreferences' => $communicationPreferences ?? \App\Support\LeadCommunicationPreferences::defaults(), 'compact' => $compact, ])
@endif