import { c as createStore } from './index-cDVGjRkU.js';

const initialState = {
    apiOrigin: "https://wc-proxy.justifi.ai",
    iframeOrigin: "https://components.justifi.ai",
    accountId: '',
};
const configStore = createStore(() => initialState);
const { state: configState} = configStore;
// resolver for the “ready” promise
let resolveConfigReady;
// initial “handshake” promise
const configReady = new Promise(r => {
    resolveConfigReady = r;
});
// called by <justifi-config-provider>
const setConfigState = (vals) => {
    Object.assign(configState, vals);
    resolveConfigReady();
};
/**
 * Wait for configProvider to run, but safe guard against never mounting.
 * @param timeoutMs max time to wait before resolving with default values
 */
const waitForConfig = (timeoutMs = 200) => {
    return new Promise(resolve => {
        const timer = setTimeout(() => {
            // timeout expired, proceed with default config state values
            resolve();
        }, timeoutMs);
        configReady.then(() => {
            clearTimeout(timer);
            resolve();
        });
    });
};

export { configState as c, setConfigState as s, waitForConfig as w };
