@extends('layouts.app')

@section('title', 'Customers')
@section('heading', 'Customers')

@section('content')
    <div class="flex-between mb-1">
        <form method="GET" class="flex gap" style="align-items:flex-end">
            <div class="form-group mb-0">
                <label for="q">Search</label>
                <input id="q" class="form-control" name="q" value="{{ request('q') }}">
            </div>
            <button type="submit" class="btn btn-ghost btn-sm">Search</button>
        </form>
    </div>
    <div class="table-wrap">
        <table class="data-table">
            <thead>
            <tr><th>Name</th><th>Email</th><th>Lead</th><th>Lifetime value</th><th></th></tr>
            </thead>
            <tbody>
            @forelse ($customers as $c)
                <tr>
                    <td><a href="{{ route('customers.show', $c) }}">{{ $c->name }}</a></td>
                    <td>{{ $c->email ?? '—' }}</td>
                    <td>@if ($c->lead)<a href="{{ route('leads.show', $c->lead) }}">#{{ $c->lead_id }}</a>@else — @endif</td>
                    <td>@if ($c->lifetime_value !== null) {{ number_format($c->lifetime_value, 2) }} @else — @endif</td>
                    <td><a href="{{ route('customers.show', $c) }}" class="btn btn-ghost btn-sm">Open</a></td>
                </tr>
            @empty
                <tr><td colspan="5">No customers yet.</td></tr>
            @endforelse
            </tbody>
        </table>
    </div>
    @include('partials.pagination', ['paginator' => $customers])
@endsection
