@php // Contact columns a question can be mapped onto. Kept in step with // MetaLeadsController::cleanMap() — that is the list that actually enforces // it; this one only decides what the picker offers. $contactColumns = [ 'name' => __('Full name'), 'first_name' => __('First name'), 'last_name' => __('Last name'), 'mobile' => __('Phone'), 'email' => __('Email'), 'country_code' => __('Country code'), 'title' => __('Job title'), 'address' => __('Address'), 'language' => __('Language'), ]; $statusStyles = [ 'ok' => ['bg-wa-mint text-wa-deep', __('Added')], 'pending' => ['bg-accent-amber/15 text-[#7B5A14]', __('Waiting')], 'failed' => ['bg-accent-coral/12 text-accent-coral', __('Needs attention')], ]; @endphp
{{-- ══════════ Left rail ══════════ --}} {{-- ══════════ Main ══════════ --}}
{{-- Header --}}
{{ __('Facebook') }} / {{ __('Lead ads') }}

{{ __('Instant form') }} {{ __('leads') }}

{{ __('Someone fills in your ad form on Facebook or Instagram. Decide which answer goes into which field, where the deal lands, and who picks it up — it happens automatically from then on.') }}

{{-- KPI strip --}}
@php $cards = [ ['label' => __('Leads captured'), 'value' => $kpis['total'], 'sub' => __('all time')], ['label' => __('Last 7 days'), 'value' => $kpis['week'], 'sub' => __('recent submissions')], ['label' => __('In your pipeline'),'value' => $kpis['ok'], 'sub' => __('contact + deal created')], ['label' => __('Needs attention'), 'value' => $kpis['failed'], 'sub' => __('waiting or failed')], ]; @endphp @foreach ($cards as $c)
{{ $c['label'] }}
{{ number_format($c['value']) }}
{{ $c['sub'] }}
@endforeach
@if ($pages->isEmpty())

{{ __('No Facebook Page connected yet.') }}

{{ __('Connect the Page that runs your lead ads, then come back and sync its forms.') }}

{{ __('Connect a Facebook account') }}
@elseif (! $selected)

{{ __('No lead forms found on your Page.') }}

{{ __('Create an Instant Form on your lead ad in Facebook Ads Manager, then press Sync. Forms already collecting leads show up here with their questions.') }}

@else {{-- ── Form configuration ─────────────────────────────── --}}
@csrf

{{ $selected->name }}

{{ $selected->status }} · {{ $selected->page?->name ?: __('Page') }} @if ($selected->last_synced_at) · {{ __('checked :time', ['time' => $selected->last_synced_at->diffForHumans()]) }} @endif

{{-- Question mapping --}}
{{ __('Where each answer goes') }}

{{ __('Left is what your form asks. Right is where that answer is saved. Anything left unmapped is still kept on the lead itself.') }}

@php $questions = (array) ($selected->questions ?? []); @endphp @if (! $questions)

{{ __('Facebook has not shared this form’s questions yet. Press Sync once the form is live.') }}

@else
@foreach ($questions as $q) @php $qKey = (string) ($q['key'] ?? $q['name'] ?? ''); $qLabel = (string) ($q['label'] ?? $q['name'] ?? $qKey); if ($qKey === '') continue; $rule = (array) (($selected->field_map ?? [])[$qKey] ?? []); $current = ($rule['target'] ?? '') && ($rule['key'] ?? '') ? $rule['target'].':'.$rule['key'] : ''; @endphp @endforeach
{{ $qLabel }}
{{ $qKey }}

{{ __('Map at least the phone or the email — that is how we recognise a returning customer instead of creating them twice.') }}

@endif
{{-- Routing --}}

{{ __('If the same person submits again while their deal is still open, we add it to that deal instead of making a second one.') }}

{{ __('Which board the new deal is added to.') }}

{{ __('Where the deal card first appears.') }}

{{ __('Sharing out in turn rotates through the team so nobody gets every lead.') }}

{{ __('Used when leads are shared out in turn.') }}

{{ __('An automatic welcome message the moment the lead arrives.') }}

@forelse ($tags as $tg) @empty

{{ __('No tags created yet.') }}

@endforelse
{{-- ── Leads ──────────────────────────────────────────── --}}

{{ __('Leads') }}

{{ $selected->name }}

@if ($leads->isEmpty())

{{ __('No leads yet for this form.') }}

{{ __('They appear here within seconds of someone submitting your ad form.') }}

@else
@foreach ($leads as $lead) @php $answers = $lead->answers(); [$pill, $pillLabel] = $statusStyles[$lead->ingest_status] ?? $statusStyles['pending']; @endphp @endforeach
{{ __('Person') }} {{ __('Answers') }} {{ __('Came from') }} {{ __('When') }} {{ __('Status') }}
@if ($lead->contact?->id) {{ $lead->contact->name ?: __('Contact') }} @else {{ $answers['full_name'] ?? ($answers['first_name'] ?? __('Unknown')) }} @endif @if ($lead->deal?->id)
{{ __('deal #:id', ['id' => $lead->deal->id]) }}
@endif
@foreach (array_slice($answers, 0, 3, true) as $k => $v)
{{ str_replace('_', ' ', $k) }}: {{ $v }}
@endforeach @if (count($answers) > 3)
{{ __('+:n more', ['n' => count($answers) - 3]) }}
@endif
{{ $lead->campaign_name ?: ($lead->is_organic ? __('Organic') : __('Unknown campaign')) }}
@if ($lead->platform)
{{ $lead->platform === 'ig' ? 'instagram' : 'facebook' }}
@endif
{{ $lead->submitted_at?->diffForHumans() ?: '—' }} {{ $pillLabel }} @if ($lead->ingest_status !== 'ok')
@if ($lead->ingest_error)
{{ $lead->ingest_error }}
@endif @endif
@if ($leads->hasPages())
{{ $leads->links() }}
@endif @endif
@endif