import { compileExpression } from "filtrex";
import React from "react";
import extraFunctions from "../utils/extraFunctions";
import format from "../utils/format";
import { useVariablesContext } from "@qorebase/app-component";
export const template = (text, values) => {
    const interpolated = format(text, {}, true);
    try {
        if (!interpolated.startsWith("="))
            throw new Error("Not an expression");
        return compileExpression(interpolated.substring(1), {
            extraFunctions,
        })(values);
    }
    catch (error) {
        return format(text, values);
    }
};
export const useTemplateLazy = () => {
    const { values } = useVariablesContext();
    return React.useCallback((text, additionalValues) => template(text, Object.assign(Object.assign({}, values), additionalValues)), [values]);
};
export default function useTemplate(text) {
    const { values } = useVariablesContext();
    return React.useMemo(() => template(text, values), [text, values]);
}
//# sourceMappingURL=useTemplate.js.map