{{-- Flash messages --}} @if(session('success'))
{{ session('success') }}
@if($lastMergeAuditId) @endif
@endif @if(session('error'))
{{ session('error') }}
@endif {{-- Page header --}}

{{ __('Combine Duplicate Contacts') }}

{{ __('Find and merge duplicate contacts in your workspace') }}

@if($mergedCount > 0) {{ $mergedCount }} {{ __('merged this session') }} @endif
{{-- Scan stats --}} @if(!empty($duplicateGroups) || $scannedContactCount > 0)
@if($scannedContactCount > 0)
{{ number_format($scannedContactCount) }} {{ __('contacts scanned') }}
@endif
{{ count($duplicateGroups) }} {{ __('duplicate group(s) found') }}
@php $totalDupeContacts = collect($duplicateGroups)->sum(fn ($g) => count($g['contacts'])); @endphp {{ number_format($totalDupeContacts) }} {{ __('contacts involved') }}
@endif {{-- Main content --}} @if(empty($duplicateGroups) && $scannedContactCount === 0) {{-- Initial state: no scan run yet --}}

{{ __('Find Duplicate Contacts') }}

{{ __('Scan your workspace for contacts that share the same email address or have matching names and companies. Review and merge them to keep your CRM clean.') }}

@elseif(empty($duplicateGroups) && $scannedContactCount > 0) {{-- No duplicates found --}}

{{ __('No Duplicates Found') }}

{{ __('Your contact list looks clean. No duplicate contacts were detected based on email address or name + company matching.') }}

@else {{-- Split view: groups list + comparison --}}
{{-- Left: Duplicate groups list --}}

{{ __('Duplicate Groups') }}

@foreach($duplicateGroups as $index => $group)
{{-- Show the match value as the group title --}}

{{ $group['match_value'] }}

@if($group['match_type'] === 'email') {{ __('Email') }} @else {{ __('Name') }} @endif {{ count($group['contacts']) }} {{ __('contacts') }}
@endforeach
{{-- Right: Comparison view --}}
@if($selectedGroupIndex !== null && !empty($selectedGroupContacts))

{{ __('Compare & Merge') }}

{{ __('Select the primary contact to keep') }}
{{-- Contact comparison cards --}}
@foreach($selectedGroupContacts as $contact) @php $isPrimary = $primaryContactId === $contact['id']; @endphp
{{-- Card header --}}
@if($isPrimary) {{ __('Master') }} @endif
{{ strtoupper(substr($contact['first_name'] ?? '', 0, 1)) }}{{ strtoupper(substr($contact['last_name'] ?? '', 0, 1)) }}

{{ $contact['full_name'] }}

{{ $contact['email'] ?? __('No email') }}

{{-- Field comparison --}}
@php $fields = [ 'phone' => __('Phone'), 'company' => __('Company'), 'job_title' => __('Job Title'), 'city' => __('City'), 'country' => __('Country'), 'timezone' => __('Timezone'), 'lead_score' => __('Engagement Score'), 'status' => __('Status'), ]; // Compute which fields differ across the group. $diffFields = []; foreach ($fields as $fKey => $fLabel) { $values = collect($selectedGroupContacts)->pluck($fKey)->unique()->filter(fn($v) => $v !== null && $v !== '')->values(); if ($values->count() > 1) { $diffFields[] = $fKey; } } @endphp @foreach($fields as $fieldKey => $fieldLabel) @php $isDiff = in_array($fieldKey, $diffFields); $value = $contact[$fieldKey] ?? null; @endphp
{{ $fieldLabel }} {{ $value !== null && $value !== '' ? $value : __('Empty') }} @if($isDiff && $value) @endif
@endforeach {{-- Tags --}}
{{ __('Tags') }}
@forelse($contact['tags'] as $tagName) {{ $tagName }} @empty {{ __('None') }} @endforelse
{{-- Relations count --}}
{{ __('Relations') }}
{{ $contact['conversations_count'] }} {{ __('conversation(s)') }}, {{ $contact['deals_count'] }} {{ __('deal(s)') }}
{{-- Created date --}}
{{ __('Created') }} {{ $contact['created_at'] ? \Carbon\Carbon::parse($contact['created_at'])->format('M j, Y') : __('Unknown') }}
@endforeach
{{-- Merge explanation --}}

{{ __('What happens when you merge:') }}

  • {{ __('All conversations and deals move to the primary contact') }}
  • {{ __('Tags from all contacts are combined') }}
  • {{ __('Empty fields on primary are filled from secondary data') }}
  • {{ __('Lead score is set to the highest value') }}
  • {{ __('Secondary contacts are soft-deleted (recoverable)') }}
{{-- Action buttons --}}
@else {{-- No group selected --}}

{{ __('Select a duplicate group from the left to compare and merge contacts') }}

@endif
@endif