@extends('backend.layouts.app')

@section('content')
<div class="row page-titles">
   <div class="col-md-5 align-self-center">
      <h4 class="text-themecolor">Promo</h4>
   </div>
   <div class="col-md-7 align-self-center text-right">
      <div class="d-flex justify-content-end align-items-center">
         <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
            <li class="breadcrumb-item active">Promo</li>
         </ol>
         @can('Promotional Codes-create')
         <a href="{{ route('promo.create') }}"> 
            <button type="button" class="btn btn-info d-none d-lg-block m-l-15">
                <i class="fa fa-plus-circle"></i> Create New
            </button>
        </a>
        @endcan
      </div>
   </div>
</div>

<div class="container-fluid">
    <div id="deleteModal" class="modal fade" role='dialog'>
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <p>Are you sure you want to delete this?</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <span id='deleteButton'></span>
                </div>
            </div>
        </div>
    </div>
    {{-- Status model --}}
    <div id="statusModal" class="modal fade" role='dialog'>
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <p>Are you sure you want to change the status?</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <span id='changestatus'></span>
                </div>
            </div>
        </div>
    </div>
    {{-- end --}}
    <div class="content-wrapper">
        @if (session('status'))
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <i class="far fa-check-circle"></i> {{ session('status') }}
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
        @endif

        @if (session('error'))
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <i class="far fa-check-circle"></i> {{ session('error') }}
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
        @endif

        <section class="content">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body">
                        <div class="form-inline">
                            <form action="{{ route('promo') }}" method="get" id="form">
                                <div class="input-group">
                                    <input type="text" name="search" value="{{ $search }}" class="form-control" placeholder="Search...">
                                    <div class="input-group-append">
                                        <button class="btn btn-secondary" type="submit"><i class="fas fa-search fa-fw"></i></button>
                                        <a href="{{ route('promo') }}" class="btn btn-secondary" title="Reload"><i class="fas fa-sync"></i></a>
                                    </div>
                                </div>
                            </form>
                        </div>
                                <br>
                                <div class="table-responsive">
                            <table id="promo" class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>@sortablelink('id', 'S. No.')</th>

                                        <th>@sortablelink('promo_code', 'Promo Code')</th>
                                        <th>@sortablelink('discount_type', 'Discount Type')</th>
                                        <th>@sortablelink('from_date', ' Discount From')</th>
                                        <th>@sortablelink('to_date', 'Discount To')</th>
                                        <th>@sortablelink('created_at', 'Created At')</th>
                                        <th>@sortablelink('updated_at', 'Updated At')</th>
                                        <th>Status</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse($promoCodeCountries as $key => $promoCodeCountry)
                                        <tr>
                                            <td>{{ $key + 1 }}</td>
                                            <td>{{ $promoCodeCountry->promo_code ?? '-' }}</td>
                                            <td>{{ $promoCodeCountry->discount_type ?? '-' }}</td>
                                            <td>{{ $promoCodeCountry->from_date ?? '-' }}</td>
                                            <td>{{ $promoCodeCountry->to_date ?? '-' }}</td>
                                            <td>{{ $promoCodeCountry->created_at->format(config('GET.admin_date_time_format')) ?? '-' }}</td>
                                            <td>{{ $promoCodeCountry->updated_at->format(config('GET.admin_date_time_format')) ?? '-' }}</td>



                                            
                                            <td onclick="myFunction({{ $promoCodeCountry->id }});">
                                                    @if ($promoCodeCountry->status  == 1)
                                                        <button class="btn btn-success btn-sm"><span>Active</span></button>
                                                    @else
                                                        <button class="btn btn-danger btn-sm"><span>Inactive</span></button>
                                                    @endif
                                                </td>
                                            <td>
                                            @can('Promotional Codes-list')
                                                <a href="{{ route('promo.view', ['id' => $promoCodeCountry->id]) }}">
                                                    <button class="btn btn-info btn-sm" title="view"><i class="fas fa-eye"></i></button>
                                                </a>
                                                @endcan
                                                @can('Promotional Codes-edit')
                                                <a href="{{ route('promo.edit', ['id' => $promoCodeCountry->id] + request()->query()) }}">
                                                    <button class="btn btn-primary btn-sm" title="edit"><i class="fas fa-edit"></i></button>
                                                </a>
                                                @endcan
                                                @can('Promotional Codes-delete')
                                                <button class="btn btn-danger btn-sm" title="delete"
                                                        onclick="confirmDeleteModal(@php echo $promoCodeCountry->id; @endphp)"><i class="fas fa-trash"></i>
                                                    </button>
                                                    @endcan
                                            </td>
                                        </tr>
                                    @empty
                                        <tr>
                                            <td colspan="12">
                                                <h6><center>No Records Found</center></h6>
                                            </td>
                                        </tr>
                                    @endforelse
                                </tbody>
                            </table>
</div>



                            @if ($promoCodeCountries->total() > 0)
                                <div class="d-flex justify-content-between align-items-center">
                                    <!-- Display custom number of entries -->
                                    <div class="entries-info">
                                        Showing {{ $promoCodeCountries->firstItem() }} to {{ $promoCodeCountries->lastItem() }} of {{ $promoCodeCountries->total() }} entries
                                    </div>

                                    <!-- Pagination -->
                                    <div class="pagination-wrapper float-right">
                                        {{ $promoCodeCountries->links('vendor.pagination.bootstrap-4') }}
                                    </div>
                                </div>
                            @endif
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
</div>
{{-- Delete modal --}}
<script type="text/javascript">
    function confirmDeleteModal(id) {
        $('#deleteModal').modal();
        $('#deleteButton').html('<a class="btn btn-danger" style="color:white;" onclick="deleteData(' + id + ')">Delete</a>');
    }

    function deleteData(id) {
            location.replace("{{ route('content.delete') }}?id=" + id  + "{{ request()->getQueryString() ? '&' . request()->getQueryString() : '' }}");
        }
</script>
{{-- end --}}

{{-- Delete modal --}}
<script type="text/javascript">
    function confirmDeleteModal(id) {
        $('#deleteModal').modal();
        $('#deleteButton').html('<a class="btn btn-danger" style="color:white;" onclick="deleteData(' + id + ')">Delete</a>');
    }

    function deleteData(id) {
            location.replace("{{ route('promo.delete') }}?id=" + id  + "{{ request()->getQueryString() ? '&' . request()->getQueryString() : '' }}");
            location.replace("{{ route('promo.delete') }}?id=" + id  + "{{ request()->getQueryString() ? '&' . request()->getQueryString() : '' }}");
        }
</script>
{{-- end --}}
{{-- change status --}}
<script>
    function myFunction(id) {
        $('#statusModal').modal();
        $('#changestatus').html('<a class="btn btn-danger" style="color:white;" onclick="changedataData(' + id + ')">Ok</a>')
    }

    function changedataData(id) {
            $('#statusModal').modal('hide');
            location.replace("{{ route('promo.changestatus') }}?id=" + id  + "{{ request()->getQueryString() ? '&' . request()->getQueryString() : '' }}");
        }
</script>
{{-- end --}}
@stop
