"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    useCompile: ()=>useCompile
});
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const compileCache = {};
const useCompile = function() {
    let { noCache } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {
        noCache: false
    };
    const options = (0, external_react_namespaceObject.useContext)(schema_namespaceObject.SchemaOptionsContext);
    const scope = (0, external_react_namespaceObject.useContext)(schema_namespaceObject.SchemaExpressionScopeContext);
    return (source, ext)=>{
        let shouldCompile = false;
        let cacheKey;
        if ('string' == typeof source && source.startsWith('{{')) {
            shouldCompile = true;
            cacheKey = source;
        }
        if (source && 'object' == typeof source && !(0, external_react_namespaceObject.isValidElement)(source)) {
            shouldCompile = true;
            cacheKey = JSON.stringify(source);
        }
        if (Array.isArray(source)) shouldCompile = true;
        if (shouldCompile) {
            const mergedScope = {
                ...options.scope,
                ...scope,
                ...ext
            };
            if (!cacheKey) return schema_namespaceObject.Schema.compile(source, mergedScope);
            try {
                if (noCache) return schema_namespaceObject.Schema.compile(source, mergedScope);
                compileCache[cacheKey] = compileCache[cacheKey] || schema_namespaceObject.Schema.compile(source, mergedScope);
                return compileCache[cacheKey];
            } catch (e) {
                return schema_namespaceObject.Schema.compile(source, mergedScope);
            }
        }
        return source;
    };
};
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
