var _a;
import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Prop } from 'vue-property-decorator';
import { ModulVue } from '../../../utils/vue/vue';
import { ACCORDION_CLOSEST_ELEMENTS } from '../../accordion/accordion';
import { PLUS_NAME, TABLE_GROUP_HEADER_NAME } from '../../component-names';
import { MPlus, MPlusSkin } from '../../plus/plus';
import { getCellAlignmentClass, getTotalColumnsLength, MTableAccordionIconPosition, MTableColspan } from '../responsive-table-commons';
import { MTableGroupMixin } from '../table-group/table-group-mixin';
import WithRender from './table-group-header.html?style=./table-group-header.scss';
var MTableGroupHeader = /** @class */ (function (_super) {
    __extends(MTableGroupHeader, _super);
    function MTableGroupHeader() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.mPlusSkin = MPlusSkin.CurrentColor;
        return _this;
    }
    Object.defineProperty(MTableGroupHeader.prototype, "tabindexEnteteAccordeon", {
        get: function () {
            return !this.as().hasAccordion ||
                this.as().isAccordionDisabled
                ? undefined
                : '0';
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MTableGroupHeader.prototype, "isAccordeonIconPositionRight", {
        get: function () {
            return (this.accordionIconPosition ===
                MTableAccordionIconPosition.Right);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MTableGroupHeader.prototype, "isAccordeonIconPositionLeft", {
        get: function () {
            return (this.accordionIconPosition ===
                MTableAccordionIconPosition.Left);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MTableGroupHeader.prototype, "accordionIconPosition", {
        get: function () {
            if (this.as().hasAccordion &&
                this.as().rowsGroup.accordion.iconPosition &&
                this.as().rowsGroup.accordion.iconPosition ===
                    MTableAccordionIconPosition.Right) {
                return MTableAccordionIconPosition.Right;
            }
            return MTableAccordionIconPosition.Left;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MTableGroupHeader.prototype, "headerLeftPositionStyle", {
        get: function () {
            return {
                left: this.as().firstColumnFixed && this.horizontalScrollOffset
                    ? this.horizontalScrollOffset + "px"
                    : undefined
            };
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MTableGroupHeader.prototype, "headerWithoutCellsStyle", {
        get: function () {
            return {
                left: this.headerLeftPositionStyle.left,
                width: this.tableComponentWidth
            };
        },
        enumerable: false,
        configurable: true
    });
    MTableGroupHeader.prototype.getCellStyle = function (cell, columnIndex) {
        if (cell.colspan
            && columnIndex === 0
            && (cell.colspan === getTotalColumnsLength(this.as().columns)
                || cell.colspan === MTableColspan.AllColumns)) {
            return this.headerWithoutCellsStyle;
        }
        return undefined;
    };
    Object.defineProperty(MTableGroupHeader.prototype, "rowsGroupHeaderClassName", {
        get: function () {
            return this.as().rowsGroup &&
                this.as().rowsGroup.header &&
                this.as().rowsGroup.header.className
                ? this.as().rowsGroup.header
                    .className
                : '';
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MTableGroupHeader.prototype, "firstCellsItem", {
        get: function () {
            return this.as().hasHeaderCell
                ? Object.keys(this.as().rowsGroup.header.cells)[0]
                : '';
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MTableGroupHeader.prototype, "displayAccordionIcon", {
        get: function () {
            return this.as().rowsGroup
                && this.as().rowsGroup.accordion ?
                this.as().rowsGroup.accordion.displayIcon === undefined
                    || Boolean(this.as().rowsGroup.accordion.displayIcon)
                : false;
        },
        enumerable: false,
        configurable: true
    });
    MTableGroupHeader.prototype.displayAccordionIconInCorrectCell = function (columnId, columnIndex) {
        if (!this.displayAccordionIcon) {
            return false;
        }
        var arrayCells = this.as().hasHeaderCell
            ? Object.keys(this.as().rowsGroup.header.cells)
            : [];
        if (this.isAccordeonIconPositionLeft || arrayCells.length <= 1) {
            return columnIndex === 0;
        }
        else {
            return arrayCells[arrayCells.length - 1] === columnId;
        }
    };
    MTableGroupHeader.prototype.toggleAccordeon = function (event) {
        var target = event.target.closest(ACCORDION_CLOSEST_ELEMENTS);
        if (!this.as().hasAccordion ||
            this.as().isAccordionDisabled ||
            Boolean(target)) {
            return;
        }
        this.as().rowsGroup.accordion.open = !this.as().rowsGroup.accordion.open;
        if (event.currentTarget) {
            event.currentTarget.blur();
        }
        if (this.as().rowsGroup.accordion.open) {
            this.as().emitOpenAccordion(this.as().rowsGroup);
        }
        else {
            this.as().emitCloseAccordion(this.as().rowsGroup);
        }
    };
    MTableGroupHeader.prototype.getColspan = function (colspan) {
        return colspan === MTableColspan.AllColumns ? this.as().totalColumnsLength : colspan;
    };
    MTableGroupHeader.prototype.getRowAlignmentClass = function (rowsGroup, column) {
        if (rowsGroup.header && rowsGroup.header.cells && rowsGroup.header.cells[column.name] && rowsGroup.header.cells[column.name].textAlign) {
            return getCellAlignmentClass(rowsGroup.header.cells[column.name].textAlign);
        }
        return getCellAlignmentClass(column.textAlign);
    };
    __decorate([
        Prop({
            default: 0
        })
    ], MTableGroupHeader.prototype, "horizontalScrollOffset", void 0);
    __decorate([
        Prop({
            default: '100%'
        })
    ], MTableGroupHeader.prototype, "tableComponentWidth", void 0);
    MTableGroupHeader = __decorate([
        WithRender,
        Component({
            components: (_a = {},
                _a[PLUS_NAME] = MPlus,
                _a),
            mixins: [MTableGroupMixin]
        })
    ], MTableGroupHeader);
    return MTableGroupHeader;
}(ModulVue));
export { MTableGroupHeader };
var TableGroupHeaderPlugin = {
    install: function (v) {
        v.prototype.$log.debug(TABLE_GROUP_HEADER_NAME, 'plugin.install');
        v.component(TABLE_GROUP_HEADER_NAME, MTableGroupHeader);
    }
};
export default TableGroupHeaderPlugin;
//# sourceMappingURL=table-group-header.js.map