@extends('admin.layouts.app')

@section('panel')
    <div class="row">

        <div class="col-lg-12">
            <div class="show-filter mb-3 text-end">
                <button type="button" class="btn btn-outline--primary showFilterBtn btn-sm"><i class="las la-filter"></i>
                    @lang('Filter')</button>
            </div>
            <div class="card responsive-filter-card mb-4">
                <div class="card-body">
                    <form action="">
                        <div class="d-flex flex-wrap gap-4">
                            <div class="flex-grow-1">
                                <label>@lang('TRX/Username/UserId')</label>
                                <input type="text" name="search" value="{{ request()->search }}" class="form-control">
                            </div>
                            <div class="flex-grow-1">
                                <label>@lang('Status')</label>
                                <select name="status" class="form-control">
                                    <option value="">@lang('All')</option>
                                    <option value="{{ Status::Pending }}" @selected(request()->status == Status::Pending)>@lang('Pending')
                                    </option>
                                    <option value="{{ Status::Approved }}" @selected(request()->status == Status::Approved)>@lang('Approved')
                                    </option>
                                    <option value="{{ Status::Rejected }}" @selected(request()->status == Status::Rejected)>@lang('Rejected')
                                    </option>
                                </select>
                            </div>
                            <div class="flex-grow-1">
                                <label>@lang('Remark')</label>
                                <select class="form-control" name="remark">
                                    <option value="">@lang('Any')</option>
                                    @foreach ($remarks as $remark)
                                        <option value="{{ $remark }}" @selected(request()->remark == $remark)>
                                            {{ __(keyToTitle($remark)) }}</option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="flex-grow-1">
                                <label>@lang('Date')</label>
                                <input name="date" type="text" data-range="true" data-multiple-dates-separator=" - "
                                    data-language="en" class="datepicker-here form-control" data-position='bottom right'
                                    placeholder="@lang('Start date - End date')" autocomplete="off" value="{{ request()->date }}">
                            </div>
                            <div class="flex-grow-1 align-self-end">
                                <button class="btn btn--primary w-100 h-45"><i class="fas fa-filter"></i>
                                    @lang('Filter')</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="d-flex justify-content-end mb-3">

                <div class="btn-group float-end" role="group" aria-label="Basic example">
                    <a href="{{ route('admin.report.transaction.pdf', ['date' => request()->date, 'search' => request()->search, 'remark' => request()->remark, 'status' => request()->status]) }}"
                        class="btn btn--primary btn-sm d-flex align-items-center"><i class="las la-file-pdf"></i>
                        @lang('Generate PDF')</a>

                    <a href="{{ route('admin.report.transaction.report', ['date' => request()->date, 'search' => request()->search, 'remark' => request()->remark, 'status' => request()->status]) }}"
                        class="btn btn--info btn-sm d-flex align-items-center"><i class="las la-file-excel"></i>
                        @lang('Generate Excel')</a>
                </div>
            </div>

            <div class="card b-radius--10 ">
                <div class="card-body p-0">
                    <div class="table-responsive--sm table-responsive">
                        <table class="table table--light style--two">
                            <thead>
                                <tr>
                                    <th>@lang('User')</th>
                                    <th>@lang('TRX')</th>
                                    <th>@lang('Transacted')</th>
                                    <th>@lang('Amount')</th>
                                    {{-- <th>@lang('Post Balance')</th> --}}
                                    <th>@lang('Mode of payment')</th>
                                    <th>@lang('Details')</th>
                                    <th>@lang('Status')</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($transactions as $trx)
                                    <tr>
                                        <td>
                                            <span class="fw-bold">{{ $trx->user->fullname }}</span>
                                            <br> <span>UserID: <b> {{ $trx->user->system_id }}</b></span>
                                            <br>
                                            <span class="small"> <a
                                                    href="{{ appendQuery('search', $trx->user->username) }}"><span>@</span>{{ $trx->user->username }}</a>
                                            </span>
                                        </td>

                                        <td>
                                            <strong>{{ $trx->trx }}</strong>
                                        </td>

                                        <td>
                                            {{ showDateTime($trx->created_at) }}<br>{{ diffForHumans($trx->created_at) }}
                                        </td>

                                        <td class="budget">
                                            <span
                                                class="fw-bold @if ($trx->trx_type == '+') text--success @else text--danger @endif">
                                                {{ $trx->trx_type }} {{ showAmount($trx->amount) }}
                                                {{ __($general->cur_text) }}
                                            </span>
                                        </td>

                                        {{-- <td class="budget">
                                        {{ showAmount($trx->post_balance) }} {{ __($general->cur_text) }}
                                    </td> --}}
                                        <td>{{ $trx->payment_mode }}</td>
                                        <td>{{ __($trx->details) }}</td>
                                        <td>@php echo $trx->statusBadge @endphp</td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td class="text-muted text-center" colspan="100%">{{ __($emptyMessage) }}</td>
                                    </tr>
                                @endforelse

                            </tbody>
                        </table><!-- table end -->
                    </div>
                </div>
                @if ($transactions->hasPages())
                    <div class="card-footer py-4">
                        {{ paginateLinks($transactions) }}
                    </div>
                @endif
            </div><!-- card end -->
        </div>
    </div>
@endsection

@push('style-lib')
    <link rel="stylesheet" href="{{ asset('assets/admin/css/vendor/datepicker.min.css') }}">
@endpush


@push('script-lib')
    <script src="{{ asset('assets/admin/js/vendor/datepicker.min.js') }}"></script>
    <script src="{{ asset('assets/admin/js/vendor/datepicker.en.js') }}"></script>
@endpush
@push('script')
    <script>
        (function($) {
            "use strict";
            if (!$('.datepicker-here').val()) {
                $('.datepicker-here').datepicker();
            }
        })(jQuery)
    </script>
@endpush
