/**
 * SDK type seam — the ONLY file in new-sheet/ that imports @mog-sdk/node.
 *
 * All other new-sheet files import from here. To sever the SDK dependency
 * (e.g. for a build that excludes new-sheet), this is the single cut point.
 */
import { createRequire } from 'node:module';
let sdkModulePromise = null;
const MOG_SDK_NODE_SPECIFIER = '@mog-sdk/node';
const requireFromHere = createRequire(import.meta.url);
export function isMogSdkAvailable() {
    try {
        requireFromHere.resolve(MOG_SDK_NODE_SPECIFIER);
        return true;
    }
    catch {
        return false;
    }
}
function isMogSdkModule(value) {
    if (!value || typeof value !== 'object')
        return false;
    const candidate = value;
    return (typeof candidate.createWorkbook === 'function' &&
        typeof candidate.createHeadlessEngine === 'function');
}
export function normalizeMogSdkModule(value) {
    if (isMogSdkModule(value))
        return value;
    if (value &&
        typeof value === 'object' &&
        'default' in value &&
        isMogSdkModule(value.default)) {
        return value.default;
    }
    return null;
}
function loadSdk() {
    if (!sdkModulePromise) {
        sdkModulePromise = (async () => {
            const imported = normalizeMogSdkModule(await importMogSdkModule());
            if (imported)
                return imported;
            throw new Error(`Failed to load ${MOG_SDK_NODE_SPECIFIER}: invalid module shape.`);
        })();
    }
    return sdkModulePromise;
}
async function importMogSdkModule() {
    try {
        return await import(MOG_SDK_NODE_SPECIFIER);
    }
    catch (error) {
        const reason = error instanceof Error ? error.message : String(error);
        throw new Error(`Mog SDK optional dependency ${MOG_SDK_NODE_SPECIFIER} is not installed or failed to load. ${reason}`);
    }
}
export async function createWorkbook(options) {
    const sdk = await loadSdk();
    return sdk.createWorkbook(options);
}
export async function createHeadlessEngine(options) {
    const sdk = await loadSdk();
    return sdk.createHeadlessEngine(options);
}
//# sourceMappingURL=sdk-types.js.map