<x-user.layout title="{{ auth()->user()->lastname.' '.auth()->user()->firstname }} | My Loan Applications">

    <div class="nk-block">
        <div class="row g-gs">
            <div class="col-12">
                <div class="card h-100">

                    <div class="card-inner card-title-group card-title border-bottom d-flex justify-content-between">
                        <div><h6 class="title">My Loan/Mortage</h6></div>
                        <div><a href="{{ route('user.apply-loan') }}" class="btn btn-primary btn-sm" > Apply</a></div>
                    </div>

                    <div class="card-inner">
                        @if(count($loans) > 0)
                            <div class="table-responsive scroll pb-4">
                                <table class="loan-table nowrap nk-tb-list is-separate" data-auto-responsive="false">
                                    <thead>
                                        <tr class="nk-tb-item nk-tb-head">
                                            <th class="nk-tb-col"><span>ID</span></th>
                                            <th class="nk-tb-col"><span>Amount</span></th>
                                            <th class="nk-tb-col"><span>Date/Time</span></th>
                                            <th class="nk-tb-col"><span>Status</span></th>
                                        </tr><!-- .nk-tb-item -->
                                    </thead>
                                    <tbody>
                                        @foreach($loans as $loan)
                                            <tr class="nk-tb-item">
                                                <td class="nk-tb-col">
                                                    <span class="tb-sub">LN{{ $loan->loan_id }}</span>
                                                </td>
                                                <td class="nk-tb-col">
                                                    <span class="tb-lead">{{ getUserCurrency().$loan->amount }}</span>
                                                </td>
                                                <td class="nk-tb-col">
                                                    <span class="tb-sub">{{ $loan->created_at->format('Y-m-d h:i A') }}</span>
                                                </td>
                                                <td class="nk-tb-col">
                                                    @if($loan->status == APPROVED_LOAN)
                                                        <span class="tb-sub"><span class="badge badge-pill badge-success">Approved</span></span>
                                                    @elseif($loan->status == PENDING_LOAN)
                                                        <span class="tb-sub"><span class="badge badge-pill badge-warning">Pending</span></span>
                                                    @else
                                                        <span class="tb-sub"><span class="badge badge-pill badge-danger">Declined</span></span>
                                                    @endif
                                                </td>
                                            </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        @else
                            <p class="text-info">No loan application at the moment. <a href="{{ route('user.apply-loan') }}">Apply for loan here</a></p>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>

</x-user.layout>
