<?php $__env->startPush('scripts'); ?>
    <script>

        (function($){
            "use strict";

            $(document).ready(function(){
                $(document).on('submit', '#item_delete_form', function(event) {
                    event.preventDefault();
                    $('#pre-loader').removeClass('d-none');
                    $('#deleteItemModal').modal('hide');
                    let formData = new FormData();
                    formData.append('_token', "<?php echo e(csrf_token()); ?>");
                    formData.append('id', $('#delete_item_id').val());
                    let id = $('#delete_item_id').val();
                    $.ajax({
                        url: "<?php echo e(route('marketing.flash-deals.delete')); ?>",
                        type: "POST",
                        cache: false,
                        contentType: false,
                        processData: false,
                        data: formData,
                        success: function(response) {
                            reloadWithData(response);
                            toastr.success('<?php echo e(__("common.deleted_successfully")); ?>')
                            $('#pre-loader').addClass('d-none');
                        },
                        error: function(response) {
                            if(response.responseJSON.error){
                                toastr.error(response.responseJSON.error ,"<?php echo e(__('common.error')); ?>");
                                $('#pre-loader').addClass('d-none');
                                return false;
                            }
                            toastr.error('<?php echo e(__("common.error_message")); ?>')
                            $('#pre-loader').addClass('d-none');
                        }
                    });
                });

                $(document).on('change', '.changeStatus', function(event){
                    let id = $(this).data('id');

                    let status = 0;
                    if($(this).prop('checked')){
                        status = 1;
                    }
                    else{
                        status = 0;
                    }
                    $('#pre-loader').removeClass('d-none');
                    let formData = new FormData();
                    formData.append('_token', "<?php echo e(csrf_token()); ?>");
                    formData.append('id', id);
                    formData.append('status', status);

                    $.ajax({
                        url: "<?php echo e(route('marketing.flash-deals.status')); ?>",
                        type: "POST",
                        cache: false,
                        contentType: false,
                        processData: false,
                        data: formData,
                        success: function(response) {
                            toastr.success("<?php echo e(__('common.updated_successfully')); ?>","<?php echo e(__('common.success')); ?>");
                            $('#pre-loader').addClass('d-none');
                            reloadWithData(response);
                        },
                        error: function(response) {
                            if(response.responseJSON.error){
                                toastr.error(response.responseJSON.error ,"<?php echo e(__('common.error')); ?>");
                                $('#pre-loader').addClass('d-none');
                                return false;
                            }
                            toastr.error("<?php echo e(__('common.error_message')); ?>");
                            $('#pre-loader').addClass('d-none');
                        }
                    });
                });

                $(document).on('change', '.changeFeatured', function(event){
                    let id = $(this).data('id');

                    let is_featured = 0;
                    if($(this).prop('checked')){
                        is_featured = 1;
                    }
                    else{
                        is_featured = 0;
                    }
                    $('#pre-loader').removeClass('d-none');
                    let formData = new FormData();
                    formData.append('_token', "<?php echo e(csrf_token()); ?>");
                    formData.append('id', id);
                    formData.append('is_featured', is_featured);

                    $.ajax({
                        url: "<?php echo e(route('marketing.flash-deals.featured')); ?>",
                        type: "POST",
                        cache: false,
                        contentType: false,
                        processData: false,
                        data: formData,
                        success: function(response) {
                            toastr.success("<?php echo e(__('common.updated_successfully')); ?>","<?php echo e(__('common.success')); ?>");
                            $('#pre-loader').addClass('d-none');
                        },
                        error: function(response) {
                            if(response.responseJSON.error){
                                toastr.error(response.responseJSON.error ,"<?php echo e(__('common.error')); ?>");
                                $('#pre-loader').addClass('d-none');
                                return false;
                            }
                            toastr.error("<?php echo e(__('common.error_message')); ?>");
                            $('#pre-loader').addClass('d-none');
                        }
                    });
                });

                $(document).on('click', '.delete_deal', function(event){
                    event.preventDefault();
                    let id = $(this).data('id');
                    $('#delete_item_id').val(id);
                    $('#deleteItemModal').modal('show');

                });

                function reloadWithData(response){
                    $('#item_table').empty();
                    $('#item_table').html(response);
                    CRMTableThreeReactive();
                }

            });

        })(jQuery);

    </script>
<?php $__env->stopPush(); ?>
<?php /**PATH /home/penastud/public_html/gsport/Modules/Marketing/Resources/views/flash_deals/components/_scripts.blade.php ENDPATH**/ ?>