"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.render = exports.ReactFabricProd = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const common_1 = require("@xframes/common");
const xframes = require("./xframes.node");
exports.ReactFabricProd = (0, common_1.ReactFabricProdInitialiser)(common_1.ReactNativePrivateInterface);
const render = (EntryPointComponent, assetsBasePath, fontDefs, theme) => {
    const onInit = () => {
        exports.ReactFabricProd.render((0, jsx_runtime_1.jsx)(common_1.WidgetRegistrationServiceContext.Provider, { value: widgetRegistrationService, children: (0, jsx_runtime_1.jsx)(EntryPointComponent, {}) }), 0, // containerTag,
        () => {
            // console.log("initialised");
        }, 1);
    };
    const onTextChange = (id, value) => {
        const rootNodeID = id;
        const topLevelType = "onChange";
        const nativeEventParam = { value };
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, nativeEventParam);
    };
    const onComboChange = (id, value) => {
        const rootNodeID = id;
        const topLevelType = "onChange";
        const nativeEventParam = { value };
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, nativeEventParam);
    };
    const onNumericValueChange = (id, value) => {
        const rootNodeID = id;
        const topLevelType = "onChange";
        const nativeEventParam = { value };
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, nativeEventParam);
    };
    const onMultiValueChange = (id, values) => {
        const rootNodeID = id;
        const topLevelType = "onChange";
        const nativeEventParam = { values };
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, nativeEventParam);
    };
    const onBooleanValueChange = (id, value) => {
        const rootNodeID = id;
        const topLevelType = "onChange";
        const nativeEventParam = { value };
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, nativeEventParam);
    };
    const onClick = (id) => {
        const rootNodeID = id;
        const topLevelType = "onClick";
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, {
            value: "clicked",
        });
    };
    const onTableSort = (id, columnIndex, sortDirection) => {
        const rootNodeID = id;
        const topLevelType = "onSort";
        const nativeEventParam = { columnIndex, sortDirection };
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, nativeEventParam);
    };
    const onTableFilter = (id, columnIndex, filterText) => {
        const rootNodeID = id;
        const topLevelType = "onFilter";
        const nativeEventParam = { columnIndex, filterText };
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, nativeEventParam);
    };
    const onTableRowClick = (id, rowIndex) => {
        const rootNodeID = id;
        const topLevelType = "onRowClick";
        const nativeEventParam = { rowIndex };
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, nativeEventParam);
    };
    const onTableItemAction = (id, rowIndex, actionId) => {
        const rootNodeID = id;
        const topLevelType = "onItemAction";
        const nativeEventParam = { rowIndex, actionId };
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(rootNodeID, topLevelType, nativeEventParam);
    };
    const onPrefetchProgress = (id, completed, total) => {
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(id, "onPrefetchProgress", { completed, total });
    };
    const onScriptError = (id, errorMessage) => {
        common_1.ReactNativePrivateInterface.nativeFabricUIManager.dispatchEvent(id, "onScriptError", { errorMessage });
    };
    xframes.init(assetsBasePath, JSON.stringify(fontDefs), JSON.stringify(theme), onInit, onTextChange, onComboChange, onNumericValueChange, onBooleanValueChange, onMultiValueChange, onClick, onTableSort, onTableFilter, onTableRowClick, onTableItemAction, onPrefetchProgress, onScriptError);
    const widgetRegistrationService = new common_1.WidgetRegistrationService(xframes);
    common_1.ReactNativePrivateInterface.nativeFabricUIManager.init(xframes, widgetRegistrationService);
    let flag = true;
    (function keepProcessRunning() {
        setTimeout(() => flag && keepProcessRunning(), 1000);
    })();
};
exports.render = render;
