@extends('admin.layouts.app')
@section('panel')
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body p-0">
                    <div class="table-responsive--md table-responsive">
                        <table class="table--light style--two table">
                            <thead>
                                <tr>
                                    <th>@lang('Name')</th>
                                    <th>@lang('Status')</th>
                                    <th>@lang('Action')</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($websitePages as $websitePage)
                                    <tr>
                                        <td>
                                            <span>{{ __($websitePage->name) }}</span>
                                        </td>
                                        <td>
                                            @php
                                                echo $websitePage->statusBadge;
                                            @endphp
                                        </td>
                                        <td>
                                            <div class="button--group">
                                                <button class="btn btn-sm btn-outline--primary editButton" data-website_page="{{ $websitePage }}">
                                                    <i class="la la-pencil"></i> @lang('Edit')
                                                </button>
                                                @if ($websitePage->status == Status::ENABLE)
                                                    <button class="btn btn-sm btn-outline--danger confirmationBtn" data-action="{{ route('admin.website.page.status', $websitePage->id) }}" data-question="@lang('Are you sure to disable this website page')?">
                                                        <i class="la la-eye-slash"></i> @lang('Disable')
                                                    </button>
                                                @else
                                                    <button class="btn btn-sm btn-outline--success confirmationBtn" data-action="{{ route('admin.website.page.status', $websitePage->id) }}" data-question="@lang('Are you sure to enable this website page')?">
                                                        <i class="la la-eye"></i> @lang('Enable')
                                                    </button>
                                                @endif
                                            </div>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td class="text-muted text-center" colspan="100%">{{ __($emptyMessage) }}</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
                @if ($websitePages->hasPages())
                    <div class="card-footer py-4">
                        {{ paginateLinks($websitePages) }}
                    </div>
                @endif
            </div>
        </div>
    </div>
    <div class="modal fade" id="websitePageModal" role="dialog" tabindex="-1">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title"></h4>
                    <button class="close" data-bs-dismiss="modal" type="button" aria-label="Close">
                        <i class="las la-times"></i>
                    </button>
                </div>
                <form method="post">
                    @csrf
                    <div class="modal-body">
                        <div class="form-group">
                            <label>@lang('Name')</label>
                            <input class="form-control" name="name" type="text" value="{{ old('name') }}" required>
                        </div>
                        <button class="btn btn--primary w-100 h-45" type="submit">@lang('Submit')</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <x-confirmation-modal />
@endsection

@push('breadcrumb-plugins')
    <x-search-form />
    <button class="btn btn--lg btn-outline--primary createButton" type="button"><i class="las la-plus"></i>@lang('Add New')</button>
@endpush


@push('script')
    <script>
        (function($) {
            "use strict"

            let modal = $('#websitePageModal');
            $('.createButton').on('click', function() {
                modal.find('.modal-title').text(`@lang('Add New Website Page')`);
                modal.find('form').attr('action', `{{ route('admin.website.page.store') }}`);
                modal.modal('show');
            });
            $('.editButton').on('click', function() {
                var websitePage = $(this).data('website_page');
                modal.find('.modal-title').text(`@lang('Update Website Page')`);
                modal.find('form').attr('action', `{{ route('admin.website.page.store', '') }}/${websitePage.id}`);
                modal.find('[name=name]').val(websitePage.name);
                modal.modal('show')
            });
            modal.on('hidden.bs.modal', function() {
                $('#websitePageModal form')[0].reset();
            });

        })(jQuery);
    </script>
@endpush
