var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import { ItemOrientation } from '@syncfusion/ej2-ribbon';
import { RibbonGroupBase } from '../ribbon-interfaces';
import { showSpinner, hideSpinner } from '@syncfusion/ej2-popups';
/**
 * Table of Contents group implementation for Reference tab
 * @private
 */
var TableOfContentsGroup = /** @class */ (function (_super) {
    __extends(TableOfContentsGroup, _super);
    /**
     * Constructor for TableOfContentsGroup
     * @param {DocumentEditorContainer} container - DocumentEditorContainer instance
     */
    function TableOfContentsGroup(container) {
        var _this = _super.call(this, container) || this;
        // Constants for IDs
        _this.TOC_BUTTON_ID = '_toc';
        _this.UPDATE_TOC_BUTTON_ID = '_update_toc';
        return _this;
    }
    /**
     * Get the Ribbon items for Table of Contents group
     * @returns {RibbonGroupModel} - Ribbon group model for Table of Contents group
     * @private
     */
    TableOfContentsGroup.prototype.getGroupModel = function () {
        return {
            header: this.localObj.getConstant('Table of Contents'),
            enableGroupOverflow: true,
            overflowHeader: this.localObj.getConstant('Table of Contents'),
            orientation: ItemOrientation.Row,
            collections: [
                {
                    items: [
                        {
                            type: 'Button',
                            keyTip: 'T',
                            buttonSettings: {
                                content: this.localObj.getConstant('Table of Contents'),
                                iconCss: 'e-icons e-de-ctnr-tableofcontent',
                                clicked: this.insertTableOfContents.bind(this)
                            },
                            id: this.ribbonId + this.TOC_BUTTON_ID,
                            ribbonTooltipSettings: {
                                title: this.localObj.getConstant('Table of Contents'),
                                content: 'Insert a table of contents'
                            }
                        },
                        {
                            type: 'Button',
                            keyTip: 'U',
                            disabled: true,
                            buttonSettings: {
                                content: this.localObj.getConstant('Update Table'),
                                iconCss: 'e-icons e-de-ctnr-table-update',
                                clicked: this.updateTocHandler.bind(this)
                            },
                            id: this.ribbonId + this.UPDATE_TOC_BUTTON_ID,
                            ribbonTooltipSettings: {
                                title: this.localObj.getConstant('Update Table'),
                                content: 'Update the table of contents'
                            }
                        }
                    ]
                }
            ]
        };
    };
    /**
     * Insert Table of Contents
     * @returns {void}
     */
    TableOfContentsGroup.prototype.insertTableOfContents = function () {
        var _this = this;
        showSpinner(this.documentEditor.element);
        setTimeout(function () {
            _this.documentEditor.editorModule.insertTableOfContents();
            hideSpinner(_this.documentEditor.element);
        });
    };
    /**
     * Update Table of Contents handler
     * @returns {void}
     */
    TableOfContentsGroup.prototype.updateTocHandler = function () {
        var isReadOnly = this.documentEditor.isReadOnlyMode;
        if (this.documentEditor.selection.isReferenceField() && (!isReadOnly ||
            (isReadOnly && this.documentEditor.documentHelper.protectionType === 'FormFieldsOnly'))) {
            this.documentEditor.selection.updateRefField();
        }
        else if (!isReadOnly) {
            this.documentEditor.editorModule.updateToc();
        }
    };
    /**
     * Update UI based on selection state
     * @returns {void}
     * @private
     */
    TableOfContentsGroup.prototype.updateSelection = function () {
        var isInTocField = this.documentEditor.selection.contextType === 'TableOfContents';
        if (isInTocField) {
            this.container.ribbon.ribbon.enableItem(this.ribbonId + this.UPDATE_TOC_BUTTON_ID);
        }
        else {
            this.container.ribbon.ribbon.disableItem(this.ribbonId + this.UPDATE_TOC_BUTTON_ID);
        }
    };
    return TableOfContentsGroup;
}(RibbonGroupBase));
export { TableOfContentsGroup };
