System.register(["./inputButton", "@stratusjs/runtime/stratus", "lodash", "froala-editor"], function (exports_1, context_1) {
    "use strict";
    var inputButton_1, stratus_1, lodash_1, froala_editor_1;
    var __moduleName = context_1 && context_1.id;
    return {
        setters: [
            function (inputButton_1_1) {
                inputButton_1 = inputButton_1_1;
            },
            function (stratus_1_1) {
                stratus_1 = stratus_1_1;
            },
            function (lodash_1_1) {
                lodash_1 = lodash_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 debug = false;
                function _init() {
                    this.uid = lodash_1.uniqueId(`froala_link_manager_`);
                    stratus_1.Stratus.Instances[this.uid] = this;
                    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';
                            }
                            editor.link.insert(link.url, link.text, attrs);
                        },
                        autoSaveSelection: true,
                        autoRestoreSelection: true,
                        debug
                    });
                    this.inputButton = inputButton;
                    this.editor = editor;
                    if (debug) {
                        console.log('initialized:', {
                            options: editor.opts.endpoint,
                            instance: this,
                            inputButton: inputButton.uid,
                        });
                    }
                }
                function onClick(el, data) {
                    if (!editor.el) {
                        console.warn('linkManager.onClick(): unable to find element');
                        return;
                    }
                    const link = editor.link.get();
                    if (debug) {
                        console.log('[linkManager.onClick()]:', link);
                    }
                    inputButton.onClick(editor.el, link);
                }
                return {
                    _init,
                    onClick
                };
            };
            froala_editor_1.default.RegisterCommand('linkManager', {
                title: 'Insert from Link Library',
                undo: false,
                focus: true,
                modal: true,
                refreshOnCallback: false,
                callback() {
                    this.linkManager.onClick();
                },
                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, this.link.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) => {
                            this.link.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
