@extends('layouts.admin.app')

@section('content')

    <main id="main" class="main">
        <div class="container" style="margin-top:5%;">
            <h3>AGENT : {{$agents->name}}</h3>
            <table class="table">
                @if($agent_assinged->isEmpty())
                    No Data Found
                @else    
                    <thead>
                        <tr>
                            <th scope="col">Sr no</th>
                            <th scope="col">Order Id</th>
                            <th scope="col">Product Name</th>
                            <th scope="col">Total Price</th>
                            <th scope="col">Assign Date</th>
                            <th scope="col">Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        @php $i = 0; $total=0;@endphp
                        @foreach($agent_assinged as $agent_assingeds)
                            @if($agent_assingeds->status == "D")
                                @php $i++; @endphp
                                <tr>
                                    <th scope="row">{{$i++}}</th>
                                    <td>{{$agent_assingeds->agent_order_id}}</td>
                                    <td>
                                        @php
                                            $printedProducts = [];
                                        @endphp
                                        @foreach($assigned_agent_product_map as $product_mapeds)
                                            @if($product_mapeds->agent_assinged_id == $agent_assingeds->id)
                                                @foreach($agent_product_list as $product)
                                                    @if($product->id == $product_mapeds->product_id && !in_array($product->id, $printedProducts))
                                                        {{ $product->item }}<br>
                                                        @php
                                                            $printedProducts[] = $product->id; 
                                                        @endphp
                                                    @endif
                                                @endforeach
                                            @endif
                                        @endforeach
                                    </td>
                                    <td>
                                        {{$agent_assingeds->totalPrice}}
                                        @php $total +=$agent_assingeds->totalPrice; @endphp
                                    </td>
                                    <td>
                                        {{$agent_assingeds->created_at}}
                                    </td>
                                    <td>
                                        DELIVERED
                                    </td>
                                </tr>
                            @endif
                        @endforeach
                    </tbody>
                    <table>
                        <tbody>
                            <tr>
                                <td><b>TOTAL PAYMENTS :</b></td>
                                <td>{{$total}}</td>
                            </tr>
                        </tbody>
                    </table>
                @endif    
            </table>
            <a class="btn btn-danger" href="{{url('/admin/order/report')}}">Back</a>
        </div>
    </main>

@endsection