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/Content'
            });
            froala_editor_1.default.PLUGINS.linkManager = function linkManager(editor) {
                let inputButton;
                const linkPlugin = froala_editor_1.default.PLUGINS.link(editor);
                const debug = false;
                function _init() {
                    inputButton = new inputButton_1.InputButtonPlugin({
                        name: 'Link Manager',
                        eventName: 'link-library',
                        editor,
                        insert: (link) => {
                            const attrs = {};
                            if (link.id) {
                                attrs['data-content-id'] = link.id;
                            }
                            if (link.target) {
                                attrs.target = '_blank';
                            }
                            linkPlugin.insert(link.url, link.text, attrs);
                        },
                        autoSaveSelection: true,
                        autoRestoreSelection: true,
                        debug
                    });
                    if (debug) {
                        console.log('initialized:', {
                            options: editor.opts.endpoint,
                            instance: this
                        });
                    }
                }
                function onClick() {
                    if (!editor.el) {
                        console.warn('linkManager.onClick(): unable to find element');
                        return;
                    }
                    inputButton.onClick(editor.el, linkPlugin.get());
                }
                return {
                    _init,
                    onClick
                };
            };
            froala_editor_1.default.RegisterCommand('linkManager', {
                title: 'Insert from Link Library',
                undo: false,
                focus: false,
                modal: true,
                callback() {
                    this.linkManager.onClick(undefined, froala_editor_1.default.PLUGINS.link(this).get());
                },
                plugin: 'linkManager',
            }),
                froala_editor_1.default.DefineIcon('linkManager', { NAME: 'folder', SVG_KEY: 'insertLink' }),
                froala_editor_1.default.RegisterCommand('linkManagerEdit', {
                    title: 'Edit Link',
                    undo: false,
                    focus: false,
                    modal: true,
                    callback() {
                        this.linkManager.onClick(undefined, froala_editor_1.default.PLUGINS.link(this).get());
                    },
                    plugin: 'linkManager',
                }),
                froala_editor_1.default.DefineIcon('linkManagerEdit', { NAME: 'edit', SVG_KEY: 'edit' }),
                froala_editor_1.default.DefineIcon('linkManagerInsert', { NAME: 'plus', SVG_KEY: 'add' }),
                froala_editor_1.default.DefineIcon('linkManagerDelete', { NAME: 'trash', SVG_KEY: 'remove' });
            froala_editor_1.default.RegisterQuickInsertButton('link', {
                icon: 'linkManager',
                title: 'Insert from Link Library',
                callback: function linkManagerCallback() {
                    const debug = false;
                    const inputButton = new inputButton_1.InputButtonPlugin({
                        name: 'Link Manager',
                        eventName: 'link-library',
                        editor: this,
                        insert: (link) => {
                            froala_editor_1.default.PLUGINS.link(this).insert(link.url, '', { 'aria-label': link.title });
                        },
                        autoSaveSelection: true,
                        autoRestoreSelection: true,
                        debug
                    });
                    if (!this.el) {
                        console.warn('linkManager.onClick(): unable to find element');
                        return;
                    }
                    inputButton.onClick(this.el);
                },
                undo: true
            });
        }
    };
});

//# sourceMappingURL=linkManager.js.map
