var _a;
import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Prop, Watch } from 'vue-property-decorator';
import { MediaQueries } from '../../mixins/media-queries/media-queries';
import { MOpenTrigger, OpenTrigger } from '../../mixins/open-trigger/open-trigger';
import { Enums } from '../../utils/enums/enums';
import { REGEX_CSS_NUMBER_VALUE } from '../../utils/props-validation/props-validation';
import { ModulVue } from '../../utils/vue/vue';
import { POPPER_NAME, POPUP_NAME, SIDEBAR_NAME } from '../component-names';
import { MPopper, MPopperPlacement } from '../popper/popper';
import { MSidebar } from '../sidebar/sidebar';
import WithRender from './popup.html?style=./popup.scss';
var MPopup = /** @class */ (function (_super) {
    __extends(MPopup, _super);
    function MPopup() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.internalOpen = false;
        return _this;
    }
    MPopup.prototype.emitUpdateOpen = function (open) { };
    MPopup.prototype.emitOpen = function () { };
    MPopup.prototype.emitClose = function () { };
    MPopup.prototype.emitPortalMounted = function () { };
    MPopup.prototype.emitPortalAfterOpen = function () { };
    MPopup.prototype.emitPortalAfterClose = function () { };
    MPopup.prototype.onOpenChange = function (open) {
        if (this.disabled) {
            return;
        }
        this.internalOpen = open;
    };
    Object.defineProperty(MPopup.prototype, "popupBody", {
        get: function () {
            return this.$children[0].popupBody;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MPopup.prototype, "propOpenTrigger", {
        get: function () {
            return this.openTrigger; // todo: mobile + hover ??
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MPopup.prototype, "propTrigger", {
        get: function () {
            return this.trigger || this.as().triggerHook || undefined;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MPopup.prototype, "popperOpen", {
        get: function () {
            return !this.isSidebarUsed ? this.internalOpen : false;
        },
        set: function (open) {
            if (this.isSidebarUsed) {
                return;
            }
            this.setOpen(open);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MPopup.prototype, "sideBarOpen", {
        get: function () {
            return this.isSidebarUsed ? this.internalOpen : false;
        },
        set: function (open) {
            if (!this.isSidebarUsed) {
                return;
            }
            this.setOpen(open);
        },
        enumerable: false,
        configurable: true
    });
    MPopup.prototype.update = function () {
        if (!this.isSidebarUsed) { // Pas de popper en mobile
            this.$refs.popper.update();
        }
    };
    Object.defineProperty(MPopup.prototype, "isSidebarUsed", {
        get: function () {
            // Use a sidebar instead when in mobile
            return this.as().isMqMaxS;
        },
        enumerable: false,
        configurable: true
    });
    MPopup.prototype.setOpen = function (open) {
        if (this.disabled) {
            return;
        }
        this.internalOpen = open;
        this.emitUpdateOpen(open);
    };
    __decorate([
        Prop()
    ], MPopup.prototype, "open", void 0);
    __decorate([
        Prop({
            default: MPopperPlacement.Bottom,
            validator: function (value) { return Enums.toValueArray(MPopperPlacement).includes(value); }
        })
    ], MPopup.prototype, "placement", void 0);
    __decorate([
        Prop({ default: MOpenTrigger.Click })
    ], MPopup.prototype, "openTrigger", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "closeOnBackdrop", void 0);
    __decorate([
        Prop({ default: true })
    ], MPopup.prototype, "focusManagement", void 0);
    __decorate([
        Prop({
            default: 'auto',
            validator: function (value) {
                return REGEX_CSS_NUMBER_VALUE.test(value) || value === 'auto';
            }
        })
    ], MPopup.prototype, "width", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "id", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "disabled", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "shadow", void 0);
    __decorate([
        Prop({ default: true })
    ], MPopup.prototype, "padding", void 0);
    __decorate([
        Prop({ default: true })
    ], MPopup.prototype, "paddingHeader", void 0);
    __decorate([
        Prop({ default: true })
    ], MPopup.prototype, "paddingBody", void 0);
    __decorate([
        Prop({ default: true })
    ], MPopup.prototype, "paddingFooter", void 0);
    __decorate([
        Prop({ default: true })
    ], MPopup.prototype, "background", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "beforeEnter", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "enter", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "afterEnter", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "enterCancelled", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "beforeLeave", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "leave", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "afterLeave", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "leaveCancelled", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "desktopOnly", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "className", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "preload", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "trigger", void 0);
    __decorate([
        Prop({ default: true })
    ], MPopup.prototype, "lazy", void 0);
    __decorate([
        Prop()
    ], MPopup.prototype, "sidebarFullHeight", void 0);
    __decorate([
        Emit('update:open')
    ], MPopup.prototype, "emitUpdateOpen", null);
    __decorate([
        Emit('open')
    ], MPopup.prototype, "emitOpen", null);
    __decorate([
        Emit('close')
    ], MPopup.prototype, "emitClose", null);
    __decorate([
        Emit('portal-mounted')
    ], MPopup.prototype, "emitPortalMounted", null);
    __decorate([
        Emit('portal-after-open')
    ], MPopup.prototype, "emitPortalAfterOpen", null);
    __decorate([
        Emit('portal-after-close')
    ], MPopup.prototype, "emitPortalAfterClose", null);
    __decorate([
        Watch('open', { immediate: true })
    ], MPopup.prototype, "onOpenChange", null);
    MPopup = __decorate([
        WithRender,
        Component({
            components: (_a = {},
                _a[POPPER_NAME] = MPopper,
                _a[SIDEBAR_NAME] = MSidebar,
                _a),
            mixins: [MediaQueries, OpenTrigger]
        })
    ], MPopup);
    return MPopup;
}(ModulVue));
export { MPopup };
var PopupPlugin = {
    install: function (v, options) {
        v.component(POPUP_NAME, MPopup);
    }
};
export default PopupPlugin;
//# sourceMappingURL=popup.js.map