/*!
 * (C) Ionic http://ionicframework.com - MIT License
 */
/**
 * Generates a unique test title based on a base title
 * and a test config. Playwright uses test titles to generate
 * test IDs for the test reports, so it's important that
 * each test title is unique.
 */
const generateTitle = (title, config) => {
    const { direction, palette, mode, theme } = config;
    /**
     * The iOS theme can only be used with the iOS mode,
     * and the MD theme can only be used with the MD mode.
     *
     * This logic enables the fallback behavior for existing tests,
     * where we only tested against a mode, which accounted for both
     * the theme and mode.
     */
    if (theme === 'ios' || theme === 'md') {
        if (palette === 'light') {
            /**
             * Ionic has many existing tests that existed prior to
             * the introduction of theme testing. To maintain backwards
             * compatibility, we will not include the theme in the test
             * title if the theme is set to light.
             */
            return `${title} - ${mode}/${direction}`;
        }
        return `${title} - ${mode}/${direction}/${palette}`;
    }
    return `${title} - ${theme}/${mode}/${direction}/${palette}`;
};
/**
 * Generates a unique filename based on a base filename
 * and a test config.
 */
const generateScreenshotName = (fileName, config) => {
    const { direction, palette, mode, theme } = config;
    /**
     * The iOS theme can only be used with the iOS mode,
     * and the MD theme can only be used with the MD mode.
     *
     * This logic enables the fallback behavior for existing tests,
     * where we only tested against a mode, which accounted for both
     * the theme and mode.
     */
    if (theme === 'ios' || theme === 'md') {
        if (palette === 'light') {
            /**
             * Ionic has many existing tests that existed prior to
             * the introduction of theme testing. To maintain backwards
             * compatibility, we will not include the theme in the screenshot
             * name if the theme is set to light.
             */
            return `${fileName}-${mode}-${direction}.png`;
        }
        return `${fileName}-${mode}-${direction}-${palette}.png`;
    }
    return `${fileName}-${theme}-${mode}-${direction}-${palette}.png`;
};
/**
 * Given a config generate an array of test variants.
 */
export const configs = (testConfig = DEFAULT_TEST_CONFIG_OPTION) => {
    var _a;
    const { modes, directions } = testConfig;
    const configs = [];
    /**
     * If certain options are not provided,
     * fall back to the defaults.
     */
    const processedModes = modes !== null && modes !== void 0 ? modes : DEFAULT_MODES;
    const processedDirection = directions !== null && directions !== void 0 ? directions : DEFAULT_DIRECTIONS;
    const processedPalette = (_a = testConfig.palettes) !== null && _a !== void 0 ? _a : DEFAULT_PALETTES;
    processedModes.forEach((mode) => {
        const [themeOrCombinedMode, modeName] = mode.split('-');
        const parsedTheme = themeOrCombinedMode;
        const parsedMode = modeName !== null && modeName !== void 0 ? modeName : themeOrCombinedMode;
        processedDirection.forEach((direction) => {
            processedPalette.forEach((palette) => {
                configs.push({ direction, palette, mode: parsedMode, theme: parsedTheme });
            });
        });
    });
    return configs.map((config) => {
        return {
            config,
            title: (title) => generateTitle(title, config),
            screenshot: (fileName) => generateScreenshotName(fileName, config),
        };
    });
};
const DEFAULT_MODES = ['ios', 'md'];
const DEFAULT_DIRECTIONS = ['ltr', 'rtl'];
const DEFAULT_PALETTES = ['light'];
const DEFAULT_TEST_CONFIG_OPTION = {
    modes: DEFAULT_MODES,
    directions: DEFAULT_DIRECTIONS,
    palettes: DEFAULT_PALETTES,
};
