'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 index$2 = require('./index-6f8c1928.js');

const rtkSidebarCss = ":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{margin-right:var(--rtk-space-0, 0px);height:100%;width:100%;max-width:var(--rtk-space-96, 384px);box-sizing:border-box;display:flex;flex-direction:column;--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-1000, 8 8 8) / var(--tw-bg-opacity));border-width:var(--rtk-border-width-sm, 1px);border-style:solid;--tw-border-opacity:1;border-color:rgba(var(--rtk-colors-background-700, 44 44 44) / var(--tw-border-opacity))}:host([view='sidebar']){right:var(--rtk-space-2, 8px);margin-right:var(--rtk-space-4, 16px);overflow:clip;border-radius:var(--rtk-border-radius-lg, 12px);--tw-shadow:0 25px 50px -12px rgb(0 0 0 / 0.25);--tw-shadow-colored:0 25px 50px -12px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);--tw-shadow-color:rgb(var(--rtk-colors-background-900, 26 26 26));--tw-shadow:var(--tw-shadow-colored)}:host([view='full-screen']){top:var(--rtk-space-0, 0px);right:var(--rtk-space-0, 0px);bottom:var(--rtk-space-0, 0px);left:var(--rtk-space-0, 0px);max-width:100%}:host(.floating){position:absolute !important;top:var(--rtk-space-0, 0px);right:var(--rtk-space-0, 0px);bottom:var(--rtk-space-0, 0px);left:var(--rtk-space-0, 0px);left:auto;z-index:50}.pinned-state{position:absolute;right:var(--rtk-space-1, 4px);display:inline-flex;width:var(--rtk-space-2, 8px);justify-content:flex-end}";
const RtkSidebarStyle0 = rtkSidebarCss;

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 RtkSidebar = class {
    constructor(hostRef) {
        index$1.registerInstance(this, hostRef);
        this.stateUpdate = index$1.createEvent(this, "rtkStateUpdate", 7);
        /** Enabled sections in sidebar */
        this.enabledSections = [];
        /** Default section */
        this.defaultSection = 'chat';
        /** Config */
        this.config = uiStore.createDefaultConfig();
        /** Icon pack */
        this.iconPack = uiStore.defaultIconPack;
        /** Language */
        this.t = uiStore.useLanguage();
        /** View type */
        this.view = 'sidebar';
        this.currentTab = this.defaultSection;
        this.isFloating = false;
        this.enablePinning = true;
        this.getTabs = () => {
            if (!this.meeting.self.config) {
                return this.enabledSections;
            }
            return this.enabledSections.filter((section) => !(section.id in this.meeting.self.config.controlBar.elements) ||
                this.meeting.self.config.controlBar.elements[section.id]);
        };
        this.close = () => {
            this.stateUpdate.emit({ activeSidebar: false, sidebar: this.defaultSection });
        };
        this.toggleFloating = () => {
            this.isFloating = !this.isFloating;
        };
    }
    connectedCallback() {
        var _a;
        this.viewChanged(this.view);
        this.statesChanged(this.states);
        this.meetingChanged(this.meeting);
        this.isFloating = ((_a = this.states) === null || _a === void 0 ? void 0 : _a.sidebarFloating) || false;
    }
    disconnectedCallback() {
        var _a, _b;
        (_b = (_a = this.meeting) === null || _a === void 0 ? void 0 : _a.stage) === null || _b === void 0 ? void 0 : _b.removeListener('stageStatusUpdate', this.onStageStatusUpdate);
        this.onStageStatusUpdate = null;
    }
    meetingChanged(meeting) {
        var _a, _b;
        if (!meeting) {
            return;
        }
        this.updateEnabledSections(meeting);
        this.onStageStatusUpdate = (_status) => {
            this.updateEnabledSections(this.meeting);
        };
        (_b = (_a = this.meeting) === null || _a === void 0 ? void 0 : _a.stage) === null || _b === void 0 ? void 0 : _b.on('stageStatusUpdate', this.onStageStatusUpdate);
    }
    statesChanged(s) {
        const states = s;
        if (states === null || states === void 0 ? void 0 : states.sidebar) {
            this.currentTab = states.sidebar;
        }
    }
    viewChanged(view) {
        if (view === 'full-screen') {
            this.enablePinning = false;
        }
        else {
            this.enablePinning = true;
        }
    }
    viewSection(section) {
        this.currentTab = section;
        this.stateUpdate.emit({ activeSidebar: true, sidebar: this.currentTab });
    }
    updateEnabledSections(meeting = this.meeting) {
        const list = [];
        if (sidebar.canViewChat(meeting)) {
            list.push({ id: 'chat', name: this.t('chat') });
        }
        if (sidebar.canViewPolls(meeting)) {
            list.push({ id: 'polls', name: this.t('polls') });
        }
        if (sidebar.canViewParticipants(meeting)) {
            list.push({ id: 'participants', name: this.t('participants') });
        }
        if (sidebar.canViewPlugins(meeting)) {
            list.push({ id: 'plugins', name: this.t('plugins') });
        }
        if (sidebar.canViewAI(meeting)) {
            list.push({ id: 'ai', name: this.t('ai.meeting_ai') });
        }
        this.enabledSections = list;
    }
    render() {
        var _a;
        if (!this.meeting) {
            return null;
        }
        const defaults = {
            meeting: this.meeting,
            config: this.config,
            states: this.states,
            size: this.size,
            t: this.t,
            iconPack: this.iconPack,
        };
        // NOTE(ishita1805): This makes it easier to use the sidebar component in isolation.
        if (((_a = defaults.states) === null || _a === void 0 ? void 0 : _a.activeSidebar) === false || !this.currentTab) {
            return null;
        }
        return (index$1.h(index$1.Host, { class: this.enablePinning ? (this.isFloating ? 'floating' : '') : 'floating' }, index$1.h("rtk-sidebar-ui", { tabs: this.getTabs(), currentTab: this.currentTab, view: this.view, onTabChange: (e) => {
                this.viewSection(e.detail);
            }, onSidebarClose: this.close }, this.enablePinning && (index$1.h("div", { class: "pinned-state", slot: "pinned-state" }, index$1.h("rtk-button", { variant: "ghost", kind: "icon", onClick: this.toggleFloating, "aria-label": this.isFloating ? this.t('pin') : this.t('unpin') }, index$1.h("rtk-icon", { icon: this.isFloating ? this.iconPack.pin : this.iconPack.pin_off })))), defaults.states.sidebar === 'chat' && (index$1.h(index$2.Render, { element: "rtk-chat", defaults: defaults, props: { slot: 'chat' } })), defaults.states.sidebar === 'polls' && index$1.h("rtk-polls", Object.assign({}, defaults, { slot: "polls" })), defaults.states.sidebar === 'participants' && (index$1.h(index$2.Render, { element: "rtk-participants", defaults: defaults, props: { slot: 'participants' } })), defaults.states.sidebar === 'plugins' && index$1.h("rtk-plugins", Object.assign({}, defaults, { slot: "plugins" })), defaults.states.sidebar === 'ai' && index$1.h("rtk-ai", Object.assign({}, defaults, { slot: "ai" })))));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"],
        "states": ["statesChanged"],
        "view": ["viewChanged"]
    }; }
};
__decorate([
    index.SyncWithStore()
], RtkSidebar.prototype, "meeting", void 0);
__decorate([
    index.SyncWithStore()
], RtkSidebar.prototype, "states", void 0);
__decorate([
    index.SyncWithStore()
], RtkSidebar.prototype, "config", void 0);
__decorate([
    index.SyncWithStore()
], RtkSidebar.prototype, "iconPack", void 0);
__decorate([
    index.SyncWithStore()
], RtkSidebar.prototype, "t", void 0);
RtkSidebar.style = RtkSidebarStyle0;

exports.rtk_sidebar = RtkSidebar;
