<?php $__env->startPush('script'); ?>
    <script>
        (function($) {
            "use strict";

            $('#ql-attachment').on('change', function(e) {
                var files = e.target.files;
                var $area = $('.ql-attachments-area');
                $area.find('.ql-attachment-file').remove();

                if (files.length > 0) {
                    for (var i = 0; i < files.length; i++) {
                        var file = files[i];
                        var html = `
                           <div class="ql-attachment-file">
                               <span class="ql-attachment-file-icon">
                                   <i class="fa-regular fa-file-zipper"></i>
                               </span>
                               <span class="ql-attachment-file-name">${file.name}</span>
                               <button type="button" class="ql-attachment-file-delete">
                                   <i class="fa-solid fa-xmark"></i>
                               </button>
                           </div>
                       `;
                        $area.append(html);
                    }
                    $area.removeClass('d-none');
                } else {
                    $area.addClass('d-none');
                }
            });

            $(document).on('click', '.ql-attachment-file-delete', function() {
                var $fileDiv = $(this).closest('.ql-attachment-file');
                var fileName = $fileDiv.find('.ql-attachment-file-name').text();

                var input = document.getElementById('ql-attachment');
                var dt = new DataTransfer();

                for (var i = 0; i < input.files.length; i++) {
                    if (input.files[i].name !== fileName) {
                        dt.items.add(input.files[i]);
                    }
                }

                input.files = dt.files;

                $fileDiv.remove();

                if ($('.ql-attachment-file').length === 0) {
                    $('#ql-attachment').val('');
                    $('.ql-attachments-area').addClass('d-none');
                }
            });

            $('#ql-attachment').on('change', function(e) {
                let attachmentsArea = $('.ql-attachments-area');
                let attachmentsAreaHeight = attachmentsArea[0].scrollHeight;
                attachmentsArea.css('--this-m', `${attachmentsAreaHeight}px`);
                if (e.target.files.length > 5) {
                    notify('error', `<?php echo app('translator')->get('You can select a maximum of 5 files.'); ?>`);
                    $('#ql-attachment').val('');
                    $('.ql-attachments-area').addClass('d-none');
                    return;
                }
            });


            let attachmentsArea = $('.ql-attachments-area');
            $('.ql-attachments-area-collapse').on('click', function() {
                attachmentsArea.toggleClass('hidden');
            });

            // ========================== editor Js Start =====================
            const editor = document.getElementById('editor');
            if (editor) {
                const quill = new Quill(editor, {
                    theme: 'snow',
                    modules: {
                        toolbar: [
                            ['bold', 'italic', 'underline', 'strike'],
                            [{
                                header: [1, 2, false]
                            }],
                            [{
                                'size': ['small', 'normal', 'large', 'huge']
                            }],
                            [{
                                list: 'ordered'
                            }, {
                                list: 'bullet'
                            }],
                            ['link', 'clean'],
                        ]
                    }
                });

                document.querySelector('.editorForm').addEventListener('submit', function() {
                    $('[name=description]').val(quill.root.innerHTML);
                });
            }

        })(jQuery);
    </script>
<?php $__env->stopPush(); ?>
<?php /**PATH C:\laragon\www\projects\custom_viserdesk\Files\core\resources\views/templates/basic/user/ticket/upload_js.blade.php ENDPATH**/ ?>