jQuery(document).ready(function () {
    //generateNotice('error', 'Ceci est une notice');
    $('.action-delete').on('click', function(e) {
        e.preventDefault();
        const id = $(this).parents('tr').first().data('id');

        $('#modal-delete').modal({ backdrop: true, keyboard: true })
            .off('click', '#modal-delete-button')
            .on('click', '#modal-delete-button', function () {
                let deleteForm = $('#delete-form');
                deleteForm.attr('action', deleteForm.attr('action').replace('__id__', id));
                deleteForm.trigger('submit');
            });
    });


});

window.addEventListener('load', (event) => {
    initLcCkEditor();
});
/* CKEditor */

function initLcCkEditor(){
    var elements = $( '.lc-ckeditor' );

    if(elements.length) {
        for (var i = 0; i < elements.length; ++i) {
            if($(elements[i]).data('config')==='simple_config'){
                CKEDITOR.replace(elements[i], {
                    "toolbar": [
                        {
                            items: ['Bold', 'Italic', 'Underline', 'Strike']
                        },
                        {
                            items: ["TextColor"]
                        }
                    ],
                    "language": "fr",
                    'height': 100
                });
            }else{
                CKEDITOR.replace(elements[i], {
                    "toolbar": [
                        {
                            name: "styles",
                            items: ["Format", 'Bold', 'Italic', 'Underline', 'Strike', "Link", "BulletedList"]
                        },
                        {
                            items: ["TextColor"]
                        },
                        {name: 'paragraph', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']},
                        {name: 'insert', items: ['Image', 'SpecialChar']},
                        {name: "document", items: ["Source"]},
                    ],
                    "language": "fr"
                });
            }

        }
    }
}
