import { r as registerInstance, d as createEvent, h, F as Fragment, a as Host } from './index-55463a54.js';
import { a as shorten } from './string-068ce30a.js';
import { c as createDefaultConfig, e as defaultIconPack, i as useLanguage, H as gracefulStorage } from './ui-store-76bb0e8e.js';
import { R as Render } from './index-3f51790f.js';
import { S as SyncWithStore } from './index-dafb4b7f.js';
import { g as getJoinErrorInfo } from './join-error-e87be64a.js';

const rtkSetupScreenCss = ":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{box-sizing:border-box;padding:var(--rtk-space-4, 16px);height:100%;min-height:100%;width:100%;display:flex;place-items:center;justify-content:center;--rtk-controlbar-button-background-color:rgb(var(--rtk-colors-background-700, 44 44 44))}.container{width:100%;max-width:1080px;display:flex;align-items:center;justify-content:space-evenly;gap:var(--rtk-space-4, 16px)}.container-tile{display:flex;height:100%;width:100%;max-width:584px;flex-direction:column;gap:var(--rtk-space-2, 8px)}.metadata{display:flex;width:100%;max-width:var(--rtk-space-80, 320px);flex-direction:column;align-items:center;text-align:center}.meeting-title{margin-bottom:var(--rtk-space-4, 16px);text-align:center;font-size:24px;font-weight:500}.join-as{margin:var(--rtk-space-0, 0px);margin-bottom:var(--rtk-space-4, 16px);text-align:center;font-size:16px;letter-spacing:-0.025em;color:rgb(var(--rtk-colors-text-600, 255 255 255 / 0.52));overflow:hidden;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:1}.uneditable-name{margin-bottom:var(--rtk-space-6, 24px)}.uneditable-name .text,.uneditable-name .name{display:inline-block}.uneditable-name .name{font-size:16px;font-weight:500}input{margin-bottom:var(--rtk-space-6, 24px);display:block;height:var(--rtk-space-10, 40px);width:100%;max-width:var(--rtk-space-80, 320px);border-radius:var(--rtk-border-radius-sm, 4px);--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-background-1000, 8 8 8) / var(--tw-bg-opacity));padding-left:var(--rtk-space-3, 12px);padding-right:var(--rtk-space-3, 12px);color:rgb(var(--rtk-colors-text-1000, 255 255 255));box-sizing:border-box;font-size:16px;outline:2px solid transparent;outline-offset:2px;transition-property:color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-duration:150ms}input::-moz-placeholder{color:rgb(var(--rtk-colors-text-600, 255 255 255 / 0.52))}input::placeholder{color:rgb(var(--rtk-colors-text-600, 255 255 255 / 0.52))}input{border:var(--rtk-border-width-sm, 1px) solid rgb(var(--rtk-colors-background-600, 60 60 60))}input:focus{--tw-border-opacity:1;border-color:rgba(var(--rtk-colors-brand-500, 33 96 253) / var(--tw-border-opacity))}rtk-spinner{color:rgb(var(--rtk-colors-text-1000, 255 255 255));--icon-size:var(--rtk-space-8, 32px)}:host([size='sm']) .container,:host([size='md']) .container{height:100%;flex-direction:column;justify-content:space-evenly}:host([size='sm']) .container-tile,:host([size='md']) .container-tile{height:-moz-min-content;height:min-content;flex-direction:column;justify-content:center}rtk-participant-tile{height:auto;width:100%;max-width:584px}.media-selectors{display:flex;flex-direction:column;justify-content:space-between}.media-selectors .row{display:grid;grid-template-columns:repeat(2, minmax(0, 1fr))}.no-network-badge{margin-top:var(--rtk-space-2, 8px);display:flex;width:100%;flex-direction:row;align-items:center;justify-content:flex-start;border-radius:var(--rtk-border-radius-sm, 4px);--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-brand-500, 33 96 253) / var(--tw-bg-opacity));background-color:rgba(var(--rtk-colors-danger, 255 45 45) / 0.1);padding-top:var(--rtk-space-1, 4px);padding-bottom:var(--rtk-space-1, 4px);font-size:12px;color:rgba(var(--rtk-colors-danger, 255 45 45) / 0.75)}.no-network-badge rtk-icon{margin-left:var(--rtk-space-2, 8px);margin-right:var(--rtk-space-2, 8px)}.troubleshoot-link{margin-top:var(--rtk-space-1, 4px);font-size:12px;--tw-text-opacity:1;color:rgba(var(--rtk-colors-brand-400, 53 110 253) / var(--tw-text-opacity));text-decoration-line:underline;text-underline-offset:2px}.troubleshoot-link:hover{--tw-text-opacity:1;color:rgba(var(--rtk-colors-brand-300, 73 124 253) / var(--tw-text-opacity))}.error-code{margin-top:var(--rtk-space-1, 4px);font-size:10px;color:rgb(var(--rtk-colors-text-600, 255 255 255 / 0.52))}";
const RtkSetupScreenStyle0 = rtkSetupScreenCss;

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 RtkSetupScreen = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.stateUpdate = createEvent(this, "rtkStateUpdate", 7);
        /** Config object */
        this.config = createDefaultConfig();
        /** Icon pack */
        this.iconPack = defaultIconPack;
        /** Language */
        this.t = useLanguage();
        this.isJoining = false;
        this.canEditName = true;
        this.canProduceAudio = true;
        this.socketStateUpdate = ({ state }) => {
            this.connectionState = state;
            if (state === 'connected') {
                this.joinError = undefined;
                this.joinErrorCode = undefined;
            }
            if (state === 'failed')
                this.isJoining = false;
        };
        this.join = async () => {
            var _a, _b, _c;
            if (((_a = this.displayName) === null || _a === void 0 ? void 0 : _a.trim()) !== '' && !this.isJoining) {
                if (this.connectionState !== 'connected') {
                    if (this.connectionState) {
                        this.joinError =
                            this.connectionState === 'failed'
                                ? this.t('network.lost_extended')
                                : this.t('network.lost');
                    }
                    return;
                }
                this.isJoining = true;
                this.joinError = undefined;
                this.joinErrorCode = undefined;
                (_b = this.meeting) === null || _b === void 0 ? void 0 : _b.self.setName(this.displayName);
                gracefulStorage.setItem('rtk-display-name', this.displayName);
                try {
                    await ((_c = this.meeting) === null || _c === void 0 ? void 0 : _c.join());
                }
                catch (e) {
                    this.isJoining = false;
                    const { message, code } = getJoinErrorInfo(this.t, e);
                    this.joinError = message;
                    this.joinErrorCode = code;
                }
            }
        };
    }
    connectedCallback() {
        this.meetingChanged(this.meeting);
    }
    disconnectedCallback() {
        this.meeting.meta.removeListener('socketConnectionUpdate', this.socketStateUpdate);
    }
    componentDidLoad() {
        var _a;
        (_a = this.inputEl) === null || _a === void 0 ? void 0 : _a.focus();
    }
    meetingChanged(meeting) {
        var _a, _b, _c;
        if (meeting) {
            this.connectionState = (_a = meeting.meta.socketState) === null || _a === void 0 ? void 0 : _a.state;
            this.canEditName = (_b = meeting.self.permissions.canEditDisplayName) !== null && _b !== void 0 ? _b : true;
            this.displayName = ((_c = meeting.self.name) === null || _c === void 0 ? void 0 : _c.trim()) || (this.canEditName ? '' : 'Participant');
            meeting.meta.addListener('socketConnectionUpdate', this.socketStateUpdate);
        }
    }
    render() {
        var _a, _b, _c, _d, _e, _f;
        if (!this.meeting) {
            return;
        }
        const showSocketError = !!this.connectionState && this.connectionState !== 'connected' && !this.joinError;
        const errorText = this.joinError
            ? this.joinError
            : this.connectionState === 'failed'
                ? this.t('network.lost_extended')
                : this.t('network.lost');
        const disabled = ((_a = this.displayName) === null || _a === void 0 ? void 0 : _a.trim()) === '' || this.connectionState !== 'connected' || this.isJoining;
        const defaults = {
            meeting: this.meeting,
            config: this.config,
            states: this.states,
            size: this.size,
            iconPack: this.iconPack,
            t: this.t,
        };
        const meetingTitle = (_d = (_c = (_b = this.meeting) === null || _b === void 0 ? void 0 : _b.meta) === null || _c === void 0 ? void 0 : _c.meetingTitle) === null || _d === void 0 ? void 0 : _d.trim();
        return (h(Host, null, h("div", { class: "container" }, h("div", { class: 'container-tile' }, h(Render, { element: "rtk-participant-tile", defaults: defaults, props: { participant: (_e = this.meeting) === null || _e === void 0 ? void 0 : _e.self, size: 'md', isPreview: true }, childProps: { participant: (_f = this.meeting) === null || _f === void 0 ? void 0 : _f.self, size: 'md' }, deepProps: true }), h("div", { class: 'media-selectors' }, h("rtk-microphone-selector", Object.assign({}, defaults, { variant: "inline" })), h("rtk-camera-selector", Object.assign({}, defaults, { variant: "inline" })), h("rtk-speaker-selector", Object.assign({}, defaults, { variant: "inline" })))), h("div", { class: "metadata" }, meetingTitle && meetingTitle !== '' && h("div", { class: "meeting-title" }, meetingTitle), this.canEditName ? (h(Fragment, null, h("div", { class: "join-as" }, this.t('setup_screen.join_in_as')), h("input", { placeholder: this.t('setup_screen.your_name'), value: this.displayName, spellcheck: false, autoFocus: true, ref: (el) => {
                this.inputEl = el;
            }, onInput: (e) => {
                this.displayName = e.target.value;
            }, onKeyDown: (e) => {
                if (e.key === 'Enter') {
                    this.join();
                }
            } }))) : (h("div", { class: "uneditable-name" }, h("span", { class: "text" }, this.t('setup_screen.join_in_as'), " "), ' ', h("div", { class: "name" }, shorten(this.displayName, 20)))), h("rtk-button", { size: "lg", kind: "wide", onClick: this.join, disabled: disabled }, this.isJoining ? h("rtk-spinner", { iconPack: this.iconPack }) : this.t('join')), (this.joinError || showSocketError) && (h("div", { class: "no-network-badge", role: "alert" }, h("rtk-icon", { size: "md", variant: "danger", icon: this.iconPack.disconnected }), errorText)), this.meeting && this.joinError && (h("a", { class: "troubleshoot-link", href: `https://test.realtime.cloudflare.com?authToken=${this.meeting.__internals__.authToken}`, target: "_blank", rel: "noopener noreferrer" }, this.t('network.troubleshoot'))), this.joinErrorCode && (h("span", { class: "error-code", part: "error-code" }, this.t('join.error_code'), ": ", this.joinErrorCode))))));
    }
    static get watchers() { return {
        "meeting": ["meetingChanged"]
    }; }
};
__decorate([
    SyncWithStore()
], RtkSetupScreen.prototype, "meeting", void 0);
__decorate([
    SyncWithStore()
], RtkSetupScreen.prototype, "states", void 0);
__decorate([
    SyncWithStore()
], RtkSetupScreen.prototype, "config", void 0);
__decorate([
    SyncWithStore()
], RtkSetupScreen.prototype, "iconPack", void 0);
__decorate([
    SyncWithStore()
], RtkSetupScreen.prototype, "t", void 0);
RtkSetupScreen.style = RtkSetupScreenStyle0;

export { RtkSetupScreen as rtk_setup_screen };
