import dotenv from 'dotenv';

// please, set path to .env file in the root of WP directory
// JEST_VAR__APP_ROOT=""
// JEST_VAR__WP_LOGIN=""
// JEST_VAR__WP_PASSWORD=""
// JEST_VAR__CHROME_EXECUTABLE=""
// JEST_VAR__CHROME_SET_UA=""
// JEST_VAR__HEADLESS="1"
dotenv.config({path: '..\\..\\..\\.env'});

/**
 * Get env data.
 * @return {{root: string, wp_login: string, wp_password: string,
 * chrome_executable: string, chrome_ua: string, headless: boolean}}
 */
export function getEnvData() {
    const envData = {
        root: process.env.JEST_VAR__APP_ROOT,
        wp_login: process.env.JEST_VAR__WP_LOGIN,
        wp_password: process.env.JEST_VAR__WP_PASSWORD,
        chrome_executable: process.env.JEST_VAR__CHROME_EXECUTABLE,
        chrome_ua: process.env.JEST_VAR__CHROME_SET_UA,
        headless: process.env.JEST_VAR__HEADLESS === '1',
    };
    if (
        envData.root === undefined ||
        envData.wp_login === undefined ||
        envData.wp_password === undefined ||
        envData.chrome_ua === undefined ||
        envData.chrome_executable === undefined ||
        envData.headless === undefined
    ) {
        throw new Error('Environment data is not set');
    }
    return envData;
}

/**
 * Get globals.
 * @return {{browserWidth: number, browserHeight: number, globalTimeout: number}}
 */
export function getGlobals() {
    return {
        browserWidth: 1920,
        browserHeight: 1080,
        globalTimeout: 200000,
    };
}
