import { createHiveChain as createHiveChain$1, createWaxFoundation as createWaxFoundation$1 } from './detailed/index.js';
export * from './detailed/index.js';
import MainModuleFunction from './build_wasm/wax.node.js';

/* @terser-ignore */
// We want to skip minification for this file to preserve string concatination hacks used for WASM loading specifically in Vite environment
const getModuleExt = async (fileLocation) => {
    if (import.meta.client || (!import.meta.client && typeof import.meta.env === "object" && !import.meta.env?.SSR)) {
        // This is import style specific to Vite. Simple hack with concatination to avoid TypeScript & Rollup bundler related errors
        const filePath = fileLocation ?? (await import('./build_wasm/wax.common.wasm' + '?url')).default;
        return {
            locateFile(path, scriptDirectory) {
                if (path === "wax.common.wasm") {
                    return filePath;
                }
                return scriptDirectory + path;
            }
        };
    }
    // Load WASM without any rewriting filepaths in non-browser environments
    if (typeof window === "undefined" && typeof process === "object")
        // We explicitly define the default locateFile function here to override wrong emscripten behavior of falling back
        // to new URL(..., import.meta.url) which fails in webpack
        return {
            locateFile: (path, scriptDirectory) => scriptDirectory + path
        };
    // Warning: important change is moving conditional ternary expression outside of URL constructor call, what confused parcel analyzer.
    // Seems it must have simple variables & literals present to correctly translate code.
    let wasmFilePath = fileLocation ?? new URL("./build_wasm/wax.common.wasm", import.meta.url).href;
    // Fallback for client-bundled inlined WASM, e.g. when using webpack
    let wasmBinary;
    if (wasmFilePath.startsWith("data:application/wasm;base64,")) {
        const base64 = wasmFilePath.slice(29);
        const binaryString = atob(base64);
        const len = binaryString.length;
        const bytes = new Uint8Array(len);
        for (let i = 0; i < len; ++i)
            bytes[i] = binaryString.charCodeAt(i);
        wasmBinary = bytes;
    }
    return {
        locateFile(path, scriptDirectory) {
            if (path === "wax.common.wasm") {
                return wasmFilePath;
            }
            return scriptDirectory + path;
        },
        wasmBinary
    };
};
/**
 * Creates a Wax Hive chain instance
 *
 * @param {Partial<IWaxOptionsChain>} [options] wax options
 *
 * @returns {Promise<IHiveChainInterface>} Wax Hive chain API Instance
 *
 * @throws {WaxError} on any Wax API-related error
 */
const createHiveChain = async (options = {}) => {
    const { wasmLocation, ...otherOptions } = options || {};
    return createHiveChain$1(MainModuleFunction, await getModuleExt(wasmLocation), otherOptions);
};
/**
 * Creates a Wax Hive base instance
 *
 * @param {Partial<IWaxOptions>} [options] wax options
 *
 * @returns {Promise<IWaxBaseInterface>} Wax Hive Base API Instance
 *
 * @throws {WaxError} on any Wax API-related error
 */
const createWaxFoundation = async (options = {}) => {
    const { wasmLocation, ...otherOptions } = options || {};
    return createWaxFoundation$1(MainModuleFunction, await getModuleExt(wasmLocation), otherOptions);
};

export { createHiveChain, createWaxFoundation };
