"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const playwrightHelpers_1 = require("./helpers/playwrightHelpers");
(0, playwrightHelpers_1.runPlaywrightTestWithConfig)(runCanChangeCurrencyTets);
const currencies = [
    'IDR - Indonesian Rupiahs',
    'AUD - Australian Dollars',
    'EUR - Euros',
];
const getNumericValueFromCurrencyString = (currencyString) => {
    return parseFloat(currencyString.replace(/[^\d.]/g, ''));
};
function runCanChangeCurrencyTets(config) {
    (0, test_1.test)(`can change currency on ${config.url}`, (_a) => __awaiter(this, [_a], void 0, function* ({ page }) {
        yield page.goto(config.url);
        const currencySelector = page.locator('header.engine-header .be-select');
        yield (0, test_1.expect)(currencySelector).toBeVisible();
        const prices = {};
        for (const currencyName of currencies) {
            yield currencySelector.click();
            const currencyOptions = page.locator('.rs-select--suggest-list');
            yield (0, test_1.expect)(currencyOptions).toBeVisible();
            const currencyOption = currencyOptions.locator(`text="${currencyName}"`);
            yield (0, test_1.expect)(currencyOption).toBeVisible();
            yield currencyOption.click();
            // todo: Find a better way to check that the currency values are ready.
            yield page.waitForTimeout(1000);
            const firstAvailableDate = page.locator('.diji-calendar-month--item.--selectable').first();
            const firstAvailableDatePriceElement = firstAvailableDate.locator('.diji-calendar-month--item-cost');
            yield (0, test_1.expect)(firstAvailableDatePriceElement).not.toBeEmpty();
            const price = yield firstAvailableDatePriceElement.textContent();
            if (!price) {
                console.error(`Failed to get price for currency: ${currencyName}`);
                test_1.test.fail();
                return;
            }
            prices[currencyName] = price.trim();
            console.log(`Currency: ${currencyName}, Price: ${price}`);
        }
        const idrValue = getNumericValueFromCurrencyString(prices['IDR - Indonesian Rupiahs']);
        const eurValue = getNumericValueFromCurrencyString(prices['EUR - Euros']);
        const audValue = getNumericValueFromCurrencyString(prices['AUD - Australian Dollars']);
        // This assumes there's no drastic changes in currency rates!
        (0, test_1.expect)(idrValue).toBeGreaterThan(audValue); // IDR > AUD
        (0, test_1.expect)(audValue).toBeGreaterThan(eurValue); // AUD > EUR
    }));
}
;
//# sourceMappingURL=canChangeCurrency.spec.js.map