'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 rtkParticipantCountCss = ":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:inline-flex;height:var(--rtk-space-10, 40px);-webkit-user-select:none;-moz-user-select:none;user-select:none;align-items:center}:host([data-hidden]){display:none}:host([size='sm']){font-size:12px}rtk-icon{margin-right:var(--rtk-space-1, 4px);height:var(--rtk-space-5, 20px);width:var(--rtk-space-5, 20px)}:host([size='sm']) rtk-icon{height:var(--rtk-space-4, 16px);width:var(--rtk-space-4, 16px)}";
const RtkParticipantCountStyle0 = rtkParticipantCountCss;

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 RtkParticipantCount = class {
    constructor(hostRef) {
        index$1.registerInstance(this, hostRef);
        /** Icon pack */
        this.iconPack = uiStore.defaultIconPack;
        /** Language */
        this.t = uiStore.useLanguage();
        this.participantCount = 0;
        this.isViewer = false;
        this.disconnectMeeting = (meeting) => {
            if (meeting != null && this.countListener != null) {
                meeting.participants.joined.removeListener('participantJoined', this.countListener);
                meeting.participants.joined.removeListener('participantLeft', this.countListener);
                (meeting === null || meeting === void 0 ? void 0 : meeting.stage) &&
                    this.stageUpdateListener &&
                    meeting.stage.removeListener('stageStatusUpdate', this.stageUpdateListener);
                meeting.self.removeListener('roomJoined', this.countListener);
            }
        };
    }
    connectedCallback() {
        this.meetingChanged(this.meeting);
    }
    disconnectedCallback() {
        this.disconnectMeeting(this.meeting);
    }
    meetingChanged(meeting, oldMeeting) {
        this.disconnectMeeting(oldMeeting);
        if (meeting != null) {
            this.countListener = () => {
                this.participantCount =
                    meeting.participants.joined.size + (meeting.self.roomJoined ? 1 : 0);
            };
            this.countListener();
            this.isViewer = uiStore.isLiveStreamViewer(this.meeting);
            meeting.participants.joined.addListener('participantJoined', this.countListener);
            meeting.participants.joined.addListener('participantLeft', this.countListener);
            if (meeting === null || meeting === void 0 ? void 0 : meeting.stage) {
                this.stageUpdateListener = () => {
                    this.isViewer = uiStore.isLiveStreamViewer(this.meeting);
                };
                meeting === null || meeting === void 0 ? void 0 : meeting.stage.addListener('stageStatusUpdate', this.stageUpdateListener);
            }
            meeting.self.addListener('roomJoined', this.countListener);
        }
    }
    render() {
        if (this.isViewer)
            return index$1.h(index$1.Host, { "data-hidden": true });
        return (index$1.h(index$1.Host, { tabIndex: 0, role: "log", "aria-label": `${this.participantCount} ${this.t('participants')}` }, index$1.h("rtk-icon", { icon: this.iconPack.people, tabIndex: -1, "aria-hidden": true, part: "icon" }), this.participantCount));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
};
__decorate([
    index.SyncWithStore()
], RtkParticipantCount.prototype, "meeting", void 0);
__decorate([
    index.SyncWithStore()
], RtkParticipantCount.prototype, "iconPack", void 0);
__decorate([
    index.SyncWithStore()
], RtkParticipantCount.prototype, "t", void 0);
RtkParticipantCount.style = RtkParticipantCountStyle0;

exports.rtk_participant_count = RtkParticipantCount;
