
<?php $__env->startSection('pageTitle', 'Carousel Image Manager'); ?>

<?php $__env->startSection('content'); ?>
<div class="card">
    <div class="card-body">
        <form id="carouselUploadForm" action="<?php echo e(route('admin.carouselphoto.list')); ?>" method="POST" enctype="multipart/form-data">
            <?php echo csrf_field(); ?>
            <div class="form-group">
                <label>Upload Carousel Images</label>
                <input type="file" name="photos[]" class="form-control" multiple required>
                <span class="text-danger photos_error"></span>
            </div>
            <button class="btn btn-primary mt-2">Upload</button>
        </form>

        <hr>

        <?php
$__split = function ($name, $params = []) {
    return [$name, $params];
};
[$__name, $__params] = $__split('admin.carousel-image');

$__html = app('livewire')->mount($__name, $__params, 'lw-1763337349-0', $__slots ?? [], get_defined_vars());

echo $__html;

unset($__html);
unset($__name);
unset($__params);
unset($__split);
if (isset($__slots)) unset($__slots);
?>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
    window.addEventListener('confirmDeleteCarouselImage', function(event) {
        const id = event.detail[0].id;

        Swal.fire({
            title: 'Delete image?',
            text: 'This action is permanent.',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonText: 'Yes, delete it',
            cancelButtonText: 'Cancel',
        }).then((result) => {
            if (result.isConfirmed) {
                Livewire.dispatch('deleteCarouselImageAction', { id });
            }
        });
    });

    $(document).ready(function () {
        $('#carouselUploadForm').submit(function (e) {
            e.preventDefault();

            let form = this;
            let formData = new FormData(form);

            $.ajax({
                url: $(form).attr('action'),
                method: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                dataType: 'json',
                beforeSend: function () {
                    $('.photos_error').text('');
                },
                success: function (res) {
                    if (res.status === 1) {
                        form.reset();
                        toastr.success(res.message);
                        Livewire.dispatch('refreshCarousel');
                    } else {
                        toastr.error(res.message);
                    }
                },
                error: function (err) {
                    $.each(err.responseJSON.errors, function (key, val) {
                        if (key.startsWith('photos')) {
                            $('.photos_error').text(val[0]);
                        }
                    });
                }
            });
        });
    });
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('back.layout.page-layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\larablog\resources\views/back/pages/carouselphoto/carousel_photo_list.blade.php ENDPATH**/ ?>