@extends('layouts.app')
@section('title', 'Lead Conversion Review')
@section('content')
<div class="main-content">
    <div class="card">
        <div class="card-header"><h5 class="card-title">Convert Qualified Lead to Deal</h5></div>
        <div class="card-body">
            <div class="alert alert-info">Review the Lead and possible duplicate Deals before continuing.</div>
            <dl class="row">
                <dt class="col-md-3">Lead</dt><dd class="col-md-9">{{ $lead->topic }}</dd>
                <dt class="col-md-3">Contact</dt><dd class="col-md-9">{{ trim($lead->first_name.' '.$lead->last_name) }}</dd>
                <dt class="col-md-3">Email</dt><dd class="col-md-9">{{ $lead->contactEmails->pluck('email')->join(', ') ?: '—' }}</dd>
                <dt class="col-md-3">Phone</dt><dd class="col-md-9">{{ $lead->contactPhones->pluck('phone')->join(', ') ?: '—' }}</dd>
                <dt class="col-md-3">Last interaction</dt><dd class="col-md-9">{{ $lead->activities()->latest('start_date')->first()?->start_date ?: 'None' }}</dd>
            </dl>
            <h6 class="fw-bold mt-4">Possible duplicate Deals</h6>
            @forelse ($duplicateDeals as $deal)
                <div class="border rounded p-3 mb-2">
                    <a href="{{ route('deals.view', ['id' => $deal->id]) }}">{{ $deal->name ?: 'Deal #'.$deal->id }}</a>
                    <span class="text-muted ms-2">{{ number_format((float) ($deal->grand_total ?: $deal->estimate_amount), 2) }}</span>
                </div>
            @empty
                <p class="text-muted">No matching Deals were detected.</p>
            @endforelse
            <div class="d-flex gap-2 mt-4">
                <a class="btn btn-light" href="{{ route('leads.view', ['id' => $lead->id]) }}">Back</a>
                <a class="btn btn-primary" href="{{ route('deals-create', ['leadId' => $lead->id, 'guidedConversion' => 1]) }}">
                    Continue to Deal creation
                </a>
            </div>
        </div>
    </div>
</div>
@endsection
