@extends('admin.layouts.app')

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

        <div class="col-lg-12">
            <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('Title')</th>
                                    <th>@lang('Level')</th>
                                    <th>@lang('Reward Amount')</th>
                                    <th>@lang('Eligibility Duration')</th>
                                    <th>@lang('Number of Users')</th>
                                    <th>@lang('Actions')</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($levels as $level)
                                    <tr>
                                        <td>
                                            <div class="d-flex align-items-center">
                                                <div class="avatar avatar-sm mr-2">
                                                    <img src="{{ getImage(getFilePath('levels') . '/' . $level->image, getFileSize('levels')) }}"
                                                        width="36" height="36" alt="@lang('level image')">
                                                </div>
                                                <span class="fw-bold ms-2">{{ $level->title }}</span>
                                            </div>
                                        </td>

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

                                        <td>
                                            {{ showAmount($level->reward_amount) }} {{ __($general->cur_text) }}
                                        </td>

                                        <td>
                                            {{ $level->eligibility_duration }} {{ __($general->interval) }}
                                        </td>

                                        <td>
                                            {{ $level->users_count ?? 0 }}
                                        </td>

                                        <td>
                                            @haspermission('level_wise_reward:edit', 'admin')
                                                <button class="btn btn-sm btn-outline--primary editBtn" data-bs-toggle="modal"
                                                    data-bs-target="#editModal" data-id="{{ $level->id }}"
                                                    data-title="@lang('Edit Level #'){{ $level->level }} ">
                                                    <i class="la la-pencil"></i> @lang('Edit')
                                                </button>
                                            @endhaspermission

                                            {{-- <button class="btn btn-sm btn-outline--danger confirmationBtn"
                                                data-question="@lang('Are you sure to delete this level?')"
                                                data-action="{{ route('admin.level.destroy', $level->id) }}"
                                                data-values="{{ json_encode(['id' => $level->id]) }}">
                                                <i class="la la-trash"></i> @lang('Delete')
                                            </button> --}}

                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td class="text-muted text-center" colspan="100%">{{ __($emptyMessage) }}</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table><!-- table end -->
                    </div>
                </div>
                @if ($levels->hasPages())
                    <div class="card-footer py-4">
                        {{ paginateLinks($levels) }}
                    </div>
                @endif
            </div><!-- card end -->
        </div>
    </div>

    <x-confirmation-modal />

    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="editModalLabel"></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                </div>
            </div>
        </div>
    </div>

    @push('script')
        <script>
            (function($) {
                "use strict";
                $('.editBtn').on('click', function() {
                    var modal = $('#editModal');
                    var id = $(this).data('id');
                    var url = "{{ route('admin.level.edit', ':id') }}";
                    url = url.replace(':id', id);
                    var title = $(this).data('title');
                    $.ajax({
                        url: url,
                        method: 'GET',
                        success: function(response) {
                            modal.find('.modal-title').text(title);
                            modal.find('.modal-body').html(response);
                            modal.modal('show');
                        }
                    });
                });
            })(jQuery);
        </script>
    @endpush
@endsection

@push('breadcrumb-plugins')
    {{-- <button class="btn btn-sm btn-outline--primary editBtn" data-bs-toggle="modal" data-bs-target="#editModal"
        data-id="{{ '' }}" data-title="@lang('Create New Level')">
        <i class="la la-plus"></i> @lang('Add New')
    </button> --}}
@endpush

@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
