@extends('admin.adminLayout') @section('admin_page_title') Upload New Lead Batch @endsection @section('admin_content')
{{-- LEFT: upload / mapping --}}

@if($mapping ?? false) Step 2 – Map Columns @else Step 1 – Upload & Analyze @endif

{{ $mapping ? 'Map your file columns to system fields before importing.' : 'Upload CSV/XLSX and we will detect the columns.' }}
@csrf @if(!$mapping) {{-- STEP 1: upload & analyze --}} {{-- CAMPAIGN CARD --}}
Campaign
{{-- 1) NEW CAMPAIGN NAME ON TOP --}}
Campaign names are unique. Once created, they’ll appear in the list below and be auto-selected.

{{-- 2) EXISTING CAMPAIGNS SELECT (SELECTPICKER) --}}
{{-- NOTES --}}
{{-- FILE UPLOAD --}}

Drop your file here or click to browse.

Accepted formats: .csv, .xlsx, .xls

Expected columns (header row): first_name, last_name, email, phone, country, city, optional: lead_code.
In the next step you can map differently named columns (e.g. Nome → first_name).
Phone is mandatory. Rows without a phone number will be marked as Invalid and skipped.
If you do not map Email, the system will auto-generate a technical email per row based on the campaign name.
Rows with duplicate Email or Phone will be flagged as invalid and skipped. The rest of the file will continue importing.
@else {{-- STEP 2: column mapping --}}

Campaign: {{ $mapping['campaign_name'] }}

We detected the following columns in your file. Please map them to system fields. You can leave optional fields un-mapped.

@php $cols = $mapping['columns'] ?? []; $fields = $mapping['fields'] ?? []; @endphp @if(empty($fields))
No importable fields were found for the leads table. Please check the controller method getLeadImportableFields().
@endif @foreach($fields as $field) @php $fieldKey = $field['key']; // e.g. first_name $fieldLabel = $field['label']; // e.g. First Name $isRequired = $field['mandatory']; $fieldHint = $field['hint'] ?? null; @endphp
@if($fieldHint)
{{ $fieldHint }}
@endif
@endforeach
The primary mapping order is First Name, Last Name, Email, Phone, Country, Call Status. Mandatory fields are marked with * and must be mapped (including Phone, which is required for every lead).
Email is optional. If you leave the Email field unmapped here, the system will automatically generate a unique technical email for each row using the campaign name.
Call Status is optional and maps to the lead's latest contact result.
Rows without a Phone number will be marked as Invalid and skipped. Rows with duplicate Email or Phone will also be flagged as invalid.
« Start over
@endif
Importing leads... Starting
Processed 0
Imported 0
Duplicates 0
Invalid 0
The file is processed in short, committed chunks to avoid server timeouts. Keep this page open. Refreshing the page will resume the same import.
{{-- RIGHT: imported batch & assignment --}}

Imported Leads (Last Batch)

Green rows are OK, red rows are invalid / skipped.
@if($currentBatchId) Batch #{{ $currentBatchId }} @endif
@if(!$currentBatchId)

After importing, the latest batch of leads will appear here. Invalid rows will be highlighted with error messages (e.g. duplicate email/phone, missing mandatory fields).

@else
Only rows with status OK and a created lead can be assigned or updated.
@csrf
# Lead Code Full Name Email Phone Country City Validation Lead Status Assigned To Created
@endif
@endsection @section('script') @endsection @section('style') @endsection