import { p as proxyCustomElement, H, h, c as Host } from './p-ae373651.js';
import { c as createDefaultConfig, e as defaultIconPack, i as useLanguage } from './p-5b3a7f00.js';
import './p-a83ccdbd.js';
import { R as Render } from './p-88bd1053.js';
import { S as SyncWithStore } from './p-070aa695.js';
import { d as defineCustomElement$1 } from './p-d48b4170.js';

const rtkParticipantsStageListCss = ":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:flex;width:100%;flex-direction:column;font-size:14px}.participants-container{margin-bottom:var(--rtk-space-4, 16px);height:100%;width:100%}h3,.heading-count{margin:var(--rtk-space-0, 0px);display:flex;align-items:center;justify-content:center;padding:var(--rtk-space-0, 0px);font-size:16px;font-weight:400;color:rgb(var(--rtk-colors-text-900, 255 255 255 / 0.88));text-align:center}.heading-count{font-size:14px}.participants{margin-top:var(--rtk-space-2, 8px);margin-bottom:var(--rtk-space-0, 0px);padding:var(--rtk-space-0, 0px)}.empty-stage-list{margin-top:var(--rtk-space-4, 16px);margin-bottom:var(--rtk-space-4, 16px);text-align:center;font-size:12px;color:rgb(var(--rtk-colors-text-700, 255 255 255 / 0.64))}rtk-participant{width:100%}";
const RtkParticipantsStageListStyle0 = rtkParticipantsStageListCss;

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 RtkParticipants = /*@__PURE__*/ proxyCustomElement(class RtkParticipants extends H {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        /** Config */
        this.config = createDefaultConfig();
        /** Hide Stage Participants Count Header */
        this.hideHeader = false;
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** View mode for participants list */
        this.view = 'sidebar';
        /** Language */
        this.t = useLanguage();
        /** Search */
        this.search = '';
        this.participants = [];
        this.createParticipantNode = (participant) => {
            const defaults = {
                meeting: this.meeting,
                view: this.view,
                t: this.t,
                config: this.config,
                states: this.states,
                size: this.size,
                iconPack: this.iconPack,
            };
            return (h("div", null, h(Render, { element: "rtk-participant", defaults: defaults, props: { role: 'listitem', participant, key: participant.id }, childProps: Object.assign(Object.assign({}, defaults), { participant, size: this.size }), deepProps: true })));
        };
        this.updateStageList = () => {
            this.getParticipants(this.search);
        };
    }
    connectedCallback() {
        this.meetingChanged(this.meeting);
        this.searchChanged(this.search);
    }
    disconnectedCallback() {
        if (!this.meeting)
            return;
        const { participants, stage } = this.meeting;
        this.participantJoinedListener &&
            this.meeting.participants.joined.removeListener('participantJoined', this.participantJoinedListener);
        this.participantLeftListener &&
            this.meeting.participants.joined.removeListener('participantLeft', this.participantLeftListener);
        participants.joined.removeListener('stageStatusUpdate', this.updateStageList);
        stage === null || stage === void 0 ? void 0 : stage.removeListener('stageStatusUpdate', this.updateStageList);
    }
    meetingChanged(meeting) {
        if (!meeting)
            return;
        this.participantJoinedListener = (participant) => {
            if (participant.stageStatus !== 'ON_STAGE')
                return;
            // Do not append if participant name or id does not match search query
            const lowerCaseSearch = this.search.toLowerCase();
            if (!participant.name.toLowerCase().includes(lowerCaseSearch) ||
                !participant.id.toLowerCase().includes(lowerCaseSearch))
                return;
            this.participants = [
                ...this.participants.filter((p) => p.id !== participant.id),
                participant,
            ];
        };
        this.participantLeftListener = (participant) => {
            this.participants = this.participants.filter((p) => p.id !== participant.id);
        };
        meeting.participants.joined.addListener('participantJoined', this.participantJoinedListener);
        meeting.participants.joined.addListener('participantLeft', this.participantLeftListener);
        this.updateStageList();
        meeting === null || meeting === void 0 ? void 0 : meeting.participants.joined.on('stageStatusUpdate', this.updateStageList);
        meeting === null || meeting === void 0 ? void 0 : meeting.stage.on('stageStatusUpdate', this.updateStageList);
    }
    searchChanged(search) {
        this.getParticipants(search);
    }
    getParticipants(search = this.search) {
        let list = this.meeting.stage.status === 'ON_STAGE' ? [this.meeting.self] : [];
        list = [
            ...list,
            ...this.meeting.participants.joined.toArray().filter((p) => p.stageStatus === 'ON_STAGE'),
        ];
        if (search === '')
            this.participants = list;
        else {
            this.participants = list.filter((p) => { var _a; return ((_a = p.name) !== null && _a !== void 0 ? _a : p.id).toLowerCase().includes(search.toLowerCase()); });
        }
    }
    render() {
        return (h(Host, { key: '1beca8f05d4f78a269317b333a00946ac642af00' }, h("div", { key: '7d54d4187eb8478ddfdc632b42af4875afd1a158', class: "participants-container" }, !this.hideHeader && (h("div", { key: 'ecaa9721738cc020fe4aa1f966d2450f0f9d8e01', class: "heading-count", part: "heading-count" }, this.t('participants'), " (", this.participants.length, ")")), h("rtk-virtualized-participant-list", { key: '8d12273242c1f9081e199fd189060addf28c45a6', items: this.participants, renderItem: this.createParticipantNode, part: "participants", class: "participants", emptyListElement: h("div", { class: "empty-stage-list" }, this.search.length > 0 ? this.t('search.could_not_find') : this.t('search.empty')) }))));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"],
        "search": ["searchChanged"]
    }; }
    static get style() { return RtkParticipantsStageListStyle0; }
}, [1, "rtk-participants-stage-list", {
        "meeting": [16],
        "states": [16],
        "config": [16],
        "size": [513],
        "hideHeader": [4, "hide-header"],
        "iconPack": [16],
        "view": [1],
        "t": [16],
        "search": [1],
        "participants": [32]
    }, undefined, {
        "meeting": ["meetingChanged"],
        "search": ["searchChanged"]
    }]);
__decorate([
    SyncWithStore()
], RtkParticipants.prototype, "meeting", void 0);
__decorate([
    SyncWithStore()
], RtkParticipants.prototype, "states", void 0);
__decorate([
    SyncWithStore()
], RtkParticipants.prototype, "config", void 0);
__decorate([
    SyncWithStore()
], RtkParticipants.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkParticipants.prototype, "t", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-participants-stage-list", "rtk-virtualized-participant-list"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-participants-stage-list":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkParticipants);
            }
            break;
        case "rtk-virtualized-participant-list":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { RtkParticipants as R, defineCustomElement as d };
