@include('admin.layouts.header')
@include('admin.layouts.sidebar')
<div class="m-grid__item m-grid__item--fluid m-wrapper">
    <div class="m-subheader ">
        <div class="d-flex align-items-center">
            <div class="mr-auto">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    Direct Assignment
                </h3>
            </div>
        </div>
    </div>
    <div class="m-content">
        @if(Session::has('success'))
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
                {{ Session::get('success') }}
            </div>
        @endif
        @if(Session::has('error'))
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
                {{ Session::get('error') }}
            </div>
        @endif

        {{-- Upload Section --}}
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__head">
                <div class="m-portlet__head-caption">
                    <div class="m-portlet__head-title">
                        <span class="m-portlet__head-icon">
                            <i class="fa fa-file-excel-o"></i>
                        </span>
                        <h3 class="m-portlet__head-text">
                            Loans Upload
                        </h3>
                    </div>
                </div>
                <div class="m-portlet__head-tools" style="padding-right: 13px;">
                    
                </div>
            </div>
            <div class="m-portlet__body">
                <div class="m-section">
                    <div class="m-section__content">
                        <div class="col-md-12">
                            <div class="row" style="color:red;">* Please remove extra headers &amp; footers from file before processing</div>
                            <div class="row" style="font-weight: 500;">[Supported file - xls, xlsx] &nbsp;&nbsp;<span style="font-weight: 500;">[<a href="/assets/blacksoil_da_los_data_format.xlsx" download>Download Sample File</a>]</span></div>
                            <form id="da_system_upload_form" class="form-horizontal" action="/admin/da-system/import" method="POST" enctype="multipart/form-data">
                                <input name="_token" value="{!! csrf_token() !!}" type="hidden">
                                <div class="row" style="padding-bottom: 10px; margin-left: -32px; padding-top: 10px;">
                                    <div class="col-md-3">
                                        <input type="file" name="file" id="file" class="form-control" autocomplete="off" required="required" accept=".xls,.xlsx">
                                    </div>
                                    <div class="col-md-6" style="padding-top: 2px;">
                                        <input type="submit" class="btn btn-accent" value="Import Data" style="margin-right: 20px;">
                                        <div class="btn btn-primary" onclick="window.location = '/admin/da-system';">Clear</div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__head">
                <div class="m-portlet__head-caption">
                    <div class="m-portlet__head-title">
                        <span class="m-portlet__head-icon">
                            <i class="fa fa-file-excel-o"></i>
                        </span>
                        <h3 class="m-portlet__head-text">
                            RPS Upload
                        </h3>
                    </div>
                </div>
                <div class="m-portlet__head-tools" style="padding-right: 13px;">
                    
                </div>
            </div>
            <div class="m-portlet__body">
                <div class="m-section">
                    <div class="m-section__content">
                        <div class="col-md-12">
                            <div class="row" style="color:red;">* Please remove extra headers &amp; footers from file before processing</div>
                            <div class="row" style="font-weight: 500;">[Supported file - xls, xlsx] &nbsp;&nbsp;<span style="font-weight: 500;">[<a href="/assets/blacksoil_da_rps_data_format.xlsx" download>Download Sample File</a>]</span></div>
                            <form id="da_system_upload_form" class="form-horizontal" action="/admin/da-system/rps-import" method="POST" enctype="multipart/form-data" onsubmit="$('.init-loader').css({display:'block'});">
                                <input name="_token" value="{!! csrf_token() !!}" type="hidden">
                                <div class="row" style="padding-bottom: 10px; margin-left: -32px; padding-top: 10px;">
                                    <div class="col-md-3">
                                        <input type="file" name="file" id="file" class="form-control" autocomplete="off" required="required" accept=".xls,.xlsx">
                                    </div>
                                    <div class="col-md-6" style="padding-top: 2px;">
                                        <input type="submit" class="btn btn-accent" value="Import Data" style="margin-right: 20px;">
                                        <div class="btn btn-primary" onclick="window.location = '/admin/da-system';">Clear</div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__head">
                <div class="m-portlet__head-caption">
                    <div class="m-portlet__head-title">
                        <span class="m-portlet__head-icon">
                            <i class="fa fa-file-excel-o"></i>
                        </span>
                        <h3 class="m-portlet__head-text">
                            Collection Upload
                        </h3>
                    </div>
                </div>
                <div class="m-portlet__head-tools" style="padding-right: 13px;">
                    
                </div>
            </div>
            <div class="m-portlet__body">
                <div class="m-section">
                    <div class="m-section__content">
                        <div class="col-md-12">
                            <div class="row" style="color:red;">* Please remove extra headers &amp; footers from file before processing</div>
                            <div class="row" style="font-weight: 500;">[Supported file - xls, xlsx] &nbsp;&nbsp;<span style="font-weight: 500;">[<a href="/assets/blacksoil_da_coll_data_format.xlsx" download>Download Sample File</a>]</span></div>
                            <form id="da_system_upload_form" class="form-horizontal" action="/admin/da-system/payment-import" method="POST" enctype="multipart/form-data" onsubmit="$('.init-loader').css({display:'block'});">
                                <input name="_token" value="{!! csrf_token() !!}" type="hidden">
                                <div class="row" style="padding-bottom: 10px; margin-left: -32px; padding-top: 10px;">
                                    <div class="col-md-3">
                                        <input type="file" name="file" id="file" class="form-control" autocomplete="off" required="required" accept=".xls,.xlsx">
                                    </div>
                                    <div class="col-md-6" style="padding-top: 2px;">
                                        <input type="submit" class="btn btn-accent" value="Import Data" style="margin-right: 20px;">
                                        <div class="btn btn-primary" onclick="window.location = '/admin/da-system';">Clear</div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        {{-- File Processing Status --}}
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__head">
                <div class="m-portlet__head-caption">
                    <div class="m-portlet__head-title">
                        <span class="m-portlet__head-icon">
                            <i class="fa fa-tasks"></i>
                        </span>
                        <h3 class="m-portlet__head-text">
                            Processing Status
                        </h3>
                    </div>
                </div>
            </div>
            <div class="m-portlet__body">
                <div class="m-section">
                    <div class="m-section__content">
                        <table class="table table-bordered table-hover" style="font-size: 13px;">
                            <thead>
                                <tr style="background-color: #f4f5f8;">
                                    <th>#</th>
                                    <th>File Name</th>
                                    <th>Queued At</th>
                                    <th>Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($jobs as $job)
                                    @php
                                        $payload = json_decode($job->payload);
                                        $fileName = $payload->file_name ?? '—';
                                    @endphp
                                    <tr>
                                        <td>{{ $job->id }}</td>
                                        <td>{{ $fileName }}</td>
                                        <td>{{ $job->created_at }}</td>
                                        <td>
                                            @if($job->is_available == 1)
                                                <span class="badge badge-success" style="padding: 5px 10px; background-color: #34bfa3; color: #fff; border-radius: 4px;">Processed</span>
                                            @else
                                                <span class="badge badge-warning" style="padding: 5px 10px; background-color: #ffb822; color: #fff; border-radius: 4px;">Pending</span>
                                            @endif
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="4" class="text-center">No files uploaded yet.</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

@include("admin.layouts.footer")
