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());
    });
};
import state from '../state';
import getAnalytics from '../services/analytics';
import { getCustomer } from '../services/customer';
import i18n from '../config/i18n';
export default function init({ customerId, language, analyticsParams = {
    dataLayerIntegration: true,
    sessionDuration: 30,
}, refreshCache = false, }) {
    return __awaiter(this, void 0, void 0, function* () {
        const ObjectIdRegex = /^(?=[a-f\d]{24}$)(\d+[a-f]|[a-f]+\d)/i;
        const UUIDv4Regex = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
        if (!ObjectIdRegex.test(customerId) && !UUIDv4Regex.test(customerId)) {
            throw new Error(`Invalid customer '${customerId}'`);
        }
        state.init = true;
        state.refreshCache = refreshCache;
        const customer = yield getCustomer(customerId);
        // Uncomment block to run a growthbook experiment
        // Remember to change values to current running experiment
        // const userId = await getUserId()
        // state.growthbook = new GrowthBook({
        //   user: {
        //     id: userId,
        //   },
        //   overrides: customer.experiments.overrides,
        // })
        // const experimentId = 'experiment-id'
        // const { value: variationId } = state.growthbook.run({
        //   key: experimentId,
        //   variations: ['A', 'B', 'C'],
        // })
        const analytics = yield getAnalytics({
            client: customerId,
            dataLayerIntegration: analyticsParams.dataLayerIntegration,
            sessionDurationMinutes: analyticsParams.sessionDuration,
        });
        state.analytics = analytics;
        state.customer = customer;
        yield Promise.all([i18n.init({ language })]);
    });
}
//# sourceMappingURL=init.js.map