"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mock = void 0;
const foxpage_js_sdk_1 = require("@foxpage/foxpage-js-sdk");
/**
 * content mock
 * @param data
 * @param opt
 * @returns mocked page template
 */
function mock(data, opt) {
    const { applicationId, extendContent, mocks } = opt;
    const { content, relations } = data;
    // generate app info
    const appInfo = {
        appId: applicationId,
        slug: '/',
        configs: {},
    };
    // generate relation info
    const { templates = [], variables = [], conditions = [], functions = [] } = relations || {};
    const relationInfo = {
        templates,
        variables,
        conditions,
        functions,
        extendPage: extendContent || {},
    };
    try {
        const mockedContent = foxpage_js_sdk_1.mocker.withMock(content, mocks, {
            appInfo,
            relationInfo: relationInfo,
        });
        return Object.assign(Object.assign({}, data), { content: mockedContent.page, relations: Object.assign(Object.assign({}, data.relations), { templates: mockedContent.templates }) });
    }
    catch (e) {
        console.error('Mock content error:', e);
        return null;
    }
}
exports.mock = mock;
