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

const rtkMicrophoneSelectorCss = ".rtk-select{--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-700, 44 44 44) / var(--tw-bg-opacity));color:rgb(var(--rtk-colors-text-1000, 255 255 255))}.rtk-select:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000)}.rtk-select{display:block;border-radius:var(--rtk-border-radius-sm, 4px);border-width:var(--rtk-border-width-none, 0);border-style:none;-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:var(--rtk-space-3, 12px);font-size:16px;--icon-size:var(--rtk-select-chevron-size, var(--rtk-space-6, 24px));--icon-right-position:var(--rtk-select-chevron-right-position, var(--rtk-space-2, 8px));background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e\");background-position:right var(--icon-right-position) center;background-repeat:no-repeat;background-size:var(--icon-size) var(--icon-size);padding-right:calc(var(--icon-right-position) * 5);width:100%;max-width:100%;text-overflow:ellipsis}.inline .rtk-select{margin-top:var(--rtk-space-1, 4px);width:100%;padding-top:var(--rtk-space-1, 4px);padding-bottom:var(--rtk-space-1, 4px);padding-left:var(--rtk-space-1\\.5, 6px);padding-right:var(--rtk-space-1\\.5, 6px);padding-right:var(--rtk-space-8, 32px);font-size:14px}.row{margin-bottom:var(--rtk-space-2, 8px);display:flex;width:100%;align-items:center;justify-content:space-between;gap:var(--rtk-space-3, 12px)}.group{margin-top:var(--rtk-space-2, 8px);margin-bottom:var(--rtk-space-2, 8px)}.group>*{margin-bottom:var(--rtk-space-2, 8px)}.group>*:last-child{margin-bottom:var(--rtk-space-0, 0px)}.group select{flex:1 1 0%}.inline.group{margin-top:var(--rtk-space-0, 0px);margin-bottom:var(--rtk-space-0\\.5, 2px)}.inline.group>*{margin-bottom:var(--rtk-space-0, 0px)}label{display:flex;-webkit-user-select:none;-moz-user-select:none;user-select:none;align-items:center;gap:var(--rtk-space-1, 4px);font-size:14px}.inline.container{display:flex;align-items:center;justify-content:flex-start;gap:var(--rtk-space-2, 8px);padding-left:var(--rtk-space-2, 8px);padding-right:var(--rtk-space-2, 8px)}";
const RtkMicrophoneSelectorStyle0 = rtkMicrophoneSelectorCss;

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 RtkMicrophoneSelector = /*@__PURE__*/ proxyCustomElement(class RtkMicrophoneSelector extends H {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** variant */
        this.variant = 'full';
        /** Language */
        this.t = useLanguage();
        this.audioinputDevices = [];
        this.canProduceAudio = true;
        this.currentDevices = { audio: undefined };
        this.stageStateListener = () => {
            this.canProduceAudio = this.meeting.self.permissions.canProduceAudio === 'ALLOWED';
        };
        this.deviceListUpdateListener = async () => {
            const devices = await this.meeting.self.getAudioDevices();
            this.audioinputDevices = devices;
        };
        this.deviceUpdateListener = ({ device }) => {
            if (device.kind === 'audioinput') {
                this.currentDevices = {
                    audio: device,
                };
            }
        };
        this.mediaPermissionUpdateListener = async ({ kind, message }) => {
            if (!this.meeting)
                return;
            if (kind === 'audio' && message === 'ACCEPTED') {
                this.audioinputDevices = await this.meeting.self.getAudioDevices();
            }
        };
    }
    connectedCallback() {
        this.meetingChanged(this.meeting);
    }
    disconnectedCallback() {
        var _a, _b, _c, _d, _e;
        (_b = (_a = this.meeting) === null || _a === void 0 ? void 0 : _a.stage) === null || _b === void 0 ? void 0 : _b.removeListener('stageStatusUpdate', this.stageStateListener);
        (_c = this.meeting) === null || _c === void 0 ? void 0 : _c.self.removeListener('deviceListUpdate', this.deviceListUpdateListener);
        (_d = this.meeting) === null || _d === void 0 ? void 0 : _d.self.removeListener('deviceUpdate', this.deviceUpdateListener);
        (_e = this.meeting) === null || _e === void 0 ? void 0 : _e.self.removeListener('mediaPermissionUpdate', this.mediaPermissionUpdateListener);
    }
    meetingChanged(meeting) {
        if (!meeting)
            return;
        writeTask(async () => {
            var _a, _b;
            const { self, stage } = meeting;
            const audioDevices = await meeting.self.getAudioDevices();
            const currentAudioDevice = (_a = meeting.self.getCurrentDevices()) === null || _a === void 0 ? void 0 : _a.audio;
            this.currentDevices = {
                audio: currentAudioDevice,
            };
            this.canProduceAudio = meeting.self.permissions.canProduceAudio === 'ALLOWED';
            stage === null || stage === void 0 ? void 0 : stage.addListener('stageStatusUpdate', this.stageStateListener);
            self.addListener('deviceListUpdate', this.deviceListUpdateListener);
            self.addListener('deviceUpdate', this.deviceUpdateListener);
            self.addListener('mediaPermissionUpdate', this.mediaPermissionUpdateListener);
            if (currentAudioDevice != undefined) {
                this.audioinputDevices = [
                    (_b = audioDevices.find((device) => device.deviceId === currentAudioDevice.deviceId)) !== null && _b !== void 0 ? _b : currentAudioDevice,
                    ...audioDevices.filter((device) => device.deviceId !== currentAudioDevice.deviceId),
                ];
            }
            else {
                this.audioinputDevices = audioDevices;
            }
        });
    }
    setDevice(deviceId) {
        var _a;
        if (isFirefox(this.meeting))
            return;
        const device = this.audioinputDevices.find((d) => d.deviceId === deviceId);
        if (device != null) {
            this.currentDevices = {
                audio: device,
            };
            (_a = this.meeting) === null || _a === void 0 ? void 0 : _a.self.setDevice(device);
        }
    }
    render() {
        if (!this.meeting)
            return null;
        let unnamedMicCount = 0;
        return (h(Host, null, this.canProduceAudio && (h("div", { part: "microphone-selection", class: 'group container ' + this.variant }, h("label", { slot: "label" }, this.variant !== 'inline' && this.t('settings.microphone_input'), h("rtk-icon", { icon: this.iconPack.mic_on, size: "sm" })), h("div", { class: "row" }, h("select", { class: "rtk-select", onChange: (e) => this.setDevice(e.target.value) }, this.audioinputDevices.map(({ deviceId, label }) => {
            var _a;
            return (h("option", { value: deviceId, selected: ((_a = this.currentDevices.audio) === null || _a === void 0 ? void 0 : _a.deviceId) === deviceId }, label || `Microphone ${++unnamedMicCount}`));
        })), h("slot", { name: "indicator" }))))));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
    static get style() { return RtkMicrophoneSelectorStyle0; }
}, [1, "rtk-microphone-selector", {
        "meeting": [16],
        "size": [513],
        "iconPack": [16],
        "variant": [1],
        "t": [16],
        "audioinputDevices": [32],
        "canProduceAudio": [32],
        "currentDevices": [32]
    }, undefined, {
        "meeting": ["meetingChanged"]
    }]);
__decorate([
    SyncWithStore()
], RtkMicrophoneSelector.prototype, "meeting", void 0);
__decorate([
    SyncWithStore()
], RtkMicrophoneSelector.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkMicrophoneSelector.prototype, "t", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["rtk-microphone-selector", "rtk-icon"];
    components.forEach(tagName => { switch (tagName) {
        case "rtk-microphone-selector":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, RtkMicrophoneSelector);
            }
            break;
        case "rtk-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { RtkMicrophoneSelector as R, defineCustomElement as d };
