import { createElement, L10n, isNullOrUndefined, select, Browser, SanitizeHtmlHelper } from '@syncfusion/ej2-base';
import { Toolbar } from '@syncfusion/ej2-navigations';
import { Button } from '@syncfusion/ej2-buttons';
import { DropDownButton } from '@syncfusion/ej2-splitbuttons';
import { TextElementBox, ElementBox, ImageElementBox, FieldElementBox, TextFormField, DropDownFormField, ParagraphWidget, ChartElementBox } from '../viewer/page';
import { WRowFormat, WCharacterFormat, TextPosition } from '../index';
import { HelperMethods } from '../editor/editor-helper';
import { Dictionary } from '../../base/index';
/**
 * Track changes pane
 */
var TrackChangesPane = /** @class */ (function () {
    function TrackChangesPane(owner, commentReviewPane) {
        this.users = [];
        this.viewTypeitems = [];
        //public revisions: Revision[];
        /**
         * @private
         */
        this.sortedRevisions = [];
        this.noChangesVisibleInternal = true;
        this.enableButtons = true;
        this.owner = owner;
        this.commentReviewPane = commentReviewPane;
        this.locale = new L10n('documenteditor', this.owner.defaultLocale);
        this.locale.setLocale(this.owner.locale);
        this.selectedUser = this.locale.getConstant('All');
        this.selectedType = this.locale.getConstant('All');
        this.initTrackChangePane();
        this.commentReviewPane.reviewTab.items[1].content = this.trackChangeDiv;
        if (!Browser.isIE) {
            this.commentReviewPane.reviewTab.refresh();
        }
        if (this.owner.enableRtl) {
            this.closeButton = createElement('button', {
                className: 'e-de-close-icon e-btn e-flat e-icon-btn', id: 'close',
                attrs: { type: 'button', style: 'position:absolute;top:6px;left:1px' }
            });
        }
        else {
            this.closeButton = createElement('button', {
                className: 'e-de-close-icon e-btn e-flat e-icon-btn', id: 'close',
                attrs: { type: 'button', style: 'position:absolute;top:6px;right:1px' }
            });
        }
        this.closeButton.title = this.locale.getConstant('Close');
        this.closeButton.setAttribute('aria-label', this.locale.getConstant('Close'));
        var closeSpan = createElement('span', { className: 'e-de-op-close-icon e-de-close-icon e-btn-icon e-icons' });
        this.closeButton.appendChild(closeSpan);
        this.commentReviewPane.reviewTab.element.appendChild(this.closeButton);
        this.closeButton.addEventListener('click', this.commentReviewPane.closePane.bind(this.commentReviewPane));
    }
    Object.defineProperty(TrackChangesPane.prototype, "setNoChangesVisibility", {
        get: function () {
            return this.noChangesVisibleInternal;
        },
        set: function (visible) {
            this.isChangesTabVisible = !visible;
            this.noChangeDivElement.style.display = visible ? 'block' : 'none';
            this.noChangesVisibleInternal = visible;
            this.enableDisableToolbarItem(!visible);
            this.commentReviewPane.reviewTab.hideTab(1, visible);
            this.owner.notify('reviewPane', { changes: !visible, comment: this.commentReviewPane.isCommentTabVisible });
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TrackChangesPane.prototype, "currentSelectedRevision", {
        get: function () {
            return this.currentSelectedRevisionInternal;
        },
        set: function (value) {
            var selectedElement = select('.e-de-trckchanges-inner-select', this.changesInfoDiv);
            if (isNullOrUndefined(value)) {
                if (!isNullOrUndefined(selectedElement)) {
                    selectedElement.classList.remove('e-de-trckchanges-inner-select');
                }
            }
            else if (value !== this.currentSelectedRevisionInternal || isNullOrUndefined(selectedElement)) {
                if (selectedElement) {
                    selectedElement.classList.remove('e-de-trckchanges-inner-select');
                }
                var currentChangeView = void 0;
                if (this.changes.length > 0 && this.changes.containsKey(value)) {
                    currentChangeView = this.changes.get(value);
                }
                else if (this.renderedChanges.containsKey(value)) {
                    currentChangeView = this.renderedChanges.get(value);
                }
                if (currentChangeView && !isNullOrUndefined(currentChangeView.singleInnerDiv)) {
                    currentChangeView.singleInnerDiv.classList.add('e-de-trckchanges-inner-select');
                }
            }
            this.currentSelectedRevisionInternal = value;
            selectedElement = select('.e-de-trckchanges-inner-select', this.changesInfoDiv);
            if (!isNullOrUndefined(selectedElement)) {
                selectedElement.parentElement.scrollIntoView({ block: 'nearest' });
            }
        },
        enumerable: true,
        configurable: true
    });
    TrackChangesPane.prototype.initTrackChangePane = function () {
        this.changes = new Dictionary();
        this.owner.revisions.groupedView = new Dictionary();
        this.renderedChanges = new Dictionary();
        this.trackChangeDiv = createElement('div', { className: 'e-de-tc-pane' });
        this.trackChangeDiv.appendChild(this.initPaneHeader());
        this.changesInfoDiv = createElement('div', { id: 'e-de-tc-pane-revision', styles: 'overflow:auto', className: !this.owner.documentEditorSettings.showHiddenMarks ? 'e-de-tc-hide-para-mark' : '' });
        this.trackChangeDiv.appendChild(this.changesInfoDiv);
        this.noChangeDivElement = createElement('div', { styles: 'display:none;', className: 'e-de-tc-no-chng' });
        this.noChangeDivElement.textContent = this.locale.getConstant('No changes');
        this.changesInfoDiv.appendChild(this.noChangeDivElement);
        this.updateTrackChanges();
    };
    /**
     * @private
     * @returns {void}
     */
    TrackChangesPane.prototype.showHiddenParaMark = function () {
        if (!this.owner.documentEditorSettings.showHiddenMarks) {
            if (!this.changesInfoDiv.classList.contains('e-de-tc-hide-para-mark')) {
                this.changesInfoDiv.classList.add('e-de-tc-hide-para-mark');
            }
        }
        else {
            if (this.changesInfoDiv.classList.contains('e-de-tc-hide-para-mark')) {
                this.changesInfoDiv.classList.remove('e-de-tc-hide-para-mark');
            }
        }
    };
    TrackChangesPane.prototype.initPaneHeader = function () {
        var _this = this;
        this.toolbarElement = createElement('div', { className: 'e-de-track-toolbar' });
        // eslint-disable-next-line @typescript-eslint/no-this-alias
        var trackChangesDiv = this;
        var isAngularModal = this.owner.isModalDialog;
        this.toolbar = new Toolbar({
            enableRtl: this.owner.enableRtl,
            items: [
                {
                    text: this.locale.getConstant('User') + ':', cssClass: 'e-de-track-toolbar-overlay', disabled: true
                },
                {
                    template: createElement('div', { id: 'e-de-user-list', attrs: { 'role': 'button' } })
                },
                {
                    type: 'Separator'
                },
                {
                    text: this.locale.getConstant('View') + ':', cssClass: 'e-de-track-toolbar-overlay', disabled: true
                },
                {
                    template: createElement('div', { id: 'e-de-revision-list', attrs: { 'role': 'button' } })
                },
                {
                    prefixIcon: 'e-de-nav-left-arrow e-de-tc-tbr', align: 'Right', cssClass: 'e-de-nvgte-left',
                    tooltipText: this.locale.getConstant('Previous Changes'), click: this.navigatePreviousChanges.bind(this)
                },
                {
                    prefixIcon: 'e-de-nav-right-arrow e-de-tc-tbr', align: 'Right', cssClass: 'e-de-nvgte-right',
                    tooltipText: this.locale.getConstant('Next Changes'), click: this.navigateNextChanges.bind(this)
                },
                {
                    template: createElement('div', { id: 'e-de-menu-option', attrs: { 'role': 'button' } }), align: 'Right', cssClass: 'e-de-tc-tbr',
                    tooltipText: this.locale.getConstant('More Options') + '...'
                }
            ]
        });
        this.toolbar.appendTo(this.toolbarElement);
        var navigateLeftButton = select('.e-de-nvgte-left', this.toolbarElement);
        navigateLeftButton.firstChild.classList.add('e-tc-nvgte');
        var navigateRightButton = select('.e-de-nvgte-right', this.toolbarElement);
        navigateRightButton.firstChild.classList.add('e-tc-nvgte');
        //User list drop down button
        var userButtonEle = select('#e-de-user-list', this.toolbarElement);
        this.userDropDownitems = [{ text: this.locale.getConstant('All') }];
        this.userDropDown = {
            items: this.userDropDownitems,
            cssClass: 'e-de-track-pane-drop-btn e-tc-btn-bg-clr',
            select: this.onUserSelect.bind(this),
            beforeOpen: function (e) {
                trackChangesDiv.onUserOpen(e, this);
            },
            beforeItemRender: function (args) {
                _this.beforeDropDownItemRender(args, _this.selectedUser);
            }
        };
        this.userDropDownButton = new DropDownButton(this.userDropDown);
        this.userDropDownButton.appendTo(userButtonEle);
        this.userDropDownButton.content = this.getSpanView(this.userDropDown.items[0].text, 0);
        //Revision view type drop down button
        var viewTypeEle = select('#e-de-revision-list', this.toolbarElement);
        this.viewTypeitems = [{ text: this.locale.getConstant('All') }, { text: this.locale.getConstant('Inserted') }, { text: this.locale.getConstant('Deleted') }];
        this.viewTypeDropDownButton = new DropDownButton({
            items: this.viewTypeitems,
            cssClass: 'e-de-track-pane-drop-btn e-tc-btn-bg-clr',
            select: this.onTypeSelect.bind(this),
            beforeItemRender: function (args) {
                _this.beforeDropDownItemRender(args, _this.selectedType);
            }
        });
        this.viewTypeDropDownButton.content = this.getSpanView(this.viewTypeitems[0].text, 1);
        this.viewTypeDropDownButton.appendTo(viewTypeEle);
        //More menu option drop down button
        this.menuoptionEle = select('#e-de-menu-option', this.toolbarElement);
        var menuOptions = [{ text: this.locale.getConstant('Accept all') }, { text: this.locale.getConstant('Reject all') }];
        var menuDropDown = {
            items: menuOptions,
            select: this.onMenuSelect.bind(this),
            iconCss: 'e-de-menu-icon',
            cssClass: 'e-caret-hide e-tc-btn-bg-clr',
            beforeOpen: function (e) {
                if (isAngularModal) {
                    var popupEl = e.element.parentElement;
                    var dropDownButtonEl = this.element;
                    trackChangesDiv.owner.movePopupToCdkOverlay(dropDownButtonEl, popupEl);
                }
            }
        };
        this.menuDropDownButton = new DropDownButton(menuDropDown);
        this.menuDropDownButton.appendTo(this.menuoptionEle);
        return this.toolbarElement;
    };
    TrackChangesPane.prototype.beforeDropDownItemRender = function (args, content) {
        args.element.innerHTML = '<span></span>' + args.item.text;
        var span = args.element.children[0];
        if (args.item.text === content) {
            span.style.marginRight = '10px';
            span.style.alignSelf = 'center';
            span.setAttribute('class', 'e-de-selected-item e-icons');
        }
        else {
            args.element.children[0].style.marginRight = '25px';
            args.element.children[0].classList.remove('e-de-selected-item');
        }
    };
    TrackChangesPane.prototype.onUserOpen = function (e, dropdown) {
        var ele = e.element;
        ele.style.maxHeight = '200px';
        ele.style.overflowY = 'auto';
        var isAngularModal = this.owner.isModalDialog;
        if (isAngularModal) {
            var popupEl = e.element.parentElement;
            var buttonEl = dropdown.element;
            this.owner.movePopupToCdkOverlay(buttonEl, popupEl);
        }
    };
    TrackChangesPane.prototype.enableDisableToolbarItem = function (enable) {
        var elements = this.toolbar.element.querySelectorAll('.e-de-tc-tbr');
        if (this.owner && this.owner.viewer) {
            this.toolbar.enableItems(elements[0].parentElement.parentElement, enable);
            this.toolbar.enableItems(elements[1].parentElement.parentElement, enable);
            this.toolbar.enableItems(elements[2], enable);
        }
    };
    TrackChangesPane.prototype.getSpanView = function (value, type) {
        return (type === 0 ? '<span class="e-de-track-span-user">' : '<span class="e-de-track-span-view">') + value + '</span>';
    };
    TrackChangesPane.prototype.onMenuSelect = function (arg) {
        var _this = this;
        var selectedText = arg.item.text;
        if (selectedText.match(this.locale.getConstant('Accept all'))) {
            setTimeout(function () {
                _this.owner.revisionsInternal.handleRevisionCollection(true, _this.sortedRevisions);
            }, 0);
        }
        else if (selectedText.match(this.locale.getConstant('Reject all'))) {
            setTimeout(function () {
                _this.owner.revisionsInternal.handleRevisionCollection(false, _this.sortedRevisions);
                /* eslint-disable */
            }, 0);
        }
        this.updateUsers();
    };
    TrackChangesPane.prototype.onSelection = function (revision) {
        this.currentSelectedRevision = revision;
    };
    TrackChangesPane.prototype.onUserSelect = function (arg) {
        var selectedText = arg.item.text;
        this.selectedUser = selectedText;
        this.userDropDownButton.content = this.getSpanView(selectedText, 0);
        this.sortCollectionToDisplay();
    };
    TrackChangesPane.prototype.onTypeSelect = function (arg) {
        var selectedText = arg.item.text;
        this.selectedType = selectedText;
        this.viewTypeDropDownButton.content = this.getSpanView(selectedText, 1);
        this.sortCollectionToDisplay();
    };
    TrackChangesPane.prototype.updateMenuOptions = function () {
        var revisionType;
        if (this.selectedType !== this.locale.getConstant('All')) {
            revisionType = this.selectedType === this.locale.getConstant('Inserted') ? this.locale.getConstant('Insertion')
                : this.locale.getConstant('Deletion');
        }
        if (this.selectedUser === this.locale.getConstant('All') && this.selectedType === this.locale.getConstant('All')) {
            this.menuDropDownButton.items[0].text = this.locale.getConstant('Accept all') + ' ' + this.locale.getConstant('Changes');
            this.menuDropDownButton.items[1].text = this.locale.getConstant('Reject all') + ' ' + this.locale.getConstant('Changes');
        }
        else if (this.selectedUser === this.locale.getConstant('All') && this.selectedType !== this.locale.getConstant('All')) {
            this.menuDropDownButton.items[0].text = this.locale.getConstant('Accept all') + ' ' + revisionType;
            this.menuDropDownButton.items[1].text = this.locale.getConstant('Reject all') + ' ' + revisionType;
        }
        else if (this.selectedUser !== this.locale.getConstant('All') && this.selectedType === this.locale.getConstant('All')) {
            this.menuDropDownButton.items[0].text = this.locale.getConstant('Accept all') + ' ' + this.locale.getConstant('Changes') +
                ' ' + this.locale.getConstant('By').toLowerCase() + ' ' + this.selectedUser;
            this.menuDropDownButton.items[1].text = this.locale.getConstant('Reject all') + ' ' + this.locale.getConstant('Changes') +
                ' ' + this.locale.getConstant('By').toLowerCase() + ' ' + this.selectedUser;
        }
        else {
            this.menuDropDownButton.items[0].text = this.locale.getConstant('Accept all') + ' ' + revisionType +
                ' ' + this.locale.getConstant('By').toLowerCase() + ' ' + this.selectedUser;
            this.menuDropDownButton.items[1].text = this.locale.getConstant('Reject all') + ' ' + revisionType +
                ' ' + this.locale.getConstant('By').toLowerCase() + ' ' + this.selectedUser;
        }
        if (this.owner.documentHelper.isDocumentProtected || this.owner.isReadOnly) {
            this.menuDropDownButton.disabled = true;
        }
        else {
            this.menuDropDownButton.disabled = false;
        }
    };
    TrackChangesPane.prototype.sortCollectionToDisplay = function () {
        var isRevisionVisible = false;
        this.sortedRevisions.length = 0;
        this.updateMenuOptions();
        for (var i = 0; i < this.owner.revisions.revisions.length; i++) {
            var changes = this.changes.get(this.owner.revisions.revisions[i]);
            var singleChangesDiv = changes.outerSingleDiv;
            if (isNullOrUndefined(singleChangesDiv)) {
                continue;
            }
            if (this.selectedUser === this.locale.getConstant('All') && this.selectedType === this.locale.getConstant('All')) {
                singleChangesDiv.style.display = 'block';
            }
            else if (this.selectedUser === this.locale.getConstant('All') && this.selectedType !== this.locale.getConstant('All')) {
                if (this.locale.getConstant(changes.revisionType) === this.selectedType) {
                    singleChangesDiv.style.display = 'block';
                }
                else {
                    singleChangesDiv.style.display = 'none';
                }
            }
            else if (this.selectedUser !== this.locale.getConstant('All') && this.selectedType === this.locale.getConstant('All')) {
                if (changes.user === this.selectedUser) {
                    singleChangesDiv.style.display = 'block';
                }
                else {
                    singleChangesDiv.style.display = 'none';
                }
            }
            else {
                if (changes.user === this.selectedUser && this.locale.getConstant(changes.revisionType) === this.selectedType) {
                    singleChangesDiv.style.display = 'block';
                }
                else {
                    singleChangesDiv.style.display = 'none';
                }
            }
            if (singleChangesDiv.style.display === 'block') {
                this.sortedRevisions.push(this.owner.revisions.revisions[i]);
            }
            isRevisionVisible = true;
        }
        this.setNoChangesVisibility = !isRevisionVisible;
    };
    TrackChangesPane.prototype.enableDisableButton = function (enableButton, isProtection) {
        this.enableButtons = enableButton;
        if (!isProtection || this.owner.showRevisions) {
            this.updateTrackChanges();
        }
    };
    TrackChangesPane.prototype.isUpdateTrackChanges = function (revisionCount) {
        var isUpdate = false;
        var isNoChangeDiv = false;
        if (!isNullOrUndefined(this.changesInfoDiv)) {
            if (this.changesInfoDiv.childNodes.length === 1 && this.changesInfoDiv.childNodes[0].className == 'e-de-tc-no-chng') {
                isNoChangeDiv = true;
            }
            else {
                if (revisionCount !== this.changesInfoDiv.childNodes.length) {
                    isUpdate = true;
                }
            }
        }
        if ((isNoChangeDiv && this.isChangesTabVisible) || revisionCount > 0) {
            isUpdate = true;
        }
        return isUpdate;
    };
    TrackChangesPane.prototype.updatePendingChangesToView = function () {
        var revision = this.owner.revisions.changes.filter(function (item) { return item.hasChanges; });
        for (var i = 0; i < revision.length; i++) {
            this.updateCurrentTrackChanges(revision[i], true);
            revision[i].hasChanges = false;
        }
    };
    TrackChangesPane.prototype.updateCurrentTrackChanges = function (revision, updateChangeView) {
        if (updateChangeView) {
            var currentChangeView = void 0;
            if (!isNullOrUndefined(revision)) {
                currentChangeView = this.owner.trackChangesPane.changes.get(revision);
            }
            if (!isNullOrUndefined(currentChangeView) && revision.getRange().length > 0) {
                var changesDiv = undefined;
                if (!isNullOrUndefined(currentChangeView.singleInnerDiv)) {
                    changesDiv = currentChangeView.singleInnerDiv.querySelector("#textDiv");
                    while (changesDiv.firstChild) {
                        currentChangeView.removeInnerChilds(changesDiv.firstChild);
                        changesDiv.removeChild(changesDiv.firstChild);
                    }
                }
                currentChangeView.tableElement = undefined;
                currentChangeView.tableWidget = undefined;
                var revisions = this.owner.revisions.groupedView.get(currentChangeView);
                var ranges = [];
                for (var i = 0; i < revisions.length; i++) {
                    ranges = ranges.concat(revisions[i].getRange());
                }
                currentChangeView.layoutElementText(revision, ranges, changesDiv);
            }
            if (!isNullOrUndefined(revision) && revision.getRange().length === 0) {
                this.owner.revisions.remove(revision);
            }
        }
        else {
            revision.hasChanges = true;
        }
    };
    TrackChangesPane.prototype.updateTrackChanges = function (show) {
        if (show || isNullOrUndefined(show)) {
            if (!this.owner.isUpdateTrackChanges) {
                this.renderedChanges.clear();
                this.removeAllChanges();
                this.owner.revisions.groupedView.clear();
            }
            if (!this.enableButtons && !this.menuoptionEle.classList.contains('e-de-overlay')) {
                this.menuoptionEle.classList.add('e-de-overlay');
            }
            else if (this.menuoptionEle.classList.contains('e-de-overlay') && !this.owner.documentHelper.isDocumentProtected && !this.owner.isReadOnly) {
                this.menuoptionEle.classList.remove('e-de-overlay');
            }
            this.isChangesTabVisible = true;
            this.owner.notify('reviewPane', { comment: this.commentReviewPane.isCommentTabVisible, changes: this.isChangesTabVisible });
            for (var i = 0; i < this.owner.revisions.changes.length; i++) {
                var revision = this.owner.revisions.changes[i];
                if (!isNullOrUndefined(this.changes.get(revision))) {
                    continue;
                }
                var previousRevision = this.owner.revisions.checkAndGetPreviousRevisionToCombine(revision);
                if (previousRevision) {
                    var changeSingleView = this.changes.get(previousRevision);
                    var changesDiv = undefined;
                    if (!isNullOrUndefined(changeSingleView.singleInnerDiv)) {
                        changesDiv = changeSingleView.singleInnerDiv.querySelector("#textDiv");
                    }
                    changeSingleView.layoutElementText(revision, revision.getRange(false), changesDiv);
                    this.owner.revisions.groupedView.get(changeSingleView).push(revision);
                    this.changes.add(revision, changeSingleView);
                }
                else {
                    this.addChanges(revision, revision.getRange(false));
                }
            }
            for (var i = 0; i < this.owner.revisions.revisions.length; i++) {
                var revision = this.owner.revisions.revisions[i];
                var currentChangeView = this.changes.get(revision);
                if (!isNullOrUndefined(currentChangeView) && !isNullOrUndefined(currentChangeView.acceptButtonElement) && !isNullOrUndefined(currentChangeView.rejectButtonElement)) {
                    if (!this.enableButtons) {
                        if (!(currentChangeView.acceptButtonElement.classList.contains('e-de-hide-track-btn'))) {
                            currentChangeView.acceptButtonElement.classList.add('e-de-hide-track-btn');
                            currentChangeView.rejectButtonElement.classList.add('e-de-hide-track-btn');
                        }
                    }
                    else if (currentChangeView.acceptButtonElement.classList.contains('e-de-hide-track-btn') && !this.owner.documentHelper.isTrackedOnlyMode) {
                        currentChangeView.acceptButtonElement.classList.remove('e-de-hide-track-btn');
                        currentChangeView.rejectButtonElement.classList.remove('e-de-hide-track-btn');
                    }
                }
            }
            var totalCount = document.getElementsByClassName('e-de-track-chngs-count').length;
            for (var i = 0; i < totalCount; i++) {
                var div = document.getElementsByClassName('e-de-track-chngs-count')[i];
                div.innerHTML = this.locale.getConstant('Changes') + ' ' + (i + 1).toString() +
                    ' ' + this.locale.getConstant('of') + ' ' + totalCount.toString();
            }
            this.sortCollectionToDisplay();
            this.updateUsers();
            if (show) {
                this.currentSelectedRevision = this.currentSelectedRevisionInternal;
                this.updateHeight();
                this.owner.resize();
            }
        }
        else {
            this.currentSelectedRevision = undefined;
        }
    };
    TrackChangesPane.prototype.updateUsers = function () {
        if (!isNullOrUndefined(this.users) && this.users.length > 0) {
            this.userDropDownButton.removeItems(this.users);
            this.users = [];
        }
        for (var i = 0; i < this.owner.revisions.revisions.length; i++) {
            if (!isNullOrUndefined(this.users) && !isNullOrUndefined(this.userDropDownButton) && this.users.indexOf(this.owner.revisions.revisions[i].author) === -1) {
                this.users.push(this.owner.revisions.revisions[i].author);
                this.userDropDownButton.items.push({ text: this.owner.revisions.revisions[i].author });
            }
        }
    };
    TrackChangesPane.prototype.updateHeight = function () {
        var tabHeaderHeight = this.commentReviewPane.reviewTab.getRootElement().getElementsByClassName('e-tab-header')[0].getBoundingClientRect().height;
        this.changesInfoDiv.style.height = this.commentReviewPane.parentPaneElement.clientHeight - this.toolbarElement.clientHeight
            - tabHeaderHeight - 2 + 'px';
    };
    TrackChangesPane.prototype.removeAllChanges = function () {
        while (this.changesInfoDiv.childNodes.length > 1) {
            this.changesInfoDiv.removeChild(this.changesInfoDiv.lastChild);
        }
        // Instead of assigning a new array (e.g., revisions = []), 
        // we reset the existing array's length to 0 to clear it.
        // This is important because `revisions` is a reference to `revisionCollec` inside the handleRevisionCollection method in the trackChanges file.
        // Reassigning a new array would break the reference, causing unexpected behavior like infinite loops.
        this.owner.revisions.revisions.length = 0;
        if (this.changes && this.changes.length > 0) {
            for (var i = 0; i < this.changes.length; i++) {
                var revision = this.changes.keys[i];
                var changesSingleView = this.changes.get(revision);
                changesSingleView.clear();
            }
            this.changes.clear();
        }
    };
    /**
     * @private
     * Updates the date value for the revision
     */
    TrackChangesPane.prototype.setDateInternal = function (revision) {
        var date = revision.date;
        var startTextPosition = new TextPosition(this.owner);
        var endTextPosition = new TextPosition(this.owner);
        this.owner.selection.selectRevision(revision, startTextPosition, endTextPosition);
        var endIndex = this.owner.selectionModule.getAbsolutePositionFromRelativePosition(endTextPosition);
        var currentChangeView;
        if (!isNullOrUndefined(revision)) {
            currentChangeView = this.owner.trackChangesPane.changes.get(revision);
        }
        if (!isNullOrUndefined(currentChangeView)) {
            var dateView = currentChangeView.singleInnerDiv.querySelector('.e-de-track-date');
            dateView.textContent = HelperMethods.getModifiedDate(revision.date);
            this.owner.getRevisionData(endIndex, date);
        }
    };
    /**
     * @private
     */
    TrackChangesPane.prototype.clear = function () {
        this.removeAllChanges();
        this.selectedUser = this.locale.getConstant('All');
        this.userDropDownButton.content = this.getSpanView(this.selectedUser, 0);
        this.selectedType = this.locale.getConstant('All');
        this.viewTypeDropDownButton.content = this.getSpanView(this.selectedType, 1);
        this.currentSelectedRevision = undefined;
    };
    /**
     * @private
     * @returns {void}
     */
    TrackChangesPane.prototype.destroy = function () {
        if (this.changes && this.changes.length > 0) {
            for (var i = 0; i < this.changes.length; i++) {
                var revision = this.changes.keys[i];
                var changesSingleView = this.changes.get(revision);
                changesSingleView.destroy();
            }
            this.changes.clear();
        }
        this.changes = undefined;
        if (this.toolbar) {
            this.toolbar.destroy();
            this.toolbar = undefined;
        }
        if (this.closeButton && this.closeButton.parentElement) {
            this.closeButton.parentElement.removeChild(this.closeButton);
        }
        this.closeButton = undefined;
        if (this.userDropDownButton) {
            this.userDropDownButton.destroy();
            this.userDropDownButton = undefined;
        }
        if (this.menuDropDownButton) {
            this.menuDropDownButton.destroy();
            this.menuDropDownButton = undefined;
        }
        if (this.viewTypeDropDownButton) {
            this.viewTypeDropDownButton.destroy();
            this.viewTypeDropDownButton = undefined;
        }
        if (this.userDropDown) {
            this.userDropDown = undefined;
        }
        if (this.users.length > 0) {
            this.users = [];
            this.users = undefined;
        }
        if (this.trackChangeDiv) {
            this.trackChangeDiv.innerHTML = '';
            if (this.trackChangeDiv.parentElement) {
                this.trackChangeDiv.parentElement.removeChild(this.trackChangeDiv);
            }
        }
        this.trackChangeDiv = undefined;
        if (this.changesInfoDiv) {
            this.changesInfoDiv.innerHTML = '';
            if (this.changesInfoDiv.parentElement) {
                this.changesInfoDiv.parentElement.removeChild(this.changesInfoDiv);
            }
        }
        this.changesInfoDiv = undefined;
        if (this.commentReviewPane) {
            this.commentReviewPane = undefined;
        }
        if (this.renderedChanges) {
            this.renderedChanges.destroy();
            this.renderedChanges = undefined;
        }
        this.currentSelectedRevisionInternal = undefined;
        this.selectedUser = undefined;
        this.selectedType = undefined;
        this.sortedRevisions = [];
        this.sortedRevisions = undefined;
        this.viewTypeitems = [];
        this.viewTypeitems = undefined;
        this.userDropDownitems = [];
        this.userDropDownitems = undefined;
        this.owner.revisions.revisions = [];
        this.owner.revisions.revisions = undefined;
        this.owner = undefined;
    };
    TrackChangesPane.prototype.addChanges = function (revision, groupedRange) {
        var currentChangeView = new ChangesSingleView(this.owner, this);
        this.changesInfoDiv.appendChild(currentChangeView.createSingleChangesDiv(revision));
        if (!this.enableButtons) {
            if (!(currentChangeView.acceptButtonElement.classList.contains('e-de-hide-track-btn'))) {
                currentChangeView.acceptButtonElement.classList.add('e-de-hide-track-btn');
                currentChangeView.rejectButtonElement.classList.add('e-de-hide-track-btn');
            }
        }
        else if (currentChangeView.acceptButtonElement.classList.contains('e-de-hide-track-btn') && !this.owner.documentHelper.isTrackedOnlyMode) {
            currentChangeView.acceptButtonElement.classList.remove('e-de-hide-track-btn');
            currentChangeView.rejectButtonElement.classList.remove('e-de-hide-track-btn');
        }
        this.layoutGroupedRange(revision, groupedRange, currentChangeView);
        this.owner.revisions.revisions.push(revision);
        this.changes.add(revision, currentChangeView);
    };
    TrackChangesPane.prototype.layoutGroupedRange = function (revision, groupedRange, currentChangeView) {
        if (groupedRange.length > 0) {
            if (groupedRange[0] instanceof WRowFormat) {
                var revisions = [];
                for (var i = 0; i < groupedRange.length; i++) {
                    revisions.push(groupedRange[i].getRevision(groupedRange[i].revisionLength - 1));
                    if (i === 0) {
                        var changesDiv = undefined;
                        if (!isNullOrUndefined(currentChangeView.singleInnerDiv)) {
                            changesDiv = currentChangeView.singleInnerDiv.querySelector("#textDiv");
                        }
                        currentChangeView.layoutElementText(revision, groupedRange, changesDiv);
                    }
                    else {
                        currentChangeView.appendRowToTable(groupedRange[i], i);
                        this.changes.add(groupedRange[i].getRevision(groupedRange[i].revisionLength - 1), currentChangeView);
                    }
                }
                this.owner.revisions.groupedView.add(currentChangeView, revisions);
            }
            else {
                var changesDiv = undefined;
                if (!isNullOrUndefined(currentChangeView.singleInnerDiv)) {
                    changesDiv = currentChangeView.singleInnerDiv.querySelector("#textDiv");
                }
                currentChangeView.layoutElementText(revision, groupedRange, changesDiv);
            }
        }
    };
    /**
     * @private
     * @returns {void}
     */
    TrackChangesPane.prototype.navigatePreviousChanges = function () {
        this.revisionNavigateInternal(false);
    };
    /**
     * @private
     * @returns {void}
     */
    TrackChangesPane.prototype.navigateNextChanges = function () {
        this.revisionNavigateInternal(true);
    };
    TrackChangesPane.prototype.revisionNavigateInternal = function (next) {
        var changes = this.owner.revisions.revisions;
        if (!this.currentSelectedRevisionInternal) {
            if (changes.length === 0) {
                return;
            }
            this.currentSelectedRevision = changes[0];
        }
        if (this.currentSelectedRevision) {
            var revisions = changes;
            var revision = this.currentSelectedRevision;
            var index = revisions.indexOf(revision);
            if (next) {
                revision = (index === (revisions.length - 1)) ? revisions[0] : revisions[index + 1];
            }
            else {
                revision = index === 0 ? revisions[revisions.length - 1] : revisions[index - 1];
            }
            this.owner.documentHelper.currentSelectedRevision = revision;
            this.owner.selectionModule.selectRevision(revision);
        }
        this.currentSelectedRevision = this.owner.documentHelper.currentSelectedRevision;
    };
    return TrackChangesPane;
}());
export { TrackChangesPane };
var ChangesSingleView = /** @class */ (function () {
    function ChangesSingleView(owner, trackChangesPane) {
        this.selectRevisionHandler = this.selectRevision.bind(this);
        this.acceptButtonClickHandler = this.acceptButtonClick.bind(this);
        this.rejectButtonClickHandler = this.rejectButtonClick.bind(this);
        this.owner = owner;
        this.locale = new L10n('documenteditor', this.owner.defaultLocale);
        this.locale.setLocale(this.owner.locale);
        this.trackChangesPane = trackChangesPane;
    }
    ChangesSingleView.prototype.updateRevisionIndexAndCount = function (currentIndex, totalCount) {
        this.changesCount.innerHTML = this.locale.getConstant('Changes') + ' ' + currentIndex.toString() +
            ' ' + this.locale.getConstant('of') + ' ' + totalCount.toString();
    };
    ChangesSingleView.prototype.createSingleChangesDiv = function (revision) {
        this.revision = revision;
        this.user = revision.author;
        this.outerSingleDiv = createElement('div', { className: 'e-de-tc-outer' });
        this.singleInnerDiv = createElement('div', { className: 'e-de-trckchanges-inner' });
        this.singleInnerDiv.addEventListener('click', this.selectRevisionHandler);
        this.outerSingleDiv.appendChild(this.singleInnerDiv);
        var userNameTotalDiv = createElement('div', { className: 'e-de-track-usernme-div' });
        var userNameLabel = createElement('div', { className: 'e-de-track-user-nme' });
        if (!isNullOrUndefined(revision.customData) && revision.customData != '' && this.owner.documentEditorSettings.revisionSettings.showCustomDataWithAuthor) {
            userNameLabel.textContent = SanitizeHtmlHelper.sanitize(revision.author) + " [" + revision.customData + "]";
        }
        else {
            userNameLabel.textContent = SanitizeHtmlHelper.sanitize(revision.author);
        }
        if (!isNullOrUndefined(revision.author)) {
            userNameTotalDiv.style.display = 'flex';
            this.owner.documentHelper.getAvatar(userNameTotalDiv, userNameLabel, undefined, revision);
        }
        var revisionTypeLabel = createElement('div');
        if (revision.revisionType === 'Insertion') {
            this.revisionType = 'Inserted';
            revisionTypeLabel.innerHTML = this.locale.getConstant('Inserted').toUpperCase();
            revisionTypeLabel.classList.add('e-de-track-insert');
        }
        else if (revision.revisionType === 'Deletion') {
            this.revisionType = 'Deleted';
            revisionTypeLabel.innerHTML = this.locale.getConstant('Deleted').toUpperCase();
            revisionTypeLabel.classList.add('e-de-track-delete');
        }
        else if (revision.revisionType === 'MoveFrom') {
            this.revisionType = 'MoveFrom';
            revisionTypeLabel.innerHTML = this.locale.getConstant('Move From').toUpperCase();
            revisionTypeLabel.classList.add('e-de-track-delete');
            revisionTypeLabel.style.whiteSpace = 'nowrap';
        }
        else if (revision.revisionType === 'MoveTo') {
            this.revisionType = 'MoveTo';
            revisionTypeLabel.innerHTML = this.locale.getConstant('Move To').toUpperCase();
            revisionTypeLabel.classList.add('e-de-track-insert');
            revisionTypeLabel.style.whiteSpace = 'nowrap';
        }
        userNameTotalDiv.appendChild(revisionTypeLabel);
        this.singleInnerDiv.appendChild(userNameTotalDiv);
        var dateView = createElement('div', {
            className: 'e-de-track-date',
            innerHTML: HelperMethods.getModifiedDate(revision.date)
        });
        this.singleInnerDiv.appendChild(dateView);
        var changesTextDiv = createElement('div', { id: 'textDiv',
            className: 'e-de-track-chngs-text'
        });
        //this.layoutElementText(revision.getRange(), changesTextDiv);
        this.singleInnerDiv.appendChild(changesTextDiv);
        var buttonTotalDiv = createElement('div', {
            styles: 'display:inline-block;width:100%'
        });
        this.singleInnerDiv.appendChild(buttonTotalDiv);
        var buttonDiv = createElement('div', {
            styles: 'float:left;'
        });
        this.acceptButtonElement = createElement('button', { className: 'e-de-track-accept-button' });
        this.acceptButton = new Button({ cssClass: 'e-outline e-success', content: this.locale.getConstant('Accept') });
        this.acceptButtonElement.setAttribute('aria-label', this.locale.getConstant('Accept'));
        buttonDiv.appendChild(this.acceptButtonElement);
        buttonTotalDiv.appendChild(buttonDiv);
        this.acceptButton.appendTo(this.acceptButtonElement);
        if (this.owner.documentHelper.isTrackedOnlyMode) {
            this.acceptButtonElement.classList.add('e-de-hide-track-btn');
        }
        this.acceptButtonElement.addEventListener('click', this.acceptButtonClickHandler);
        buttonDiv = createElement('div', {
            styles: 'float:left;'
        });
        this.rejectButtonElement = createElement('button', { className: 'e-de-track-reject-button' });
        this.rejectButton = new Button({ cssClass: 'e-outline e-danger', content: this.locale.getConstant('Reject') });
        this.rejectButtonElement.setAttribute('aria-label', this.locale.getConstant('Reject'));
        buttonDiv.appendChild(this.rejectButtonElement);
        buttonTotalDiv.appendChild(buttonDiv);
        this.rejectButton.appendTo(this.rejectButtonElement);
        if (this.owner.documentHelper.isTrackedOnlyMode) {
            this.rejectButtonElement.classList.add('e-de-hide-track-btn');
        }
        this.rejectButtonElement.addEventListener('click', this.rejectButtonClickHandler);
        this.changesCount = createElement('div', { className: 'e-de-track-chngs-count', styles: 'float:right;' });
        var currentCount = this.owner.revisions.changes.indexOf(revision) + 1;
        var totalCount = this.owner.revisions.changes.length;
        this.changesCount.innerHTML = this.locale.getConstant('Changes') + ' ' + currentCount.toString() +
            ' ' + this.locale.getConstant('of') + ' ' + totalCount.toString();
        buttonTotalDiv.appendChild(this.changesCount);
        return this.outerSingleDiv;
    };
    /**
     * @private
     */
    ChangesSingleView.prototype.appendRowToTable = function (rowFormat, insertIndex) {
        this.tableElement.insertRow();
        for (var k = 0; k < rowFormat.ownerBase.childWidgets.length; k++) {
            this.tableElement.rows[insertIndex].insertCell();
            this.tableElement.rows[insertIndex].cells[k].classList.add('e-de-tc-tble-cell');
        }
    };
    ChangesSingleView.prototype.selectRevision = function () {
        this.owner.selectionModule.selectRevision(this.revision);
        this.trackChangesPane.onSelection(this.revision);
    };
    ChangesSingleView.prototype.compareAndGetSameTypeRevision = function (currentRevision, revisionToCompare) {
        var revisionType = currentRevision.revisionType;
        for (var i = 0; i < revisionToCompare.length; i++) {
            if (revisionType === revisionToCompare[i].revisionType) {
                return revisionToCompare[i];
            }
        }
        return undefined;
    };
    ChangesSingleView.prototype.layoutElementText = function (revision, range, changesText, skipUpdate) {
        if (changesText) {
            changesText.style.width = '100%';
        }
        var fragment = document.createDocumentFragment();
        var text = '';
        var toSkip = false;
        var isHyperlinkField = false;
        var revisions = [];
        var tocFieldDepth = 0;
        for (var i = 0; i < range.length; i++) {
            var element = range[i];
            var currentRevision = this.compareAndGetSameTypeRevision(revision, element.getAllRevision());
            if (revisions.length === 0 || revisions.indexOf(currentRevision) === -1) {
                revisions.push(currentRevision);
            }
            if (!this.trackChangesPane.changes.containsKey(currentRevision)) {
                this.trackChangesPane.changes.add(currentRevision, this);
            }
            if (!isNullOrUndefined(this.tableElement) && (element instanceof ElementBox || element instanceof WCharacterFormat)) {
                continue;
            }
            if (element instanceof FieldElementBox && element.fieldType === 1) {
                if (tocFieldDepth > 0) {
                    //Need to skip all the elements until tocFieldDepth is equal to zero.
                    tocFieldDepth--;
                    if (tocFieldDepth === 0) {
                        toSkip = false;
                    }
                }
                else {
                    toSkip = false;
                }
                continue;
            }
            // added the condition to skip to get the field result from the field start if the link applied for multiple paragraphs.
            if (element instanceof FieldElementBox && element.fieldType === 0) {
                var fieldCode = this.owner.selectionModule.getFieldCode(element);
                if (fieldCode.match('HYPERLINK ') && range[range.indexOf(element.fieldEnd) - 1] instanceof TextElementBox) {
                    isHyperlinkField = true;
                }
                if (fieldCode.match('TOC ') || fieldCode.match('Toc')) {
                    tocFieldDepth++;
                    //Need to skip the other toc fields if the toc field depth is greater than 1.
                    if (tocFieldDepth > 1) {
                        continue;
                    }
                }
            }
            if (isHyperlinkField && element instanceof FieldElementBox && (element.fieldType === 2 || element.fieldType === 1)) {
                toSkip = false;
                isHyperlinkField = false;
                continue;
            }
            if (toSkip || element instanceof ChartElementBox) {
                continue;
            }
            if (element instanceof FieldElementBox && element.fieldType === 0) {
                toSkip = true;
            }
            if (element instanceof TextElementBox) {
                text += element.text;
            }
            else if (element instanceof FieldElementBox && element.fieldType === 0) {
                var fieldCode = this.owner.selectionModule.getFieldCode(element);
                if (fieldCode.match('TOC ') || fieldCode.match('Toc')) {
                    //The text "<Table of Content>" must be appended only once for the first TOC field.
                    if (tocFieldDepth === 1) {
                        text += '<Table of Content>';
                        fragment.appendChild(this.addSpan(text));
                        text = '';
                    }
                    continue;
                }
                else if ((fieldCode.match('HYPERLINK ') && !isHyperlinkField) || fieldCode.match('MERGEFIELD') || fieldCode.match('FORMTEXT') || fieldCode.match('PAGE ')) {
                    text += this.owner.editorModule.retrieveFieldResultantText(element.fieldEnd);
                }
                else if (element.formFieldData) {
                    var emptyChar = this.owner.documentHelper.textHelper.repeatChar(this.owner.documentHelper.textHelper.getEnSpaceCharacter(), 5);
                    if (text !== '') {
                        fragment.appendChild(this.addSpan(text));
                        text = '';
                    }
                    if (element.formFieldData instanceof TextFormField) {
                        fragment.appendChild(this.addSpan(element.formFieldData.defaultValue === '' ? emptyChar : element.formFieldData.defaultValue, 'e-de-tc-field'));
                    }
                    else if (element.formFieldData instanceof DropDownFormField) {
                        fragment.appendChild(this.addSpan(element.formFieldData.dropdownItems.length > 0 ? element.formFieldData.dropdownItems[0] : emptyChar, 'e-de-tc-field'));
                    }
                    else {
                        fragment.appendChild(this.addSpan(element.formFieldData.checked ? this.owner.editorModule.getCheckBoxText() : String.fromCharCode(9744), 'e-de-tc-field'));
                    }
                }
            }
            else if (element instanceof ImageElementBox) {
                if (text !== '') {
                    fragment.appendChild(this.addSpan(text));
                    text = '';
                }
                var imageEle = createElement('img');
                imageEle.setAttribute('src', this.owner.documentHelper.getImageString(element));
                imageEle.classList.add('e-de-tc-shrink-img');
                fragment.appendChild(imageEle);
            }
            else if (element instanceof WRowFormat) {
                var table = element.ownerBase.ownerTable.getSplitWidgets()[0];
                if (isNullOrUndefined(this.tableElement)) {
                    this.tableWidget = table;
                    this.tableElement = createElement('table');
                    this.tableElement.classList.add('e-de-track-chng-table');
                    this.tableElement.insertRow();
                    for (var i_1 = 0; i_1 < element.ownerBase.childWidgets.length; i_1++) {
                        this.tableElement.rows[0].insertCell();
                        this.tableElement.rows[0].cells[i_1].classList.add('e-de-tc-tble-cell');
                    }
                    fragment.appendChild(this.tableElement);
                }
                else {
                    if (this.tableWidget === table) {
                        this.appendRowToTable(element, this.tableElement.rows.length);
                    }
                }
                //return;
            }
            else if (element instanceof WCharacterFormat) {
                if (text !== '') {
                    fragment.appendChild(this.addSpan(text));
                    text = '';
                }
                var paraMark = '¶';
                if (element.ownerBase instanceof ParagraphWidget && element.ownerBase.isEndsWithPageBreak) {
                    paraMark = '............Page Break............' + paraMark;
                }
                fragment.appendChild(this.addSpan(paraMark, 'e-de-tc-pmark'));
                fragment.appendChild(createElement('br'));
            }
        }
        if (!skipUpdate) {
            this.owner.revisions.groupedView.add(this, revisions);
        }
        fragment.appendChild(this.addSpan(text));
        if (changesText) {
            changesText.appendChild(fragment);
        }
        for (var j = 0; j < revisions.length; j++) {
            this.trackChangesPane.renderedChanges.add(revisions[j], this);
        }
    };
    ChangesSingleView.prototype.addSpan = function (text, cssClass) {
        var span = createElement('span');
        span.textContent = text;
        if (cssClass) {
            span.classList.add(cssClass);
        }
        return span;
    };
    ChangesSingleView.prototype.acceptButtonClick = function () {
        this.revision.accept();
        if (this.owner.enableHeaderAndFooter) {
            this.owner.editorModule.updateHeaderFooterWidget();
        }
    };
    ChangesSingleView.prototype.rejectButtonClick = function () {
        this.revision.reject();
        if (this.owner.enableHeaderAndFooter) {
            this.owner.editorModule.updateHeaderFooterWidget();
        }
    };
    ChangesSingleView.prototype.removeFromParentCollec = function () {
        if (!isNullOrUndefined(this.revision) && this.trackChangesPane.changes.containsKey(this.revision)) {
            this.trackChangesPane.changes.remove(this.revision);
        }
        if (!isNullOrUndefined(this.revision) && this.owner.revisions.revisions.indexOf(this.revision) !== -1) {
            this.owner.revisions.revisions.splice(this.owner.revisions.revisions.indexOf(this.revision), 1);
        }
        if (this.trackChangesPane.changes.length === 0) {
            this.trackChangesPane.setNoChangesVisibility = true;
        }
        this.trackChangesPane.updateUsers();
    };
    /**
     * @private
     */
    ChangesSingleView.prototype.removeInnerChilds = function (element) {
        if (element) {
            while (element.firstChild) {
                if (element.firstChild.childNodes.length > 0) {
                    this.removeInnerChilds(element.firstChild);
                }
                element.removeChild(element.firstChild);
            }
        }
    };
    /**
     * @private
     */
    ChangesSingleView.prototype.removeEvents = function () {
        if (this.outerSingleDiv) {
            this.outerSingleDiv.removeEventListener('click', this.selectRevisionHandler);
        }
        if (this.acceptButtonElement) {
            this.acceptButtonElement.removeEventListener('click', this.acceptButtonClickHandler);
        }
        if (this.rejectButtonElement) {
            this.rejectButtonElement.removeEventListener('click', this.rejectButtonClickHandler);
        }
    };
    /**
     *
     * @private
     */
    ChangesSingleView.prototype.clear = function () {
        this.removeFromParentCollec();
        this.removeEvents();
        this.removeInnerChilds(this.outerSingleDiv);
        if (this.acceptButton) {
            this.acceptButton.destroy();
            this.acceptButton = undefined;
        }
        if (this.rejectButton) {
            this.rejectButton.destroy();
            this.rejectButton = undefined;
        }
        if (this.acceptButtonElement) {
            this.acceptButtonElement.innerHTML = '';
            if (this.acceptButtonElement.parentElement) {
                this.acceptButtonElement.parentElement.removeChild(this.acceptButtonElement);
            }
            this.acceptButtonElement = undefined;
        }
        if (this.rejectButtonElement) {
            this.rejectButtonElement.innerHTML = '';
            if (this.rejectButtonElement.parentElement) {
                this.rejectButtonElement.parentElement.removeChild(this.rejectButtonElement);
            }
            this.rejectButtonElement = undefined;
        }
        if (this.tableElement) {
            this.tableElement.innerHTML = '';
            if (this.tableElement.parentElement) {
                this.tableElement.parentElement.removeChild(this.tableElement);
            }
            this.tableElement = undefined;
        }
        if (this.singleInnerDiv) {
            this.singleInnerDiv.innerHTML = '';
            if (this.singleInnerDiv.parentElement) {
                this.singleInnerDiv.parentElement.removeChild(this.singleInnerDiv);
            }
            this.singleInnerDiv = undefined;
        }
        if (this.outerSingleDiv) {
            this.outerSingleDiv.innerHTML = '';
            if (this.outerSingleDiv.parentElement) {
                this.outerSingleDiv.parentElement.removeChild(this.outerSingleDiv);
            }
            this.outerSingleDiv = undefined;
        }
        this.tableWidget = undefined;
    };
    /**
     * Disposes the internal objects which are maintained.
     * @private
     */
    ChangesSingleView.prototype.destroy = function () {
        this.removeEvents();
        this.removeInnerChilds(this.outerSingleDiv);
        if (this.acceptButton) {
            this.acceptButton.destroy();
            this.acceptButton = undefined;
        }
        if (this.rejectButton) {
            this.rejectButton.destroy();
            this.rejectButton = undefined;
        }
        if (this.acceptButtonElement) {
            this.acceptButtonElement.innerHTML = '';
            if (this.acceptButtonElement.parentElement) {
                this.acceptButtonElement.parentElement.removeChild(this.acceptButtonElement);
            }
            this.acceptButtonElement = undefined;
        }
        if (this.rejectButtonElement) {
            this.rejectButtonElement.innerHTML = '';
            if (this.rejectButtonElement.parentElement) {
                this.rejectButtonElement.parentElement.removeChild(this.rejectButtonElement);
            }
            this.rejectButtonElement = undefined;
        }
        if (this.tableElement) {
            this.tableElement.innerHTML = '';
            if (this.tableElement.parentElement) {
                this.tableElement.parentElement.removeChild(this.tableElement);
            }
            this.tableElement = undefined;
        }
        if (this.singleInnerDiv) {
            this.singleInnerDiv.innerHTML = '';
            if (this.singleInnerDiv.parentElement) {
                this.singleInnerDiv.parentElement.removeChild(this.singleInnerDiv);
            }
            this.singleInnerDiv = undefined;
        }
        if (this.outerSingleDiv) {
            this.outerSingleDiv.innerHTML = '';
            if (this.outerSingleDiv.parentElement) {
                this.outerSingleDiv.parentElement.removeChild(this.outerSingleDiv);
            }
            this.outerSingleDiv = undefined;
        }
        this.revision = undefined;
        this.user = undefined;
        this.revisionType = undefined;
        this.trackChangesPane = undefined;
        this.owner = undefined;
        this.tableWidget = undefined;
    };
    return ChangesSingleView;
}());
export { ChangesSingleView };
