@extends('master_header')

@section('content')

    @include('includes.header-topbar')

   <!-- ========== App Menu ========== -->
    @include('md.sidebar-menu')
    <!-- Left Sidebar End -->
    <!-- Vertical Overlay-->
    <div class="vertical-overlay"></div>

    <!-- ============================================================== -->
    <!-- Start right Content here -->
    <!-- ============================================================== -->
    <div class="main-content">

        <div class="page-content">
            <div class="container-fluid">

                <!-- start page title -->
                <div class="row">
                    <div class="col-12">
                        <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                            <h4 class="mb-sm-0">Agents</h4>

                            <div class="page-title-right">
                                <ol class="breadcrumb m-0">
                                    <li class="breadcrumb-item"><a href="javascript: void(0);">Dashboard</a></li>
                                    <li class="breadcrumb-item active">Agents</li>
                                </ol>
                            </div>

                        </div>
                    </div>
                </div>
                <!-- end page title -->

                <div class="row">
                    <div class="col-xxl-3 col-md-6">
                        <div class="card card-animate">
                            <div class="card-body">
                                <div class="d-flex mb-3">
                                    <div class="flex-grow-1">
                                        <lord-icon src="https://cdn.lordicon.com/fhtaantg.json" trigger="loop" colors="primary:#405189,secondary:#0ab39c" style="width:55px;height:55px"></lord-icon>
                                    </div>

                                </div>
                                <h3 class="mb-2">₦<span class="counter-value" data-target="{{$amount_paid}}">0</span><small class="text-muted fs-13"></small></h3>
                                <h6 class="text-muted mb-0">Amount Paid</h6>
                            </div>
                        </div>
                        <!--end card-->
                    </div>
                    <!--end col-->
                    <div class="col-xxl-3 col-md-6">
                        <div class="card card-animate">
                            <div class="card-body">
                                <div class="d-flex mb-3">
                                    <div class="flex-grow-1">
                                        <lord-icon src="https://cdn.lordicon.com/qhviklyi.json" trigger="loop" colors="primary:#405189,secondary:#0ab39c" style="width:55px;height:55px"></lord-icon>
                                    </div>
                                </div>
                                <h3 class="mb-2">₦<span class="counter-value" data-target="{{$amount_unpaid}}">0</span><small class="text-muted fs-13"></small></h3>
                                <h6 class="text-muted mb-0">Amount Unpaid</h6>
                            </div>
                        </div>
                        <!--end card-->
                    </div>
                    <!--end col-->
                </div>
                <!--end row-->

                {{--<div class="row align-items-center mb-4 g-3">
                    <!--end col-->
                    <div class="col-sm-auto ms-auto">
                        <div class="d-flex gap-2">
                            <a href="javascript:void(0);" class="btn btn-info">Deposit</a>
                            <a href="javascript:void(0);" class="btn btn-danger">Withdraw</a>
                        </div>
                    </div>
                    <!--end col-->
                </div>--}}
                <!--end row-->

                <div class="card" id="contactList">
                    <div class="card-header">
                        <div class="row align-items-center g-3">
                            <div class="col-md-3">
                                <h5 class="card-title mb-0">All Transactions</h5>
                            </div>
                            <!--end col-->
                            <div class="col-md-auto ms-auto">
                                <div class="d-flex gap-2">
                                    <div class="search-box">
                                        <input type="text" class="form-control search" placeholder="Search for transactions...">
                                        <i class="ri-search-line search-icon"></i>
                                    </div>
                                    <button class="btn btn-success"><i class="ri-equalizer-line align-bottom me-1"></i> Filters</button>
                                </div>
                            </div>
                            <!--end col-->
                        </div>
                        <!--end row-->
                    </div>
                    <!--end card-header-->
                    <div class="card-body">
                        <div class="table-responsive table-card">
                            <table class="table align-middle table-nowrap" id="customerTable">
                                <thead class="table-light text-muted">
                                <tr>
                                    <th class="sort" data-sort="date" scope="col">Agent</th>
                                    <th class="sort" data-sort="date" scope="col">TIN</th>
                                    <th class="sort" data-sort="currency_name" scope="col">Customer</th>
                                    <th class="sort" data-sort="form_name" scope="col">Project</th>
                                    <th class="sort" data-sort="to_name" scope="col">House Type</th>
                                    <th class="sort" data-sort="amount" scope="col">Amount</th>
                                    <th class="sort" data-sort="amount" scope="col">Customer Percentage <br> Paid</th>
                                    <th class="sort" data-sort="amount" scope="col">Agent Percentage <br> Paid</th>
                                    <th class="sort" data-sort="status" scope="col">Status</th>
                                    <th class="sort" data-sort="status" scope="col">Action</th>
                                </tr>
                                <!--end tr-->
                                </thead>
                                <tbody class="list form-check-all">
                                @foreach($agents as $agent)
                                <tr>
                                    <td class="id" style="display:none;"><a href="javascript:void(0);" class="fw-medium link-primary">#VZ001</a></td>
                                    <td class="currency_name">
                                        {{$agent->agent_name}}
                                    </td>
                                    <td class="currency_name">
                                      {{$agent->tin}}
                                  </td>
                                    <td class="form_name">{{$agent->customer_name}}</td>
                                    <td class="to_name">{{$agent->project}}</td>
                                    <td class="type">{{$agent->house_type}}</td>
                                    <td>
                                        <h6 class="text-danger mb-1 amount">₦ -{{number_format($agent->amount_paid ?? 0)}}</h6>
                                        <p class="text-muted mb-0">₦ {{number_format($agent->amount)}}</p>
                                    </td>
                                    <td class="to_name"> {{number_format($agent->percentage_paid, 0)}} % </td>
                                    <td class="to_name"> 0 % </td>
                                    <td class="status">
                                        <span class="badge bg-warning-subtle text-warning fs-11"><i class="ri-time-line align-bottom"></i> Processing</span>
                                    </td>

                                    <td>
                                        <div class="dropdown">
                                            <a href="javascript:void(0);" class="btn btn-light btn-icon" id="dropdownMenuLink15" data-bs-toggle="dropdown" aria-expanded="false">
                                                <i class="ri-equalizer-fill"></i>
                                            </a>
                                            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuLink15" style="">

                                                    <li>
                                                        <button type="submit" class="dropdown-item">
                                                            <i class="ri-download-2-fill me-2 align-middle text-muted"></i>
                                                            <a href="{{ route('md-view-agent-details',$agent->id) }}" class="btn btn-blue rounded-pill waves-effect waves-light">View</a>
                                                        </button>
                                                    </li>

                                                <li class="dropdown-divider"></li>

                                                @if(($agent->percentage_paid > 29) || ($agent->percentage_paid < 60))
                                                <form id="initiateOfferForm" method="post" action="{{ route('view-application') }}">
                                                    @csrf
                                                    <input type="hidden" name="id" value="">
                                                    <li>
                                                        <button type="submit" class="dropdown-item">
                                                            <i class="ri-download-2-fill me-2 align-middle text-muted"></i>
                                                            Pay 1st Payment
                                                        </button>
                                                    </li>
                                                </form>
                                                @endif
                                                @if(($agent->percentage_paid > 60) ||  ($agent->percentage_paid < 80))
                                                <form id="initiateOfferForm" method="post" action="{{ route('view-application') }}">
                                                    @csrf
                                                    <input type="hidden" name="id" value="">
                                                    <li>
                                                        <button type="submit" class="dropdown-item">
                                                            <i class="ri-download-2-fill me-2 align-middle text-muted"></i>
                                                            Pay 2nd Payment
                                                        </button>
                                                    </li>
                                                </form>
                                                @endif
                                                @if($agent->percentage_paid > 99)
                                                <form id="initiateOfferForm" method="post" action="{{ route('view-application') }}">
                                                    @csrf
                                                    <input type="hidden" name="id" value="">
                                                    <li>
                                                        <button type="submit" class="dropdown-item">
                                                            <i class="ri-download-2-fill me-2 align-middle text-muted"></i>
                                                            Pay 3rd Payment
                                                        </button>
                                                    </li>
                                                </form>
                                                @endif
                                                @if($agent->percentage_paid == 100)
                                                <form id="initiateOfferForm" method="post" action="{{ route('view-application') }}">
                                                    @csrf
                                                    <input type="hidden" name="id" value="">
                                                    <li>
                                                        <button type="submit" class="dropdown-item">
                                                            <i class="ri-download-2-fill me-2 align-middle text-muted"></i>
                                                            Final Payment
                                                        </button>
                                                    </li>
                                                </form>
                                                @endif
                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                                @endforeach
                                <!--end tr-->
                                </tbody>
                            </table>
                            <!--end table-->
                            <div class="noresult" style="display: none">
                                <div class="text-center">
                                    <lord-icon src="https://cdn.lordicon.com/msoeawqm.json" trigger="loop" colors="primary:#405189,secondary:#0ab39c" style="width:75px;height:75px"></lord-icon>
                                    <h5 class="mt-2">Sorry! No Result Found</h5>
                                    <p class="text-muted mb-0">We've searched more than 150+ transactions We did not find any transactions for you search.</p>
                                </div>
                            </div>
                        </div>
                        <div class="d-flex justify-content-end mt-3">
                            <div class="pagination-wrap hstack gap-2">
                                <a class="page-item pagination-prev disabled" href="#">
                                    Previous
                                </a>
                                <ul class="pagination listjs-pagination mb-0"></ul>
                                <a class="page-item pagination-next" href="#">
                                    Next
                                </a>
                            </div>
                        </div>
                    </div>
                    <!--end card-body-->
                </div>
                <!--end card-->

            </div>
            <!-- container-fluid -->
        </div>
        <!-- End Page-content -->

        <footer class="footer">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-6">
                        <script>document.write(new Date().getFullYear())</script> © Velzon.
                    </div>
                    <div class="col-sm-6">
                        <div class="text-sm-end d-none d-sm-block">
                            Design & Develop by Themesbrand
                        </div>
                    </div>
                </div>
            </div>
        </footer>
    </div>
    <!-- end main content-->

</div>
<!-- END layout-wrapper -->
@endsection
