import { p as proxyCustomElement, H, h, c as Host } from './p-ae373651.js';
import { e as defaultIconPack, i as useLanguage, L as showLivestream } from './p-5b3a7f00.js';
import { S as SyncWithStore } from './p-070aa695.js';
import { d as defineCustomElement$1 } from './p-3e0452c4.js';

const rtkViewerCountCss = ":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;font-size:14px}: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)}:host([variant='embedded']){--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-1000, 8 8 8) / var(--tw-bg-opacity));opacity:0.5;margin-top:var(--rtk-space-1, 4px);margin-left:var(--rtk-space-1, 4px);height:var(--rtk-space-5, 20px);border-radius:var(--rtk-border-radius-sm, 4px);padding-left:var(--rtk-space-2, 8px);padding-right:var(--rtk-space-2, 8px);font-size:12px}:host([variant='embedded']) rtk-icon{height:var(--rtk-space-4, 16px);width:var(--rtk-space-4, 16px)}";
const RtkViewerCountStyle0 = rtkViewerCountCss;

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 RtkViewerCount = /*@__PURE__*/ proxyCustomElement(class RtkViewerCount extends H {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        /** Viewer count variant */
        this.variant = 'primary';
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** Language */
        this.t = useLanguage();
        this.viewerCount = 0;
        this.disconnectMeeting = (meeting) => {
            var _a;
            if (meeting != null && this.countListener != null) {
                (_a = meeting.livestream) === null || _a === void 0 ? void 0 : _a.removeListener('viewerCountUpdate', this.countListener);
            }
        };
    }
    connectedCallback() {
        this.meetingChanged(this.meeting);
    }
    disconnectedCallback() {
        this.disconnectMeeting(this.meeting);
    }
    meetingChanged(meeting, oldMeeting) {
        var _a;
        this.disconnectMeeting(oldMeeting);
        if (meeting != null) {
            this.countListener = () => {
                var _a;
                this.viewerCount = (_a = meeting.livestream) === null || _a === void 0 ? void 0 : _a.viewerCount;
            };
            this.countListener();
            (_a = meeting.livestream) === null || _a === void 0 ? void 0 : _a.addListener('viewerCountUpdate', this.countListener);
        }
    }
    render() {
        if (!showLivestream(this.meeting))
            return h(Host, { "data-hidden": true });
        return (h(Host, { tabIndex: 0, role: "log", "aria-label": `${this.viewerCount} ${this.t('viewers')}` }, h("rtk-icon", { icon: this.iconPack.viewers, tabIndex: -1, "aria-hidden": true, part: "icon" }), this.viewerCount, " ", this.t('viewers')));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
    static get style() { return RtkViewerCountStyle0; }
}, [1, "rtk-viewer-count", {
        "meeting": [16],
        "variant": [513],
        "iconPack": [16],
        "t": [16],
        "viewerCount": [32]
    }, undefined, {
        "meeting": ["meetingChanged"]
    }]);
__decorate([
    SyncWithStore()
], RtkViewerCount.prototype, "meeting", void 0);
__decorate([
    SyncWithStore()
], RtkViewerCount.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkViewerCount.prototype, "t", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-viewer-count", "rtk-icon"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-viewer-count":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkViewerCount);
            }
            break;
        case "rtk-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { RtkViewerCount as R, defineCustomElement as d };
