@extends('layouts.admin')
@section('title', 'Loan Details')

@section('content')

<style>

.details-card{
    border-top:6px solid #104042;
}

.details-label{
    color:#6c757d;
    font-size:13px;
    margin-bottom:4px;
}

.details-value{
    font-weight:600;
    word-break:break-word;
}

.section-title{
    border-bottom:1px solid #dee2e6;
    padding-bottom:10px;
    margin-bottom:25px;
    font-weight:600;
}

.back-btn{
    text-decoration:none;
    color:#000;
}

.back-btn:hover{
    color:#104042;
}

.status-btn{
    min-width:120px;
}

</style>

<section class="container py-3">

    <div class="row g-3">

        <!-- SIDEBAR -->

        <div class="col-md-3 d-none d-md-block">

            <div class="row">

                <div class="col-12">

                    <h4 class="fw-bold mb-3">

                        Admin Dashboard

                    </h4>

                </div>

            </div>

            <div class="sidebar">

                <a href="{{ route('admin.dashboard') }}">

                    <i class="fa fa-chart-line"></i>

                    Dashboard

                </a>

                <a href="{{ route('admin.dashboard') }}#users-tab"
                   class="active">

                    <i class="fa fa-users"></i>

                    Users

                </a>
                
                <form method="POST"
                      action="{{ route('admin.logout') }}">

                    @csrf

                    <button class="btn btn-primary-custom w-100 mt-3">

                        Logout

                    </button>

                </form>

            </div>

        </div>

        <!-- CONTENT -->

        <div class="col-md-9">

            <!-- HEADER -->

            <div class="d-flex justify-content-between align-items-center mb-3">

    <a href="{{ url('admin/user-loans/' . $loanApplication->user_id) }}"
       class="back-btn fw-semibold">

        <h4>
            <i class="fa-solid fa-arrow-left-long me-2"></i>
            Loan Application Details
        </h4>

    </a>

</div>

            <!-- STATUS UPDATE -->
 @if($loanApplication->status == "completed")
            <div class="row g-2 g-md-3 mb-3">
                
              

    <div class="col-4">
        <form method="POST"
              action="{{ route('admin.loan.status.update', $loanApplication->id) }}">
            @csrf

            <input type="hidden" name="status" value="approved">

            <button class="card-custom border-0 w-100 px-2 py-3 p-md-4 text-center bg-success text-white">
                <div class="fw-semibold">Approve</div>
            </button>
        </form>
    </div>

    <div class="col-4">
        <form method="POST"
              action="{{ route('admin.loan.status.update', $loanApplication->id) }}">
            @csrf

            <input type="hidden" name="status" value="rejected">

            <button class="card-custom border-0 w-100 px-2 py-3 p-md-4 text-center bg-danger text-white">
                <div class="fw-semibold">Reject</div>
            </button>
        </form>
    </div>

    <div class="col-4">
        <form method="POST"
              action="{{ route('admin.loan.status.update', $loanApplication->id) }}">
            @csrf

            <input type="hidden" name="status" value="completed">

            <button class="card-custom border-0 w-100 px-2 py-3 p-md-4 text-center bg-dark text-white">
                <div class="fw-semibold">Completed</div>
            </button>
        </form>
    </div>

