@extends('back-end.master.app')
@section('title', 'Gallery')

@section('body')
    <main class="app-content">
        <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-9">
                        <h5>galleries</h5>
                    </div>
                    <div class="col-md-3">
                        <a href="{{ route('gallery.create') }}" style="float: right;" class="btn btn-primary btn-sm btn-rounded btn-sm btn-rounded">Add Gallery</a>
                    </div>
                </div>
                <div class="row mt-4">
                    @foreach ($galleries as $gallery)
                        <div class="col-md-4 col-sm-6 col-12">
                            <div class="card">
                                <img class="card-img-top" src="{{ asset('storage/'.$gallery->image) }}"
                                    alt="{{ $gallery->title }}" style="width:100%; height:250px;">
                                <div class="card-body">
                                    <h4 class="card-title">{{ $gallery->title }}</h4>
                                    <p class="card-text">
                                        @php
                                            if ($gallery->isSlider == 1) {
                                                echo 'Slider True';
                                            } else {
                                                echo 'Slider False';
                                            }
                                        @endphp
                                    </p>
                                    <a href="{{ route('gallery.edit',$gallery->id) }}" class="btn btn-primary btn-sm btn-rounded"><i class="fa fa-edit"></i>Edit</a>
                                    <a href="{{ route('gallery.delete',$gallery->id) }}" class="btn btn-primary btn-sm btn-rounded"><i class="fa fa-trash"></i>Delete</a>


                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
    </main>


@endsection


@section('pageJs')
    <script type="text/javascript">
        $(".app-menu").removeClass("active");
        $("#nav_gallery").addClass("active");
        $("#nav_galleryi").addClass("is-expanded");
        $("#nav_sub_gallery_list").addClass("active");
        $(document).on("click", ".btn-delete", function() {
            var id = $(this).attr("data-id");
            swal({
                title: "Are you sure want to delete?",
                text: "...",
                type: "warning",
                showCancelButton: true,
                confirmButtonText: "Yes!",
                cancelButtonText: "No!",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function(isConfirm) {
                if (isConfirm) {
                    $('#delete-form').attr('action', "/admin/gallery/" + id);
                    $("#delete-form").submit();
                } else {
                    swal("Cancelled", "Record not deleted", "error");
                    return false;
                }
            });
        });
        <?php
if (session()->has("msg")) {
    ?>

        $.notify({
            title: "Notice: ",
            message: "<?= session()->get('msg') ?>",
            icon: "fa fa-check"
        }, {
            type: "success"
        });
        <?php
}
if ($errors->any()) {
    echo "$('#userModal').modal('show');";
}
?>
    </script>
@endsection
