System.register(["./inputButton", "froala-editor"], function (exports_1, context_1) {
    "use strict";
    var inputButton_1, froala_editor_1;
    var __moduleName = context_1 && context_1.id;
    return {
        setters: [
            function (inputButton_1_1) {
                inputButton_1 = inputButton_1_1;
            },
            function (froala_editor_1_1) {
                froala_editor_1 = froala_editor_1_1;
            }
        ],
        execute: function () {
            froala_editor_1.default.DEFAULTS = Object.assign(froala_editor_1.default.DEFAULTS, {
                endpoint: '/Api/Media'
            });
            froala_editor_1.default.PLUGINS.mediaManager = function mediaManager(editor) {
                let inputButton;
                const debug = false;
                function _init() {
                    inputButton = new inputButton_1.InputButtonPlugin({
                        name: 'Media Manager',
                        eventName: 'media-library',
                        editor,
                        insert: (media) => {
                            editor.html.insert(media.html);
                        },
                        autoSaveSelection: true,
                        autoRestoreSelection: true,
                        debug
                    });
                    if (debug) {
                        console.log('initialized:', {
                            options: editor.opts.endpoint,
                            instance: this
                        });
                    }
                }
                function onClick() {
                    if (!editor.el) {
                        console.warn('mediaManager.onClick(): unable to find element');
                        return;
                    }
                    inputButton.onClick(editor.el);
                }
                return {
                    _init,
                    onClick
                };
            };
            froala_editor_1.default.DEFAULTS.imageInsertButtons.push('mediaManager'),
                froala_editor_1.default.RegisterCommand('mediaManager', {
                    title: 'Insert from Media Library',
                    undo: false,
                    focus: false,
                    modal: true,
                    callback() {
                        this.mediaManager.onClick();
                    },
                    plugin: 'mediaManager',
                }),
                froala_editor_1.default.DefineIcon('mediaManager', { NAME: 'folder', SVG_KEY: 'imageManager' }),
                froala_editor_1.default.DefineIcon('mediaManagerInsert', { NAME: 'plus', SVG_KEY: 'add' }),
                froala_editor_1.default.DefineIcon('mediaManagerDelete', { NAME: 'trash', SVG_KEY: 'remove' });
            froala_editor_1.default.RegisterQuickInsertButton('media', {
                icon: 'mediaManager',
                title: 'Insert from Media Library',
                callback: function mediaManagerCallback() {
                    const debug = false;
                    const inputButton = new inputButton_1.InputButtonPlugin({
                        name: 'Media Manager',
                        eventName: 'media-library',
                        editor: this,
                        insert: (media) => {
                            this.html.insert(media.html);
                        },
                        autoSaveSelection: true,
                        autoRestoreSelection: true,
                        debug
                    });
                    if (!this.el) {
                        console.warn('mediaManager.onClick(): unable to find element');
                        return;
                    }
                    inputButton.onClick(this.el);
                },
                undo: true
            });
        }
    };
});

//# sourceMappingURL=mediaManager.js.map