</div>
@endif

            <!-- CARD -->

            <div class="card-custom p-4 details-card">

                <!-- PERSONAL -->

                 <!-- PERSONAL -->
                <div class="preview-section mb-5">

                    <h5 class="section-title">
                        Personal Information
                    </h5>

                    <div class="row g-3">

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Full Name</div>
                            <div class="details-value">
                                {{ $loanApplication->full_name ?? 'N/A' }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Date of Birth</div>
                            <div class="details-value">
                                {{ $loanApplication->dob ? \Carbon\Carbon::parse($loanApplication->dob)->format('m-d-Y') : 'N/A' }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Gender</div>
                            <div class="details-value">
                                {{ $loanApplication->gender ?? 'N/A' }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Marital Status</div>
                            <div class="details-value">
                                {{ $loanApplication->marital_status ?? 'N/A' }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Father Name</div>
                            <div class="details-value">
                                {{ $loanApplication->father_name ?? 'N/A' }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">PAN Number</div>
                            <div class="details-value">
                                {{ $loanApplication->pan_number ?? 'N/A' }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Aadhaar Number</div>
                            <div class="details-value">
                                {{ $loanApplication->aadhaar_number ?? 'N/A' }}
                            </div>
                        </div>

                    </div>

                </div>

                <!-- ADDRESS -->
                <div class="preview-section mb-5">

                    <h5 class="section-title">
                        Address Details
                    </h5>

                    <div class="row g-3">

                        <div class="col-12 col-lg-6">
                            <div class="details-label">Current Address</div>

                             <div>
                                <strong>Address :</strong>
                                <span >{{ $loanApplication->current_address ?? 'N/A' }}</span>
                            </div>
                            
                            <div>
                                <strong>City :</strong>
                                <span >{{ $loanApplication->current_city ?? 'N/A' }}</span>
                            </div>
                
                
                            <div>
                                <strong>State :</strong>
                                <span >{{ $loanApplication->current_state ?? 'N/A' }}</span>
                            </div>
                                        <div>
                                <strong>Country :</strong>
                                <span >{{ $loanApplication->current_country ?? 'N/A' }}</span>
                            </div>
                            
                        </div>

                        <div class="col-12 col-lg-6">
                            <div class="details-label">Permanent Address</div>

                             <div>
                                <strong>Address :</strong>
                                <span >{{ $loanApplication->permanent_address ?? 'N/A' }}</span>
                            </div>
                            
                            <div>
                                <strong>City :</strong>
                                <span >{{ $loanApplication->permanent_city ?? 'N/A' }}</span>
                            </div>
                
                
                            <div>
                                <strong>State :</strong>
                                <span >{{ $loanApplication->permanent_state ?? 'N/A' }}</span>
                            </div>
                                        <div>
                                <strong>Country :</strong>
                                <span >{{ $loanApplication->permanent_country ?? 'N/A' }}</span>
                            </div>
                        </div>

                    </div>

                </div>

                <!-- LOAN -->
                <div class="preview-section mb-5">

                    <h5 class="section-title">
                        Loan Details
                    </h5>

                    <div class="row g-3">

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Loan Type</div>
                            <div class="details-value">
                                {{ $loanApplication->loan_type ?? 'N/A' }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Purpose</div>
                            <div class="details-value">
                                {{ $loanApplication->purpose_of_loan ?? 'N/A' }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Loan Amount</div>
                            <div class="details-value">
                                ₹ {{ number_format((float)($loanApplication->loan_amount ?? 0)) }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Loan Tenure</div>
                            <div class="details-value">
                                {{ $loanApplication->loan_tenure ?? 0 }} Months
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Preferred EMI</div>
                            <div class="details-value">
                                ₹ {{ number_format((float)($loanApplication->preferred_emi ?? 0)) }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Total Interest</div>
                            <div class="details-value">
                                ₹ {{ number_format((float)($loanApplication->total_interest ?? 0)) }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Processing Charges</div>
                            <div class="details-value">
                                ₹ {{ number_format((float)($loanApplication->processing_charges ?? 0)) }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Total Payment</div>
                            <div class="details-value">
                                ₹ {{ number_format((float)($loanApplication->total_payment ?? 0)) }}
                            </div>
                        </div>

                    </div>

                </div>

                <!-- FINANCIAL -->
                <div class="preview-section mb-5">

                    <h5 class="section-title">
                        Financial Details
                    </h5>

                    <div class="row g-3">

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Monthly Income</div>
                            <div class="details-value">
                                ₹ {{ number_format((float)($loanApplication->monthly_income ?? 0)) }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Annual Income</div>
                            <div class="details-value">
                                ₹ {{ number_format((float)($loanApplication->annual_income ?? 0)) }}
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-lg-4">
                            <div class="details-label">Employment Type</div>
                            <div class="details-value">
                                {{ $loanApplication->employment_type ?? 'N/A' }}
                            </div>
                        </div>

                    </div>

                </div>

                <!-- DOCUMENTS -->
                <div class="preview-section">

                    <h5 class="section-title">
                        Documents
                    </h5>

                    <div class="row g-2 g-md-3">

                        @if($loanApplication->id_proof)
                            <div class="col-6 col-sm-6 col-lg-4">
                                <a href="{{ asset('storage/' . $loanApplication->id_proof) }}"
                                   target="_blank"
                                   class="btn btn-primary-custom w-100">
                                   View ID Proof
                                </a>
                            </div>
                        @endif

                        @if($loanApplication->address_proof)
                            <div class="col-6 col-sm-6 col-lg-4">
                                <a href="{{ asset('storage/' . $loanApplication->address_proof) }}"
                                   target="_blank"
                                   class="btn btn-primary-custom w-100">
                                    View Address Proof
                                </a>
                            </div>
                        @endif

                        @if($loanApplication->income_proof)
                            <div class="col-6 col-sm-6 col-lg-4">
                                <a href="{{ asset('storage/' . $loanApplication->income_proof) }}"
                                   target="_blank"
                                   class="btn btn-primary-custom w-100">
                                    View Income Proof
                                </a>
                            </div>
                        @endif

                    </div>

                </div>

            </div>

        </div>

    </div>

</section>

@endsection