var _a;
import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Prop, Watch } from 'vue-property-decorator';
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 = {}));
var COMPONENT_IN_CLOSEST = '.' + BUTTON_GROUP_NAME + ', .' + INPUT_STYLE_NAME + ', .' + CHECKBOX_NAME + ', .' + RADIO_GROUP_NAME + ', .' + RADIO_NAME + ', .' + LINK_NAME + ', .' + INPLACE_EDIT_NAME;
function isAccordionGroup(parent) {
    return parent && 'addAccordion' in parent;
}
var MAccordion = /** @class */ (function (_super) {
    __extends(MAccordion, _super);
    function MAccordion() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.titleMenuOpen = _this.$i18n.translate('m-accordion:open');
        _this.titleMenuClose = _this.$i18n.translate('m-accordion:close');
        _this.uuid = uuid.generate();
        _this.internalPropOpen = false;
        return _this;
    }
    MAccordion.prototype.clickEvent = function (event) {
    };
    Object.defineProperty(MAccordion.prototype, "propDisabled", {
        get: function () {
            return (isAccordionGroup(this.$parent) && this.$parent.disabled) ||
                this.disabled;
        },
        enumerable: true,
        configurable: true
    });
    MAccordion.prototype.created = function () {
        this.internalPropOpen = this.open;
        if (isAccordionGroup(this.$parent)) {
            this.$parent.addAccordion(this);
        }
    };
    MAccordion.prototype.beforeDestroy = function () {
        if (isAccordionGroup(this.$parent)) {
            this.$parent.removeAccordion(this.propId);
        }
    };
    Object.defineProperty(MAccordion.prototype, "propId", {
        get: function () {
            return this.id || this.uuid;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "idBodyWrap", {
        get: function () {
            return this.propId + "-body-wrap";
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "classBody", {
        get: function () {
            return {
                'm--has-padding': this.paddingBody && this.padding
            };
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "propOpen", {
        get: function () {
            return this.internalPropOpen;
        },
        set: function (value) {
            if (value !== this.internalPropOpen) {
                this.internalPropOpen = value;
                this.$emit('update:open', value);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "headerTabindex", {
        get: function () {
            return this.propDisabled || !this.hasContent() ? undefined : 0;
        },
        enumerable: true,
        configurable: true
    });
    MAccordion.prototype.hasContent = function () {
        return !!this.$slots.default;
    };
    Object.defineProperty(MAccordion.prototype, "propSkin", {
        get: function () {
            return isAccordionGroup(this.$parent) ? this.$parent.skin : this.skin;
        },
        enumerable: true,
        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: true,
        configurable: true
    });
    Object.defineProperty(MAccordion.prototype, "hasIconBorder", {
        get: function () {
            if (this.iconBorder) {
                return this.iconBorder;
            }
            return this.propSkin === MAccordionSkin.Light ? true : false;
        },
        enumerable: true,
        configurable: true
    });
    MAccordion.prototype.toggleAccordion = function (event) {
        if (!this.hasContent()) {
            return;
        }
        var target = event.target.closest('[href], [onclick], a, button, input, textarea, radio, ' + COMPONENT_IN_CLOSEST);
        if (!this.propDisabled && !target) {
            var initialState = this.internalPropOpen;
            if (!this.internalPropOpen &&
                isAccordionGroup(this.$parent) &&
                this.$parent.concurrent) {
                this.$parent.closeAllAccordions();
            }
            this.$refs.accordionHeader.blur();
            this.propOpen = !initialState;
            this.clickEvent(event);
        }
    };
    MAccordion.prototype.syncOpenProp = function (val) {
        this.propOpen = val;
    };
    __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 value === MAccordionSkin.Default ||
                    value === MAccordionSkin.Dark ||
                    value === MAccordionSkin.DarkB ||
                    value === MAccordionSkin.Light ||
                    value === MAccordionSkin.Plain;
            }
        })
    ], MAccordion.prototype, "skin", void 0);
    __decorate([
        Prop({
            default: MAccordionIconPosition.Left,
            validator: function (value) {
                return value === MAccordionIconPosition.Left ||
                    value === MAccordionIconPosition.Right;
            }
        })
    ], MAccordion.prototype, "iconPosition", void 0);
    __decorate([
        Prop()
    ], MAccordion.prototype, "iconBorder", void 0);
    __decorate([
        Prop({
            default: MAccordionIconSize.Large,
            validator: function (value) {
                return value === MAccordionIconSize.Small ||
                    value === MAccordionIconSize.Large;
            }
        })
    ], 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([
        Emit('click')
    ], MAccordion.prototype, "clickEvent", null);
    __decorate([
        Watch('open')
    ], MAccordion.prototype, "syncOpenProp", 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, options) {
        v.component(ACCORDION_NAME, MAccordion);
    }
};
export default AccordionPlugin;
//# sourceMappingURL=accordion.js.map