@section('site_title', formatTitle([__('Payments'), config('settings.title')]))

@include('shared.breadcrumbs', ['breadcrumbs' => [
    ['url' => route('admin.dashboard'), 'title' => __('Admin')],
    ['title' => __('Payments')],
]])

<div class="d-flex">
    <div class="flex-grow-1">
        <h2 class="mb-3 d-inline-block">{{ __('Payments') }}</h2>
    </div>
</div>

<div class="card border-0 shadow-sm">
    <div class="card-header align-items-center">
        <div class="row">
            <div class="col"><div class="font-weight-medium py-1">{{ __('Payments') }}</div></div>
            <div class="col-auto">
                <form method="GET" action="{{ route('admin.payments') }}" class="d-md-flex">
                    @include('shared.filter-tags')
                    <div class="input-group input-group-sm">
                        <input class="form-control" name="search" placeholder="{{ __('Search') }}" value="{{ app('request')->input('search') }}">
                        <div class="input-group-append">
                            <button type="button" class="btn {{ request()->input('search') || request()->input('type') || request()->input('status') || request()->input('sort') ? 'btn-primary' : 'btn-outline-primary' }} d-flex align-items-center dropdown-toggle dropdown-toggle-split reset-after" data-enable="tooltip" title="{{ __('Filters') }}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">@include('icons.filter', ['class' => 'fill-current width-4 height-4'])&#8203;</button>
                            <div class="dropdown-menu {{ (__('lang_dir') == 'rtl' ? 'dropdown-menu' : 'dropdown-menu-right') }} border-0 shadow width-64" id="search-filters">
                                <div class="dropdown-header py-1">
                                    <div class="row">
                                        <div class="col"><div class="font-weight-medium m-0 text-dark">{{ __('Filters') }}</div></div>
                                        <div class="col-auto">
                                            @if(request()->input('search') || request()->input('type') || request()->input('status') || request()->input('sort'))
                                                <a href="{{ route('admin.payments') }}" class="text-secondary">{{ __('Reset') }}</a>
                                            @endif
                                        </div>
                                    </div>
                                </div>

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

                                <div class="form-group px-4">
                                    <label for="i-by" class="small">{{ __('Search by') }}</label>
                                    <select name="by" id="i-by" class="custom-select custom-select-sm">
                                        @foreach(['payment' => __('Payment ID'), 'invoice' => __('Invoice ID')] as $key => $value)
                                            <option value="{{ $key }}" @if(request()->input('by') == $key || !request()->input('by') && $key == 'payment') selected @endif>{{ $value }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="form-group px-4">
                                    <label for="i-plan" class="small">{{ __('Plan') }}</label>
                                    <select id="i-plan" name="plan" class="custom-select custom-select-sm">
                                        <option value="">{{ __('All') }}</option>
                                        @foreach($plans as $plan)
                                            <option value="{{ $plan->id }}" @if(request()->input('plan') == $plan->id) selected @endif>{{ $plan->name }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="form-group px-4">
                                    <label for="i-interval" class="small">{{ __('Interval') }}</label>
                                    <select name="interval" id="i-interval" class="custom-select custom-select-sm">
                                        <option value="">{{ __('All') }}</option>
                                        @foreach(['month' => __('Monthly'), 'year' => __('Yearly')] as $key => $value)
                                            <option value="{{ $key }}" @if(request()->input('interval') == $key && request()->input('interval') !== null) selected @endif>{{ $value }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="form-group px-4">
                                    <label for="i-processor" class="small">{{ __('Processor') }}</label>
                                    <select name="processor" id="i-processor" class="custom-select custom-select-sm">
                                        <option value="">{{ __('All') }}</option>
                                        @foreach(config('payment.processors') as $key => $value)
                                            <option value="{{ $key }}" @if(request()->input('processor') == $key && request()->input('processor') !== null) selected @endif>{{ __($value['name']) }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="form-group px-4">
                                    <label for="i-status" class="small">{{ __('Status') }}</label>
                                    <select name="status" id="i-status" class="custom-select custom-select-sm">
                                        <option value="">{{ __('All') }}</option>
                                        @foreach(['completed' => __('Completed'), 'pending' => __('Pending'), 'cancelled' => __('Cancelled')] as $key => $value)
                                            <option value="{{ $key }}" @if(request()->input('status') == $key && request()->input('status') !== null) selected @endif>{{ $value }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="form-group px-4">
                                    <label for="i-sort" class="small">{{ __('Sort') }}</label>
                                    <select name="sort" id="i-sort" class="custom-select custom-select-sm">
                                        @foreach(['desc' => __('Descending'), 'asc' => __('Ascending')] as $key => $value)
                                            <option value="{{ $key }}" @if(request()->input('sort') == $key) selected @endif>{{ $value }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="form-group px-4 mb-2">
                                    <button type="submit" class="btn btn-primary btn-sm btn-block">{{ __('Search') }}</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="card-body">
        @include('shared.message')

        @if(count($payments) == 0)
            {{ __('No results found.') }}
        @else
            <div class="list-group list-group-flush my-n3">
                <div class="list-group-item px-0 text-muted">
                    <div class="row align-items-center">
                        <div class="col">
                            <div class="row align-items-center">
                                <div class="col-12 col-lg-5 d-flex">
                                    {{ __('Amount') }}
                                </div>

                                <div class="col-12 col-lg-5 d-flex">
                                    {{ __('User') }}
                                </div>

                                <div class="col-12 col-lg-2 d-flex">
                                    {{ __('Status') }}
                                </div>
                            </div>
                        </div>
                        <div class="col-auto">
                            <a href="#" class="btn btn-outline-primary btn-sm invisible">{{ __('Edit') }}</a>
                        </div>
                    </div>
                </div>
                @foreach($payments as $payment)
                    <div class="list-group-item px-0">
                        <div class="row align-items-center">
                            <div class="col text-truncate">
                                <div class="row align-items-center">
                                    <div class="col-12 col-lg-5 d-flex">
                                        <div class="text-truncate">
                                            <div class="d-flex align-items-center">
                                                <img src="{{ url('/') }}/images/icons/payments/{{ $payment->processor }}.svg" class="width-6 rounded-sm">

                                                <div class="text-truncate {{ (__('lang_dir') == 'rtl' ? 'mr-3 ml-2' : 'ml-3 mr-2') }}">
                                                    <a href="{{ route('admin.payments.edit', $payment->id) }}">{{ formatMoney($payment->amount, $payment->currency) }}</a> <span class="text-muted">{{ $payment->currency }}</span>
                                                </div>

                                                @if(in_array($payment->status, ['completed', 'cancelled']))
                                                    <a href="{{ route('admin.invoices.show', $payment->id) }}" class="badge badge-secondary text-truncate" data-enable="tooltip" title="{{ __('Invoice') }}">{{ $payment->invoice_id }}</a>
                                                @endif
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-12 col-lg-5 d-flex align-items-center">
                                        @if(isset($payment->user))
                                            <div class="d-inline-block {{ (__('lang_dir') == 'rtl' ? 'ml-3' : 'mr-3') }} text-truncate">
                                                <img src="{{ gravatar($payment->user->email, 48) }}" class="rounded-circle width-6 height-6">
                                            </div>
                                            <a href="{{ route('admin.users.edit', $payment->user->id) }}">{{ $payment->user->name }}</a>
                                        @else
                                            <div class="d-inline-block {{ (__('lang_dir') == 'rtl' ? 'ml-3' : 'mr-3') }}">
                                                <img src="{{ gravatar('', 48, 'mp') }}" class="rounded-circle width-6 height-6">
                                            </div>
                                            <div class="text-muted">{{ __('Deleted') }}</div>
                                        @endif
                                    </div>

                                    <div class="col-12 col-lg-2 d-flex">
                                        @if($payment->status == 'completed')
                                            <span class="badge badge-success text-truncate">{{ __('Completed') }}</span>
                                        @elseif($payment->status == 'pending')
                                            <span class="badge badge-secondary text-truncate">{{ __('Pending') }}</span>
                                        @else
                                            <span class="badge badge-danger text-truncate">{{ __('Cancelled') }}</span>
                                        @endif
                                    </div>
                                </div>
                            </div>
                            <div class="col-auto">
                                <a href="{{ route('admin.payments.edit', $payment->id) }}" class="btn btn-outline-primary btn-sm">{{ __('Edit') }}</a>
                            </div>

                        </div>
                    </div>
                @endforeach

                <div class="mt-3 align-items-center">
                    <div class="row">
                        <div class="col">
                            <div class="mt-2 mb-3">{{ __('Showing :from-:to of :total', ['from' => $payments->firstItem(), 'to' => $payments->lastItem(), 'total' => $payments->total()]) }}
                            </div>
                        </div>
                        <div class="col-auto">
                            {{ $payments->onEachSide(1)->links() }}
                        </div>
                    </div>
                </div>
            </div>
        @endif
    </div>
</div>