@extends('layout.app')

@section('content')
<div class="container-fluid">
    <div class="card">
        <div class="card-header">
            <h3 class="card-title">New Join Summary Report (by Employee)</h3>
            <div class="card-tools">
                <span class="text-muted">From {{ $from_date }} to {{ $to_date }}</span>
                <button type="button" class="btn btn-sm btn-primary ml-2 noprint" onclick="window.print()">
                    <i class="fa fa-print"></i> Print
                </button>
                <a href="{{ route('newJoinSummaryReport') . '?' . http_build_query(array_merge(request()->query(), ['download' => 'excel'])) }}" class="btn btn-sm btn-success ml-2 noprint">
                    <i class="fa fa-file-excel-o"></i> Download Excel
                </a>
                <a href="{{ route('list', 'new-join') }}" class="btn btn-sm btn-secondary ml-1 noprint">
                    <i class="fa fa-arrow-left"></i> Back to List
                </a>
            </div>
        </div>
        <div class="card-body">
            <table class="table table-bordered table-striped">
                <thead>
                    <tr style="background:#78716C !important; color:white;">
                        <th>#</th>
                        <th>Employee</th>
                        <th>Total User</th>
                    </tr>
                </thead>
                <tbody>
                    @php $sr = 1; $grandTotal = 0; @endphp
                    @foreach ($summary as $row)
                        @php
                            $employeeName = $row->marketing_employee_id
                                ? ($employees[$row->marketing_employee_id] ?? 'Employee #' . $row->marketing_employee_id)
                                : 'No employee';
                            $grandTotal += $row->total;
                        @endphp
                        <tr>
                            <td>{{ $sr++ }}</td>
                            <td>{{ $employeeName }}</td>
                            <td>{{ $row->total }}</td>
                        </tr>
                    @endforeach
                </tbody>
                <tfoot>
                    <tr class="font-weight-bold">
                        <td colspan="2" class="text-right">Total</td>
                        <td>{{ $grandTotal }}</td>
                    </tr>
                </tfoot>
            </table>
            @if ($summary->isEmpty())
                <p class="text-muted mb-0">No records found for the selected date range and filters.</p>
            @endif
        </div>
    </div>
</div>
@endsection
