@extends('Admin.layouts.master')

@section('content')
    <?php $currentPage = 'manage-restaurant'; ?>




    <!--  END LOADER -->
    <!--  BEGIN MAIN CONTAINER  -->

    <div class="layout-px-spacing">
        <div class="middle-content container-xxl p-0">
            <div class="row layout-top-spacing ">
                <div class="top-tabel">
                    <div class="row">
                        <div class="col-md-4">
                            <h6 class="card-title">Archive Restaurant</h6>
                            {{-- voucher to restaurant updated --}}
                        </div>
                        <div class="col-md-8">

                        </div>
                    </div>
                </div>

                <div class="col-xl-12 col-lg-12 col-sm-12  layout-spacing">
                    <div class="widget-content widget-content-area br-8 position-btn" style="overflow: auto;">
                        <table id="zero-config" class="table dt-table-hover" style="width:100%">
                            <thead class="text-center">
                                <th class="text-center">Sr no</th>
                                <th class="text-center">Restaurant Name</th>
                                <th class="text-center">Restaurant ID</th>
                                <th class="text-center">Image </th>
                                <th class="no-content">Action</th>
                                </tr>


                            </thead>
                            <tbody class="text-center">
                                @php($count = 0)
                                @foreach ($restaurant as $restaurants)
                                    @php($count++)
                                    <tr>
                                        <td class="text-center">{{ $count }}</td>
                                        <td class="text-center">{{ $restaurants->name }}</td>
                                        <td class="text-center">{{ $restaurants->restaurant_id }}</td>
                                        <td><img src="{{ ListingImageUrl('restaurant_images', $restaurants['image']) }}"
                                                height="50px" width="50px"></td>
                                        <td class="view-transcation">
                                            <a class="cust_unarchive_btn" data-id="{{ $restaurants->id }}" href=""
                                                data-toggle="modal" data-target="#restore-modal">
                                                <img src="{{ asset('public/assets/img/restore.svg') }}" />
                                                <span>Restore</span>
                                            </a>
                                        </td>
                                    </tr>
                                @endforeach


                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="restore-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
    aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">

            <div class="modal-body">
                <div class="modal-header">
                    <button type="button pointer" class="btn-close" data-dismiss="modal" aria-label="Close">
                        x
                    </button>
                </div>
                <input type="hidden" id="unarchive_id" name="unarchive_customer_id">
                <p class="modal-text restore-modal-heading">Are you sure you want to<br>Unarchive?</p>
                <div class="modal-btn d-flex ">
                    <a class="extra-btn pointer" data-dismiss="modal">No</a>
                    <a class="download-btn-custom restaurant_unarchive" href="">Yes, Unarchive</a>
                </div>

            </div>
        </div>
    </div>
</div>
@endsection

@section('section_script')
    <script>
        // For Un-archive

        $(document).on("click", ".cust_unarchive_btn", function() {
            var data_id = $(this).data('id');
            $('#unarchive_id').val(data_id);
        });

        $(document).on("click", ".restaurant_unarchive", function(e) {
            e.preventDefault();
            let base_url = url_path;
            var archive_id = $('#unarchive_id').val();
            $.ajaxSetup({
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                },
            });
            $.ajax({
                type: "POST",
                url: base_url + "/manage_restaurant_unarchive/" + archive_id,
                success: function(response) {
                    if (response.status == 200) {
                        toastr.success('Record has been unarchive');
                        setTimeout(function() {
                            window.location.href = base_url + "/manage_restaurant_archive";
                        }, 1000);
                    } else {
                        toastr.error("Something went wrong");
                    }
                },
            });
        });
    </script>
@endsection
