
<?php $__env->startSection('pageTitle', isset($pageTitle) ? $pageTitle : 'Page Title Here'); ?>
<?php $__env->startSection('content'); ?>

<div class="page-header mb-3">
    <h4>Manage Photos for: <?php echo e($facilities->name); ?></h4>
</div>

<div class="card">
    <div class="card-body">
        <form id="photoUploadForm" action="<?php echo e(route('admin.facilityPhotos.upload', $facilities->id)); ?>" method="POST" enctype="multipart/form-data">
            <?php echo csrf_field(); ?>
            <div class="form-group">
                <label for="photos">Upload Photos</label>
                <input type="file" name="photos[]" multiple class="form-control">
                <span class="error-text photos_error text-danger"></span>
            </div>
            <button type="submit" class="btn btn-primary">Upload</button>
        </form>


        <hr>

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

$__html = app('livewire')->mount($__name, $__params, 'lw-3754538807-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('deletePhoto', function(event) {
        var id = event.detail[0].id;

        Swal.fire({
            title: 'Are you sure?',
            text: 'You want to delete this photo.',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonText: 'Yes, Delete',
            cancelButtonText: 'Cancel',
            cancelButtonColor: '#d33',
            confirmButtonColor: '#3085d6',
            width: '320px',
            allowOutsideClick: false
        }).then((result) => {
            if (result.isConfirmed) {
                Livewire.dispatch('deletePhotoAction', {
                    id: id
                });
                Livewire.dispatch('refreshPhotos');
            }
        });
    })

    $(document).ready(function() {
        $('#photoUploadForm').submit(function(e) {
            e.preventDefault();
            if (!$("input[name='photos[]']").val()) {
            toastr.error("Please select at least one image.");
            return;
        }
            var form = this;
            var formData = new FormData(form);

            $.ajax({
                url: $(form).attr('action'),
                method: $(form).attr('method'),
                data: formData,
                processData: false,
                contentType: false,
                dataType: 'json',
                beforeSend: function() {
                    $(form).find('span.error-text').text('');
                },
                success: function(data) {
                    if (data.status === 1) {
                        $(form)[0].reset();
                        toastr.success(data.message);

                        Livewire.dispatch('refreshPhotos'); // Reload photo list
                    } else {
                        toastr.error(data.message);
                    }
                },
                error: function(data) {
                    $.each(data.responseJSON.errors, function(prefix, val) {
                        if (prefix.startsWith('photos')) {
                            $(form).find('span.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\facility\facilityPhoto\photo_list.blade.php ENDPATH**/ ?>