'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index$1 = require('./index-2e5758b6.js');
const uiStore = require('./ui-store-583d205a.js');
const index = require('./index-3f8e5441.js');
const index$2 = require('./index-6f8c1928.js');

const rtkDialogManagerCss = ":host{line-height:initial;font-family:var(--rtk-font-family, sans-serif);font-feature-settings:normal;font-variation-settings:normal}p{margin:var(--rtk-space-0, 0px);padding:var(--rtk-space-0, 0px)}:host{display:block}";
const RtkDialogManagerStyle0 = rtkDialogManagerCss;

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
        r = Reflect.decorate(decorators, target, key, desc);
    else
        for (var i = decorators.length - 1; i >= 0; i--)
            if (d = decorators[i])
                r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const RtkDialogManager = class {
    constructor(hostRef) {
        index$1.registerInstance(this, hostRef);
        this.stateUpdate = index$1.createEvent(this, "rtkStateUpdate", 7);
        /** UI Config */
        this.config = uiStore.createDefaultConfig();
        /** Icon pack */
        this.iconPack = uiStore.defaultIconPack;
        /** Language */
        this.t = uiStore.useLanguage();
        this.updateStoreState = (state, value) => {
            this.stateUpdate.emit({ [state]: value });
        };
        this.cancelJoinStage = async () => {
            var _a, _b, _c;
            if (((_a = this.meeting.stage) === null || _a === void 0 ? void 0 : _a.status) === 'ACCEPTED_TO_JOIN_STAGE') {
                await ((_c = (_b = this.meeting) === null || _b === void 0 ? void 0 : _b.stage) === null || _c === void 0 ? void 0 : _c.leave());
            }
            this.updateStoreState('activeJoinStage', false);
        };
        this.joinStage = async () => {
            await this.meeting.stage.join();
            /** NOTE(ishita1805): We close the modal once the status has changed */
        };
        this.stageStatusUpdateListener = (status) => {
            var _a;
            if (!((_a = this.states) === null || _a === void 0 ? void 0 : _a.activeJoinStage))
                return;
            if (status === 'ON_STAGE')
                this.updateStoreState('activeJoinStage', false);
        };
    }
    connectedCallback() {
        this.meetingChanged(this.meeting);
    }
    disconnectedCallback() {
        var _a;
        (_a = this.meeting.stage) === null || _a === void 0 ? void 0 : _a.removeListener('stageStatusUpdate', this.stageStatusUpdateListener);
    }
    meetingChanged(meeting) {
        if (!meeting)
            return;
        const { stage } = meeting;
        stage === null || stage === void 0 ? void 0 : stage.addListener('stageStatusUpdate', this.stageStatusUpdateListener);
    }
    render() {
        var _a, _b, _c, _d;
        if (!this.meeting) {
            return;
        }
        const defaults = {
            meeting: this.meeting,
            states: this.states,
            config: this.config,
            size: this.size,
            iconPack: this.iconPack,
            t: this.t,
        };
        const states = this.states;
        if ((states === null || states === void 0 ? void 0 : states.image) != null) {
            const image = states.image;
            const onImageClose = () => {
                this.stateUpdate.emit({ image: null });
            };
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, onRtkDialogClose: onImageClose, hideCloseButton: true, iconPack: this.iconPack, t: this.t }, index$1.h(index$2.Render, { element: "rtk-image-viewer", defaults: defaults, props: { image, onClose: onImageClose } }))));
        }
        else if ((states === null || states === void 0 ? void 0 : states.activeSettings) === true) {
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeSettings', false), iconPack: this.iconPack, t: this.t }, index$1.h(index$2.Render, { element: "rtk-settings", defaults: defaults }))));
        }
        else if ((states === null || states === void 0 ? void 0 : states.activeDebugger) === true) {
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeDebugger', false), iconPack: this.iconPack, t: this.t }, index$1.h("rtk-debugger", Object.assign({}, defaults)))));
        }
        else if ((states === null || states === void 0 ? void 0 : states.activeLeaveConfirmation) === true) {
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeLeaveConfirmation', false), iconPack: this.iconPack, t: this.t }, index$1.h("rtk-leave-meeting", Object.assign({}, defaults)))));
        }
        else if (((_a = states === null || states === void 0 ? void 0 : states.activePermissionsMessage) === null || _a === void 0 ? void 0 : _a.enabled) === true) {
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, hideCloseButton: true, iconPack: this.iconPack, t: this.t }, index$1.h("rtk-permissions-message", Object.assign({}, defaults)))));
        }
        else if (((_b = states === null || states === void 0 ? void 0 : states.activeBreakoutRoomsManager) === null || _b === void 0 ? void 0 : _b.active) === true) {
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeBreakoutRoomsManager', {
                    active: false,
                    data: undefined,
                }), iconPack: this.iconPack, t: this.t }, index$1.h("rtk-breakout-rooms-manager", Object.assign({}, defaults)))));
        }
        else if (((_c = states === null || states === void 0 ? void 0 : states.activeConfirmationModal) === null || _c === void 0 ? void 0 : _c.active) === true) {
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeConfirmationModal', false), iconPack: this.iconPack, t: this.t }, index$1.h("rtk-confirmation-modal", Object.assign({}, defaults)))));
        }
        else if (((_d = states === null || states === void 0 ? void 0 : states.activeOverlayModal) === null || _d === void 0 ? void 0 : _d.active) === true) {
            return (index$1.h(index$1.Host, null, index$1.h("rtk-overlay-modal", { meeting: this.meeting, states: this.states, iconPack: this.iconPack, t: this.t })));
        }
        else if (states === null || states === void 0 ? void 0 : states.activeBroadcastMessageModal) {
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeBroadcastMessageModal', false), iconPack: this.iconPack, t: this.t }, index$1.h("rtk-broadcast-message-modal", Object.assign({}, defaults)))));
        }
        else if ((states === null || states === void 0 ? void 0 : states.activeJoinStage) === true) {
            const dataState = {
                title: this.t('stage.join_title'),
                label: {
                    accept: this.t('stage.join_confirm'),
                    reject: this.t('stage.join_cancel'),
                },
                description: this.t('stage.join_summary'),
            };
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, onRtkDialogClose: this.cancelJoinStage, iconPack: this.iconPack, t: this.t }, index$1.h("rtk-join-stage", Object.assign({ dataConfig: dataState, onRtkJoinStage: this.joinStage, onRtkLeaveStage: this.cancelJoinStage }, defaults)))));
        }
        else if ((states === null || states === void 0 ? void 0 : states.activeMuteAllConfirmation) === true) {
            return (index$1.h(index$1.Host, null, index$1.h("rtk-dialog", { open: true, onRtkDialogClose: () => {
                    this.updateStoreState('activeMuteAllConfirmation', false);
                }, iconPack: this.iconPack, t: this.t }, index$1.h("rtk-mute-all-confirmation", Object.assign({}, defaults)))));
        }
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
};
__decorate([
    index.SyncWithStore()
], RtkDialogManager.prototype, "meeting", void 0);
__decorate([
    index.SyncWithStore()
], RtkDialogManager.prototype, "config", void 0);
__decorate([
    index.SyncWithStore()
], RtkDialogManager.prototype, "states", void 0);
__decorate([
    index.SyncWithStore()
], RtkDialogManager.prototype, "iconPack", void 0);
__decorate([
    index.SyncWithStore()
], RtkDialogManager.prototype, "t", void 0);
RtkDialogManager.style = RtkDialogManagerStyle0;

exports.rtk_dialog_manager = RtkDialogManager;
