var _a;
import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Prop, Ref, Watch } from 'vue-property-decorator';
import { Enums } from '../../utils/enums/enums';
import uuid from '../../utils/uuid/uuid';
import { ModulVue } from '../../utils/vue/vue';
import { ACCORDION_NAME, ACCORDION_TRANSITION_NAME, BUTTON_GROUP_NAME, CHECKBOX_NAME, I18N_NAME, INPLACE_EDIT_NAME, INPUT_STYLE_NAME, LINK_NAME, PLUS_NAME, RADIO_GROUP_NAME, RADIO_NAME } from '../component-names';
import { MI18n } from '../i18n/i18n';
import { MPlus, MPlusSkin } from '../plus/plus';
import { MAccordionTransition } from '../transitions/accordion-transition/accordion-transition';
import WithRender from './accordion.html?style=./accordion.scss';
export var MAccordionSkin;
(function (MAccordionSkin) {
    MAccordionSkin["Default"] = "default";
    MAccordionSkin["Dark"] = "dark";
    MAccordionSkin["DarkB"] = "dark-b";
    MAccordionSkin["Light"] = "light";
    MAccordionSkin["Plain"] = "plain";
})(MAccordionSkin || (MAccordionSkin = {}));
export var MAccordionIconPosition;
(function (MAccordionIconPosition) {
    MAccordionIconPosition["Left"] = "left";
    MAccordionIconPosition["Right"] = "right";
})(MAccordionIconPosition || (MAccordionIconPosition = {}));
export var MAccordionIconSize;
(function (MAccordionIconSize) {
    MAccordionIconSize["Small"] = "small";
    MAccordionIconSize["Large"] = "large";
})(MAccordionIconSize || (MAccordionIconSize = {}));
export var ACCORDION_CLOSEST_ELEMENTS = "[href], [onclick], [for], a, button, input, textarea, radio, ." + BUTTON_GROUP_NAME + ", ." + INPUT_STYLE_NAME + ", ." + CHECKBOX_NAME + ", ." + RADIO_GROUP_NAME + ", ." + RADIO_NAME + ", ." + LINK_NAME + ", ." + INPLACE_EDIT_NAME;
var MAccordion = /** @class */ (function (_super) {
    __extends(MAccordion, _super);
    function MAccordion() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.uuid = uuid.generate();
        _this.internalOpen = false;
        return _this;
    }
    MAccordion.prototype.emitClick = function (event) { };
    MAccordion.prototype.emitUpdateOpen = function (open) { };
    MAccordion.prototype.onOpenChange = function (open) {
        this.internalOpen = open;
    };
    Object.defineProperty(MAccordion.prototype, "propDisabled", {
        get: function () {
            if (!this.internalGroupRef) {
                return false;
            }
            return this.internalGroupRef.disabled || this.disabled;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "propId", {
        get: function () {
            return this.id || this.uuid;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "idBodyWrap", {
        get: function () {
            return this.propId + "-body-wrap";
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "classBody", {
        get: function () {
            return {
                'm--has-padding': this.paddingBody && this.padding
            };
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "propOpen", {
        get: function () {
            return this.internalOpen;
        },
        set: function (open) {
            if (open !== this.internalOpen) {
                this.internalOpen = open;
                this.emitUpdateOpen(open);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "headerTabindex", {
        get: function () {
            return this.propDisabled || !this.hasContent() ? undefined : 0;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "headerAriaLabel", {
        get: function () {
            return !this.propDisabled && this.hasContent() ?
                this.$i18n.translate("m-accordion:" + (this.propOpen ? 'close' : 'open'))
                : undefined;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "isIconPositionLeft", {
        get: function () {
            return this.iconPosition === MAccordionIconPosition.Left;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "isIconSizeLarge", {
        get: function () {
            return this.iconSize === MAccordionIconSize.Large;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "deltaHeight", {
        get: function () {
            switch (this.propSkin) {
                case MAccordionSkin.Default:
                case MAccordionSkin.Dark:
                case MAccordionSkin.DarkB:
                    return 32;
                default:
                    return 0;
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "propSkin", {
        get: function () {
            return this.internalGroupRef ? this.internalGroupRef.skin : this.skin;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "plusSkin", {
        get: function () {
            if (this.skin === MAccordionSkin.DarkB) {
                if (this.propOpen) {
                    return MPlusSkin.CurrentColor;
                }
                else {
                    return MPlusSkin.Light;
                }
            }
            else {
                return MPlusSkin.Default;
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "hasIconBorder", {
        get: function () {
            if (this.iconBorder) {
                return this.iconBorder;
            }
            return this.propSkin === MAccordionSkin.Light;
        },
        enumerable: false,
        configurable: true
    });
    MAccordion.prototype.hasContent = function () {
        return Boolean(this.$slots.default);
    };
    MAccordion.prototype.toggleAccordion = function (event) {
        if (!this.hasContent()) {
            return;
        }
        var target = event.target.closest(ACCORDION_CLOSEST_ELEMENTS);
        if (!this.propDisabled && !target) {
            var initialState = this.internalOpen;
            if (!this.internalOpen &&
                this.internalGroupRef &&
                this.internalGroupRef.concurrent) {
                this.internalGroupRef.closeAllAccordions();
            }
            this.refAccordionHeader.blur();
            this.propOpen = !initialState;
            this.emitClick(event);
        }
    };
    MAccordion.prototype.mounted = function () {
        if (this.internalGroupRef) {
            this.internalGroupRef.addAccordion(this);
        }
    };
    MAccordion.prototype.beforeDestroy = function () {
        if (!this.internalGroupRef) {
            return;
        }
        this.internalGroupRef.removeAccordion(this.propId);
    };
    Object.defineProperty(MAccordion.prototype, "internalGroupRef", {
        get: function () {
            if (this.isParentAccordionGroup()) {
                return this.$parent;
            }
            else if (this.groupRef) {
                return this.groupRef;
            }
        },
        enumerable: false,
        configurable: true
    });
    MAccordion.prototype.isParentAccordionGroup = function () {
        return 'addAccordion' in this.$parent;
    };
    __decorate([
        Prop()
    ], MAccordion.prototype, "groupRef", void 0);
    __decorate([
        Prop()
    ], MAccordion.prototype, "id", void 0);
    __decorate([
        Prop({
            default: false
        })
    ], MAccordion.prototype, "open", void 0);
    __decorate([
        Prop({
            default: false
        })
    ], MAccordion.prototype, "disabled", void 0);
    __decorate([
        Prop({
            default: MAccordionSkin.Default,
            validator: function (value) { return Enums.toValueArray(MAccordionSkin).includes(value); }
        })
    ], MAccordion.prototype, "skin", void 0);
    __decorate([
        Prop({
            default: MAccordionIconPosition.Left,
            validator: function (value) { return Enums.toValueArray(MAccordionIconPosition).includes(value); }
        })
    ], MAccordion.prototype, "iconPosition", void 0);
    __decorate([
        Prop()
    ], MAccordion.prototype, "iconBorder", void 0);
    __decorate([
        Prop({
            default: MAccordionIconSize.Large,
            validator: function (value) { return Enums.toValueArray(MAccordionIconSize).includes(value); }
        })
    ], MAccordion.prototype, "iconSize", void 0);
    __decorate([
        Prop({ default: true })
    ], MAccordion.prototype, "padding", void 0);
    __decorate([
        Prop({ default: true })
    ], MAccordion.prototype, "paddingHeader", void 0);
    __decorate([
        Prop({ default: true })
    ], MAccordion.prototype, "paddingBody", void 0);
    __decorate([
        Prop({ default: false })
    ], MAccordion.prototype, "keepContentAlive", void 0);
    __decorate([
        Ref('accordionHeader')
    ], MAccordion.prototype, "refAccordionHeader", void 0);
    __decorate([
        Emit('click')
    ], MAccordion.prototype, "emitClick", null);
    __decorate([
        Emit('update:open')
    ], MAccordion.prototype, "emitUpdateOpen", null);
    __decorate([
        Watch('open', { immediate: true })
    ], MAccordion.prototype, "onOpenChange", null);
    MAccordion = __decorate([
        WithRender,
        Component({
            components: (_a = {},
                _a[ACCORDION_TRANSITION_NAME] = MAccordionTransition,
                _a[PLUS_NAME] = MPlus,
                _a[I18N_NAME] = MI18n,
                _a)
        })
    ], MAccordion);
    return MAccordion;
}(ModulVue));
export { MAccordion };
var AccordionPlugin = {
    install: function (v) {
        v.component(ACCORDION_NAME, MAccordion);
    }
};
export default AccordionPlugin;
//# sourceMappingURL=accordion.js.map