'use strict';

const uiStore = require('./ui-store-583d205a.js');
const merge = require('./merge-ff059743.js');

/**
 * Extend the default UI Config with your own
 * @param config Your extended UI Config
 * @returns New extended UI Config object
 */
const extendConfig = (config, baseConfig = uiStore.createDefaultConfig()) => {
    let newConfig = Object.assign({}, baseConfig);
    merge.deepMerge(newConfig, config);
    return newConfig;
};
/**
 * Generates a config with older theme value.
 * @param oldConfig Theme object
 * @param toExtend UI Config object to extend the generated config
 * @param options Options for toggling components
 * @returns
 */
const generateConfig = (oldConfig, meeting, toExtend = {}, options = { grid_pagination: true, settings_toggle: true }) => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
    const data = { showSetupScreen: true };
    let logo;
    let meetingElements = ['rtk-stage'];
    let headerChildren = {}, controlBarChildren = {};
    const showSettingsToggle = (options === null || options === void 0 ? void 0 : options.settings_toggle) !== false;
    const showGridPagination = (options === null || options === void 0 ? void 0 : options.grid_pagination) !== false;
    if ((_a = oldConfig.controlBar) === null || _a === void 0 ? void 0 : _a.isEnabled) {
        meetingElements.push('rtk-controlbar');
        const { elements } = oldConfig.controlBar;
        const leftElements = [
            ...(elements.fullscreen ? ['rtk-fullscreen-toggle'] : []),
            ...(showSettingsToggle ? ['rtk-settings-toggle'] : []),
        ];
        const rightElements = [];
        const moreElements = [];
        if (((_b = meeting.participants.pip) === null || _b === void 0 ? void 0 : _b.isSupported()) &&
            ((_d = (_c = meeting.self) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.pipMode) &&
            ((_e = meeting.self.config) === null || _e === void 0 ? void 0 : _e.viewType) !== 'LIVESTREAM') {
            moreElements.push('rtk-pip-toggle');
        }
        if (meeting === null || meeting === void 0 ? void 0 : meeting.self.permissions.canDisableParticipantAudio) {
            moreElements.push('rtk-mute-all-button');
        }
        moreElements.push('rtk-breakout-rooms-toggle');
        if ((_f = meeting.self) === null || _f === void 0 ? void 0 : _f.permissions.canRecord) {
            moreElements.push('rtk-recording-toggle');
        }
        if ((_g = meeting.self.permissions.transcriptionEnabled) !== null && _g !== void 0 ? _g : false) {
            moreElements.push('rtk-caption-toggle');
        }
        if (navigator.product !== 'ReactNative')
            moreElements.push('rtk-debugger-toggle');
        if (uiStore.isLiveStreamHost(meeting)) {
            leftElements.push('rtk-livestream-toggle');
        }
        if (elements.screenshare) {
            leftElements.push('rtk-screen-share-toggle');
        }
        if (elements.chat) {
            rightElements.push('rtk-chat-toggle');
        }
        if (elements.polls) {
            rightElements.push('rtk-polls-toggle');
        }
        if (elements.participants) {
            rightElements.push('rtk-participants-toggle');
        }
        if (elements.plugins) {
            rightElements.push('rtk-plugins-toggle');
        }
        rightElements.push('rtk-ai-toggle');
        // NOTE(ishita1805): No condition as permission check happens within component
        const centerElements = [
            'rtk-mic-toggle',
            'rtk-camera-toggle',
            'rtk-stage-toggle',
            'rtk-leave-button',
        ];
        if (moreElements.length > 0)
            centerElements.push('rtk-more-toggle');
        const allSideElements = leftElements.concat(rightElements).concat(moreElements);
        let hasMobileDrawer = false;
        if (allSideElements.length > 0) {
            hasMobileDrawer = true;
        }
        controlBarChildren = {
            'rtk-controlbar': {
                states: ['activeMoreMenu'],
                children: ['div#controlbar-left', 'div#controlbar-center', 'div#controlbar-right'],
            },
            'div#controlbar-left': leftElements,
            'div#controlbar-center': centerElements,
            'div#controlbar-right': rightElements,
            'rtk-more-toggle': {
                states: ['activeMoreMenu'],
                children: [],
            },
            'rtk-more-toggle.activeMoreMenu': moreElements.map((el) => [
                el,
                { variant: 'horizontal', slot: 'more-elements' },
            ]),
            'rtk-controlbar.sm': ['div#controlbar-mobile'],
            'rtk-controlbar.md': ['div#controlbar-mobile'],
            'rtk-more-toggle.activeMoreMenu.md': allSideElements.map((el) => [
                el,
                { variant: 'horizontal', slot: 'more-elements' },
            ]),
            'rtk-more-toggle.activeMoreMenu.sm': allSideElements.map((el) => [
                el,
                { variant: 'horizontal', slot: 'more-elements' },
            ]),
            'div#controlbar-mobile': [
                'rtk-mic-toggle',
                'rtk-camera-toggle',
                'rtk-stage-toggle',
                ...[hasMobileDrawer && 'rtk-more-toggle'],
                'rtk-leave-button',
            ],
        };
    }
    if ((_h = oldConfig.header) === null || _h === void 0 ? void 0 : _h.isEnabled) {
        meetingElements.unshift('rtk-header');
        const { elements } = oldConfig.header;
        let leftElements = ['rtk-recording-indicator', 'rtk-livestream-indicator'], centerElements = [], rightElements = [];
        if (showGridPagination) {
            rightElements.push('rtk-grid-pagination');
        }
        if (elements.title) {
            centerElements.push('rtk-meeting-title');
        }
        if (typeof elements.logo === 'string' && elements.logo.length > 0) {
            logo = elements.logo;
            leftElements.unshift('rtk-logo');
        }
        if (elements.participantCount) {
            rightElements.push('rtk-participant-count', 'rtk-viewer-count');
        }
        if (elements.timer) {
            rightElements.push('rtk-clock');
        }
        headerChildren = {
            'rtk-header': ['div#header-left', 'div#header-center', 'div#header-right'],
            'rtk-header.sm': { remove: ['div#header-center'] },
            'div#header-left': leftElements,
            'div#header-center': centerElements,
            'div#header-right': rightElements,
            'div#header-left.sm': {
                remove: ['rtk-logo'],
                prepend: ['rtk-meeting-title'],
            },
        };
    }
    meetingElements.push('rtk-participants-audio', 'rtk-dialog-manager');
    let designTokens = {
        logo,
    };
    designTokens = oldConfig.designTokens;
    if (merge.isValidHexColor((_k = (_j = oldConfig === null || oldConfig === void 0 ? void 0 : oldConfig.designTokens) === null || _j === void 0 ? void 0 : _j.colors) === null || _k === void 0 ? void 0 : _k.textOnBrand)) {
        designTokens.colors['text-on-brand'] = (_m = (_l = oldConfig === null || oldConfig === void 0 ? void 0 : oldConfig.designTokens) === null || _l === void 0 ? void 0 : _l.colors) === null || _m === void 0 ? void 0 : _m.textOnBrand;
    }
    if (merge.isValidHexColor((_p = (_o = oldConfig === null || oldConfig === void 0 ? void 0 : oldConfig.designTokens) === null || _o === void 0 ? void 0 : _o.colors) === null || _p === void 0 ? void 0 : _p.videoBg)) {
        designTokens.colors['video-bg'] = (_r = (_q = oldConfig === null || oldConfig === void 0 ? void 0 : oldConfig.designTokens) === null || _q === void 0 ? void 0 : _q.colors) === null || _r === void 0 ? void 0 : _r.videoBg;
    }
    let config = {
        designTokens,
        styles: {
            'rtk-header': {
                display: 'grid',
                height: '48px',
                gridTemplateColumns: 'repeat(3, 1fr)',
                gridTemplateRows: '1fr',
                alignItems: 'center',
                '--header-section-gap': 'var(--rtk-space-2, 8px)',
            },
            'rtk-header.sm': {
                display: 'grid',
                gridArea: 'header',
                gridTemplateColumns: 'repeat(2, 1fr)',
                gridTemplateRows: '1fr',
                alignItems: 'center',
                '--header-section-gap': 'var(--rtk-space-1, 4px)',
            },
            'div#header-left': {
                display: 'flex',
                alignItems: 'center',
                height: '48px',
                wordBreak: 'break-all',
                gap: 'var(--header-section-gap)',
            },
            'rtk-logo': {
                height: '26px',
            },
            'div#header-center': {
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'center',
                wordBreak: 'break-all',
                gap: 'var(--header-section-gap)',
                paddingInline: 'var(--rtk-space-3, 12px)',
            },
            'div#header-right': {
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'flex-end',
                gap: 'var(--header-section-gap)',
            },
            'rtk-stage': {
                display: 'flex',
                flex: '1',
            },
            'rtk-grid': {
                flex: '1',
                height: 'auto',
            },
            'rtk-controlbar': {
                display: 'grid',
                gridTemplateColumns: 'repeat(3,1fr)',
                gridTemplateRows: '1fr',
                alignItems: 'center',
                padding: '8px',
            },
            'rtk-controlbar.sm': {
                display: 'flex',
                position: 'relative',
                backgroundColor: 'var(--rtk-colors-background-1000, #000)',
            },
            'rtk-controlbar.md': {
                display: 'flex',
                position: 'relative',
                backgroundColor: 'var(--rtk-colors-background-1000, #000)',
            },
            'div#controlbar-left': {
                display: 'flex',
                alignItems: 'center',
                gap: 'var(--rtk-space-1, 4px)',
            },
            'div#controlbar-center': {
                display: 'flex',
                alignItems: 'center',
                position: 'relative',
                overflow: 'visible',
                justifyContent: 'center',
                gap: 'var(--rtk-space-1, 4px)',
            },
            'div#controlbar-mobile': {
                display: 'flex',
                flex: '1',
                alignItems: 'center',
                justifyContent: 'center',
                zIndex: '10000',
                gap: 'var(--rtk-space-1, 4px)',
            },
            'div#controlbar-right': {
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'flex-end',
                gap: 'var(--rtk-space-1, 4px)',
            },
            'rtk-settings': {
                width: '720px',
                height: '480px',
            },
            'rtk-debugger': {
                width: '720px',
                height: '480px',
            },
            'div#setupcontrols-indicator': {
                position: 'absolute',
                bottom: '12px',
                left: '12px',
                display: 'flex',
                gap: '6px',
                background: 'rgb(var(--rtk-colors-background-800, 0 0 0))',
                borderRadius: '100%',
            },
            'div#setupcontrols-media': {
                position: 'absolute',
                bottom: '8px',
                right: '8px',
                display: 'flex',
                gap: '6px',
            },
            'div#setupcontrols-settings': {
                position: 'absolute',
                top: '8px',
                right: '8px',
                display: 'flex',
                flexDirection: 'column',
                gap: '6px',
            },
            'rtk-meeting-title.sm': {
                marginLeft: '0',
            },
            'rtk-clock': {
                marginRight: '0',
            },
        },
        root: Object.assign(Object.assign(Object.assign({ 'rtk-meeting': {
                // if using key value pair, provide the key in `state`
                // else provide array of states in `states`
                state: 'meeting',
                states: ['activeSidebar'],
            }, 'rtk-meeting[meeting=idle]': ['rtk-idle-screen'], 'rtk-meeting[meeting=waiting]': ['rtk-waiting-screen'], 'rtk-meeting[meeting=setup]': ['rtk-setup-screen', 'rtk-dialog-manager'], 'rtk-meeting[meeting=joined]': meetingElements, 'rtk-meeting[meeting=joined].activeSidebar.sm': {
                add: [['rtk-sidebar', { view: 'full-screen' }]],
            }, 'rtk-meeting[meeting=joined].activeSidebar.md': {
                add: [['rtk-sidebar', { view: 'full-screen' }]],
            }, 'rtk-meeting[meeting=ended]': ['rtk-ended-screen'] }, headerChildren), controlBarChildren), { 'rtk-stage': {
                states: ['activeSidebar'],
                children: ['rtk-grid', 'rtk-notifications', 'rtk-transcripts'],
            }, 'rtk-stage.activeSidebar': {
                add: [['rtk-sidebar', { view: 'sidebar' }]],
            }, 
            // hide sidebar for smaller screens
            'rtk-stage.activeSidebar.sm': { remove: ['rtk-sidebar'] }, 'rtk-grid': {
                states: ['activeScreenShare', 'activePlugin', 'activeSpotlight'],
                state: 'viewType',
                children: ['rtk-simple-grid'],
            }, 'rtk-grid[viewType=AUDIO_ROOM]': ['rtk-audio-grid'], 'rtk-grid[viewType=AUDIO_ROOM].activePlugin': ['rtk-mixed-grid'], 'rtk-grid[viewType=AUDIO_ROOM].activeScreenshare': ['rtk-mixed-grid'], 'rtk-grid[viewType=AUDIO_ROOM].activeScreenShare.activeSpotlight': ['rtk-mixed-grid'], 'rtk-grid[viewType=AUDIO_ROOM].activePlugin.activeSpotlight': ['rtk-mixed-grid'], 'rtk-grid[viewType=AUDIO_ROOM].activePlugin.activeScreenShare.activeSpotlight': [
                'rtk-mixed-grid',
            ], 'rtk-grid.activeSpotlight': ['rtk-spotlight-grid'], 'rtk-grid.activeScreenShare': ['rtk-mixed-grid'], 'rtk-grid.activePlugin': ['rtk-mixed-grid'], 'rtk-grid.activeScreenShare.activeSpotlight': ['rtk-mixed-grid'], 'rtk-grid.activePlugin.activeSpotlight': ['rtk-mixed-grid'], 'rtk-grid.activePlugin.activeScreenShare.activeSpotlight': ['rtk-mixed-grid'], 'rtk-mixed-grid': {
                states: ['activeSpotlight'],
                state: 'viewType',
                children: ['rtk-simple-grid'],
            }, 'rtk-mixed-grid[viewType=AUDIO_ROOM]': ['rtk-audio-grid'], 'rtk-mixed-grid.activeSpotlight': ['rtk-spotlight-grid'], 'rtk-participant-tile': {
                state: 'meeting',
                children: ['rtk-name-tag', 'rtk-avatar', 'rtk-network-indicator'],
            }, 'rtk-participant-setup': ['rtk-avatar', 'div#setupcontrols-media'], 'rtk-participant-tile[meeting=setup]': [
                'rtk-avatar',
                'div#setupcontrols-indicator',
                'div#setupcontrols-media',
                ...(showSettingsToggle ? ['div#setupcontrols-settings'] : []),
            ], 'div#setupcontrols-indicator': [['rtk-audio-visualizer', { slot: 'start', hideMuted: true }]], 'div#setupcontrols-media': [
                ['rtk-mic-toggle', { size: 'sm' }],
                ['rtk-camera-toggle', { size: 'sm' }],
            ], 'div#setupcontrols-settings': [['rtk-settings-toggle', { size: 'sm' }]], 'rtk-screenshare-view': ['rtk-name-tag', 'rtk-network-indicator'], 'rtk-name-tag': [['rtk-audio-visualizer', { slot: 'start' }]] }),
        config: {
            notification_sounds: {
                participant_left: false,
            },
            participant_joined_sound_notification_limit: 3,
            participant_chat_message_sound_notification_limit: 10,
            videoFit: 'cover',
        },
    };
    config = extendConfig(toExtend, config);
    data.showSetupScreen = (_t = (_s = oldConfig.setupScreen) === null || _s === void 0 ? void 0 : _s.isEnabled) !== null && _t !== void 0 ? _t : true;
    return { config, data };
};

exports.extendConfig = extendConfig;
exports.generateConfig = generateConfig;
