import { p as proxyCustomElement, H, h } from './p-ae373651.js';
import { c as createDefaultConfig, e as defaultIconPack, i as useLanguage } from './p-5b3a7f00.js';
import './p-a83ccdbd.js';
import { S as SyncWithStore } from './p-070aa695.js';
import { d as defineCustomElement$5 } from './p-a3bf84d7.js';
import { d as defineCustomElement$4 } from './p-85587a5c.js';
import { d as defineCustomElement$3 } from './p-3e0452c4.js';
import { d as defineCustomElement$2 } from './p-e6245534.js';
import { d as defineCustomElement$1 } from './p-bece0226.js';

const rtkParticipantsStageQueueCss = ":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-top:var(--rtk-space-2, 8px);display:flex;width:100%;flex-direction:column;font-size:14px}.stage-requested-participants{margin-bottom:var(--rtk-space-8, 32px)}.stage-requested-participants .bulk-actions{display:flex;gap:var(--rtk-space-2, 8px)}.stage-requested-participants .bulk-actions .accept-all-button{--tw-text-opacity:1;color:rgba(var(--rtk-colors-success, 98 165 4) / var(--tw-text-opacity))}.stage-requested-participants .bulk-actions rtk-button{flex:1 1 0%}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);padding:var(--rtk-space-0, 0px)}.waiting-participant{margin-top:var(--rtk-space-2, 8px);margin-bottom:var(--rtk-space-2, 8px);display:flex;align-items:center}.waiting-participant .participant-details{margin-right:auto;display:flex;align-items:center}.waiting-participant .participant-details rtk-avatar{margin-right:var(--rtk-space-2, 8px);height:var(--rtk-space-8, 32px);width:var(--rtk-space-8, 32px);flex-shrink:0;font-size:14px}.waiting-participant .participant-details .name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:rgb(var(--rtk-colors-text-900, 255 255 255 / 0.88))}@media (min-width: 1080px){.waiting-participant .participant-details .name{max-width:var(--rtk-space-40, 160px)}}.waiting-participant .waitlist-controls{display:flex}.waiting-participant .waitlist-controls rtk-button{margin-left:var(--rtk-space-2, 8px);cursor:pointer;border-radius:var(--rtk-border-radius-sm, 4px)}.waiting-participant .waitlist-controls rtk-icon.accept{--tw-text-opacity:1;color:rgba(var(--rtk-colors-success, 98 165 4) / var(--tw-text-opacity))}.waiting-participant .waitlist-controls rtk-icon.deny{--tw-text-opacity:1;color:rgba(var(--rtk-colors-danger, 255 45 45) / var(--tw-text-opacity))}";
const RtkParticipantsStageQueueStyle0 = rtkParticipantsStageQueueCss;

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 RtkParticipantsStaged = /*@__PURE__*/ proxyCustomElement(class RtkParticipantsStaged extends H {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        /** Config */
        this.config = createDefaultConfig();
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** View mode for participants list */
        this.view = 'sidebar';
        /** Language */
        this.t = useLanguage();
        this.stageRequestedParticipants = [];
        this.updateStageRequestedParticipants = () => {
            this.stageRequestedParticipants = this.meeting.participants.joined
                .toArray()
                .filter((p) => p.stageStatus === 'REQUESTED_TO_JOIN_STAGE');
        };
        this.acceptStageRequest = async (p) => {
            const { userId } = p;
            await this.meeting.stage.grantAccess([userId]);
        };
        this.rejectStageRequest = async (p) => {
            const { userId } = p;
            await this.meeting.stage.denyAccess([userId]);
        };
        this.acceptAllStageRequest = async () => {
            await this.meeting.stage.grantAccess(this.stageRequestedParticipants.map((p) => p.userId));
        };
        this.denyAllStageRequest = async () => {
            var _a;
            await ((_a = this.meeting.stage) === null || _a === void 0 ? void 0 : _a.denyAccess(this.stageRequestedParticipants.map((p) => p.userId)));
        };
        this.shouldShowStageRequests = () => {
            return (this.meeting.self.permissions.stageEnabled &&
                this.meeting.self.permissions.acceptStageRequests &&
                this.stageRequestedParticipants.length > 0);
        };
        this.updateRequestList = async (stageRequests) => {
            var _a, _b, _c, _d, _e, _f, _g;
            if (!this.meeting.self.permissions.acceptStageRequests ||
                !this.meeting.self.permissions.stageEnabled) {
                this.stageRequestedParticipants = [];
                return;
            }
            if (this.meeting.meta.viewType === 'LIVESTREAM' ||
                ((_c = (_b = (_a = this.meeting) === null || _a === void 0 ? void 0 : _a.self) === null || _b === void 0 ? void 0 : _b.permissions) === null || _c === void 0 ? void 0 : _c.mediaRoomType) === 'HIVE') {
                if (!stageRequests) {
                    stageRequests = (_f = (_e = (await ((_d = this.meeting.stage) === null || _d === void 0 ? void 0 : _d.getAccessRequests()))) === null || _e === void 0 ? void 0 : _e.stageRequests) !== null && _f !== void 0 ? _f : [];
                }
                /**
                 * NOTE(ishita1805): Temporarily mapping `displayName` to `name` till socket service sends the correct key.
                 */
                this.stageRequestedParticipants = stageRequests.map((p) => {
                    return Object.assign(Object.assign({}, p), { name: p.displayName });
                });
            }
            else {
                this.stageRequestedParticipants = (_g = [
                    this.meeting.self,
                    ...this.meeting.participants.joined.toArray(),
                ]) === null || _g === void 0 ? void 0 : _g.filter((p) => p.stageStatus === 'REQUESTED_TO_JOIN_STAGE');
            }
        };
    }
    connectedCallback() {
        this.meetingChanged(this.meeting);
    }
    disconnectedCallback() {
        var _a;
        const { stage } = this.meeting;
        stage === null || stage === void 0 ? void 0 : stage.removeListener('stageAccessRequestUpdate', this.updateRequestList);
        (_a = this.meeting.participants.joined) === null || _a === void 0 ? void 0 : _a.removeListener('stageStatusUpdate', this.updateStageRequestedParticipants);
    }
    meetingChanged(meeting) {
        var _a;
        if (!meeting)
            return;
        this.updateRequestList();
        meeting.participants.joined.on('stageStatusUpdate', this.updateStageRequestedParticipants);
        (_a = meeting.stage) === null || _a === void 0 ? void 0 : _a.on('stageAccessRequestUpdate', this.updateRequestList);
    }
    render() {
        if (!this.meeting)
            return null;
        if (this.view !== 'sidebar' || !this.shouldShowStageRequests())
            return;
        return (h("div", { class: "stage-requested-participants" }, h("div", { class: "heading-count", part: "staged-heading-count" }, this.t('stage_request.header_title'), " (", this.stageRequestedParticipants.length, ")"), h("ul", { class: "participants", part: "staged-participants" }, this.stageRequestedParticipants.map((participant) => (h("li", { class: "waiting-participant", key: participant.id }, h("div", { class: "participant-details" }, h("rtk-avatar", { participant: participant, size: "sm", iconPack: this.iconPack, t: this.t }), h("p", { class: "name", title: participant.name }, participant.name)), h("div", { class: "waitlist-controls" }, h("rtk-tooltip", { label: this.t('stage_request.deny_request'), variant: "secondary" }, h("rtk-button", { variant: "secondary", kind: "icon", onClick: () => this.rejectStageRequest(participant) }, h("rtk-icon", { class: "deny", icon: this.iconPack.dismiss }))), h("rtk-tooltip", { label: this.t('stage_request.accept_request'), variant: "secondary" }, h("rtk-button", { variant: "secondary", kind: "icon", onClick: () => this.acceptStageRequest(participant) }, h("rtk-icon", { class: "accept", icon: this.iconPack.checkmark })))))))), h("div", { class: "bulk-actions" }, h("rtk-button", { class: "accept-all-button", variant: "secondary", onClick: this.acceptAllStageRequest }, this.t('stage_request.accept_all')), h("rtk-button", { class: "deny-all-button", variant: "danger", onClick: this.denyAllStageRequest }, this.t('stage_request.deny_all')))));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
    static get style() { return RtkParticipantsStageQueueStyle0; }
}, [1, "rtk-participants-stage-queue", {
        "meeting": [16],
        "config": [16],
        "size": [513],
        "iconPack": [16],
        "view": [1],
        "t": [16],
        "stageRequestedParticipants": [32]
    }, undefined, {
        "meeting": ["meetingChanged"]
    }]);
__decorate([
    SyncWithStore()
], RtkParticipantsStaged.prototype, "meeting", void 0);
__decorate([
    SyncWithStore()
], RtkParticipantsStaged.prototype, "config", void 0);
__decorate([
    SyncWithStore()
], RtkParticipantsStaged.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkParticipantsStaged.prototype, "t", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-participants-stage-queue", "rtk-avatar", "rtk-button", "rtk-icon", "rtk-spinner", "rtk-tooltip"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-participants-stage-queue":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkParticipantsStaged);
            }
            break;
        case "rtk-avatar":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "rtk-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "rtk-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "rtk-spinner":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "rtk-tooltip":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { RtkParticipantsStaged as R, defineCustomElement as d };
