import type { App } from 'vue';
import installI18n from './i18n';

export default (app: App, configName: string) => {
    installI18n(app);
    const win: any = window;

    win.$appConfig = {};

    // Get the config and parse it's values
    const pluginConfig = win[configName];

    // Booleans
    pluginConfig.is_logged_in = Boolean(pluginConfig.is_logged_in);
    pluginConfig.settings.enable_category_creation = Boolean(pluginConfig.settings.enable_category_creation);

    // Numbers
    pluginConfig.settings.available_tokens = Number(pluginConfig.settings.available_tokens);
    pluginConfig.settings.used_tokens = Number(pluginConfig.settings.used_tokens);

    pluginConfig.settings.available_tokens_additional = Number(pluginConfig.settings.available_tokens_additional);

    pluginConfig.settings.category_creation_limit = Number(pluginConfig.settings.category_creation_limit);

    // Set the nonce for the first call
    win.$appConfig.nonce = pluginConfig.rest.nonce;

    // Add window and config to the app
    app.config.globalProperties.$win = win;
    app.provide('win', win);
    app.provide('pluginConfig', pluginConfig);
};
