"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLayoutConfig = getLayoutConfig;
const table_column_preset_1 = require("../controllers/table-column-preset");
const utils_1 = require("../utils");
const authorization_1 = require("../utils/authorization");
const oauth_1 = require("./oauth");
async function getLayoutConfig(req, params) {
    const { name = 'main', login, ytConfig, settings } = params;
    const { ytApiUseCORS, uiSettings, metrikaCounter, allowPasswordAuth, odinBaseUrl, prometheusBaseUrl, userSettingsConfig, tabletErrorsBaseUrl, } = req.ctx.config;
    const YT = ytConfig;
    const uiVersion = (0, utils_1.getInterfaceVersion)();
    const parameters = {
        interface: {
            version: uiVersion,
        },
        login,
        authWay: (0, authorization_1.getAuthWay)(req),
    };
    const isProduction = (0, utils_1.isProductionEnv)();
    const selectedFontType = settings.data['global::fontType'];
    const { defaultFontType } = uiSettings;
    const res = {
        bodyContent: { root: '', className: `app-font-${selectedFontType || defaultFontType || ''}` },
        title: 'YT',
        lang: 'en',
        meta: [
            {
                name: 'viewport',
                content: 'width=device-width, initial-scale=1.0',
            },
        ],
        inlineScripts: [
            `window.YT = Object.assign(window.YT || {}, ${JSON.stringify(YT)}, ${JSON.stringify({
                parameters,
            })});`,
            `window.YT.environment = window.YT.environment || (${isProduction} ? 'production' : 'development');`,
        ],
        data: {
            userSettingsCluster: userSettingsConfig?.cluster,
            settings,
            ytApiUseCORS,
            uiSettings,
            metrikaCounterId: metrikaCounter?.[0]?.id,
            allowPasswordAuth: Boolean(allowPasswordAuth),
            allowOAuth: (0, oauth_1.isOAuthAllowed)(req),
            oauthButtonLabel: (0, oauth_1.isOAuthAllowed)(req) ? (0, oauth_1.getOAuthSettings)(req).buttonLabel : undefined,
            allowUserColumnPresets: (0, table_column_preset_1.isUserColumnPresetsEnabled)(req),
            odinPageEnabled: Boolean(odinBaseUrl),
            allowTabletErrorsAPI: Boolean(tabletErrorsBaseUrl),
            allowPrometheusDashboards: Boolean(prometheusBaseUrl),
        },
        pluginsOptions: {
            yandexMetrika: {
                counter: metrikaCounter,
            },
            layout: {
                name,
            },
        },
    };
    return res;
}
