'use strict';

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

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

const rtkPluginsToggleCss = ":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}:host([data-hidden]){display:none}";
const RtkPluginsToggleStyle0 = rtkPluginsToggleCss;

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 RtkPluginsToggle = class {
    constructor(hostRef) {
        index$1.registerInstance(this, hostRef);
        this.stateUpdate = index$1.createEvent(this, "rtkStateUpdate", 7);
        /** Variant */
        this.variant = 'button';
        /** Icon pack */
        this.iconPack = uiStore.defaultIconPack;
        /** Language */
        this.t = uiStore.useLanguage();
        this.pluginsActive = false;
        this.canViewPlugins = false;
        this.updateCanView = () => {
            this.canViewPlugins = sidebar.canViewPlugins(this.meeting);
        };
    }
    disconnectedCallback() {
        var _a, _b, _c, _d;
        (_b = (_a = this.meeting) === null || _a === void 0 ? void 0 : _a.stage) === null || _b === void 0 ? void 0 : _b.removeListener('stageStatusUpdate', this.updateCanView);
        (_d = (_c = this.meeting) === null || _c === void 0 ? void 0 : _c.self) === null || _d === void 0 ? void 0 : _d.permissions.removeListener('pluginsUpdate', this.updateCanView);
    }
    connectedCallback() {
        this.statesChanged(this.states);
        this.meetingChanged(this.meeting);
    }
    meetingChanged(meeting) {
        var _a, _b;
        if (!meeting)
            return;
        this.canViewPlugins = sidebar.canViewPlugins(meeting);
        (_a = meeting === null || meeting === void 0 ? void 0 : meeting.stage) === null || _a === void 0 ? void 0 : _a.on('stageStatusUpdate', this.updateCanView);
        (_b = meeting === null || meeting === void 0 ? void 0 : meeting.self) === null || _b === void 0 ? void 0 : _b.permissions.addListener('pluginsUpdate', this.updateCanView);
    }
    statesChanged(states) {
        if (states != null) {
            this.pluginsActive = states.activeSidebar === true && states.sidebar === 'plugins';
        }
    }
    togglePlugins() {
        const states = this.states;
        this.pluginsActive = !((states === null || states === void 0 ? void 0 : states.activeSidebar) && (states === null || states === void 0 ? void 0 : states.sidebar) === 'plugins');
        this.stateUpdate.emit({
            activeSidebar: this.pluginsActive,
            sidebar: this.pluginsActive ? 'plugins' : undefined,
            activeMoreMenu: false,
        });
    }
    handlePluginsActiveChange() {
        // Plugins sidebar closed without opening a different sidebar
        if (!this.pluginsActive && !this.states.activeSidebar) {
            this.buttonEl.focus();
        }
    }
    render() {
        if (!this.canViewPlugins)
            return index$1.h(index$1.Host, { "data-hidden": true });
        const text = this.t('plugins');
        return (index$1.h(index$1.Host, { title: text }, index$1.h("rtk-controlbar-button", { ref: (el) => (this.buttonEl = el), part: "controlbar-button", size: this.size, iconPack: this.iconPack, class: { active: this.pluginsActive }, onClick: () => this.togglePlugins(), icon: this.iconPack.rocket, label: text, variant: this.variant })));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"],
        "states": ["statesChanged"],
        "pluginsActive": ["handlePluginsActiveChange"]
    }; }
};
__decorate([
    index.SyncWithStore()
], RtkPluginsToggle.prototype, "meeting", void 0);
__decorate([
    index.SyncWithStore()
], RtkPluginsToggle.prototype, "states", void 0);
__decorate([
    index.SyncWithStore()
], RtkPluginsToggle.prototype, "iconPack", void 0);
__decorate([
    index.SyncWithStore()
], RtkPluginsToggle.prototype, "t", void 0);
RtkPluginsToggle.style = RtkPluginsToggleStyle0;

exports.rtk_plugins_toggle = RtkPluginsToggle;
