import { r as registerInstance, d as createEvent, h, a as Host } from './index-55463a54.js';
import { c as createDefaultConfig, e as defaultIconPack, i as useLanguage } from './ui-store-76bb0e8e.js';
import { S as SyncWithStore } from './index-dafb4b7f.js';
import { R as Render } from './index-3f51790f.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) {
        registerInstance(this, hostRef);
        this.stateUpdate = createEvent(this, "rtkStateUpdate", 7);
        /** UI Config */
        this.config = createDefaultConfig();
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** Language */
        this.t = 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 (h(Host, null, h("rtk-dialog", { open: true, onRtkDialogClose: onImageClose, hideCloseButton: true, iconPack: this.iconPack, t: this.t }, h(Render, { element: "rtk-image-viewer", defaults: defaults, props: { image, onClose: onImageClose } }))));
        }
        else if ((states === null || states === void 0 ? void 0 : states.activeSettings) === true) {
            return (h(Host, null, h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeSettings', false), iconPack: this.iconPack, t: this.t }, h(Render, { element: "rtk-settings", defaults: defaults }))));
        }
        else if ((states === null || states === void 0 ? void 0 : states.activeDebugger) === true) {
            return (h(Host, null, h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeDebugger', false), iconPack: this.iconPack, t: this.t }, h("rtk-debugger", Object.assign({}, defaults)))));
        }
        else if ((states === null || states === void 0 ? void 0 : states.activeLeaveConfirmation) === true) {
            return (h(Host, null, h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeLeaveConfirmation', false), iconPack: this.iconPack, t: this.t }, 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 (h(Host, null, h("rtk-dialog", { open: true, hideCloseButton: true, iconPack: this.iconPack, t: this.t }, 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 (h(Host, null, h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeBreakoutRoomsManager', {
                    active: false,
                    data: undefined,
                }), iconPack: this.iconPack, t: this.t }, 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 (h(Host, null, h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeConfirmationModal', false), iconPack: this.iconPack, t: this.t }, 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 (h(Host, null, 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 (h(Host, null, h("rtk-dialog", { open: true, onRtkDialogClose: () => this.updateStoreState('activeBroadcastMessageModal', false), iconPack: this.iconPack, t: this.t }, 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 (h(Host, null, h("rtk-dialog", { open: true, onRtkDialogClose: this.cancelJoinStage, iconPack: this.iconPack, t: this.t }, 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 (h(Host, null, h("rtk-dialog", { open: true, onRtkDialogClose: () => {
                    this.updateStoreState('activeMuteAllConfirmation', false);
                }, iconPack: this.iconPack, t: this.t }, h("rtk-mute-all-confirmation", Object.assign({}, defaults)))));
        }
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
};
__decorate([
    SyncWithStore()
], RtkDialogManager.prototype, "meeting", void 0);
__decorate([
    SyncWithStore()
], RtkDialogManager.prototype, "config", void 0);
__decorate([
    SyncWithStore()
], RtkDialogManager.prototype, "states", void 0);
__decorate([
    SyncWithStore()
], RtkDialogManager.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkDialogManager.prototype, "t", void 0);
RtkDialogManager.style = RtkDialogManagerStyle0;

export { RtkDialogManager as rtk_dialog_manager };
