const evaluateMathExpression = (expression: string, context: Record<string, any>) => {
	try {
		// Create a function to evaluate the math expression
		const contextKeys = Object.keys(context).join(", ");
		const contextValues = Object.values(context);
		expression = String(expression ?? '').trim();
		if (expression === '') {
			return 0;
		}
		const func = new Function(contextKeys, `return (${expression});`);
		const result = func(...contextValues);
		if (typeof result === 'number' && isNaN(result)) {
			return 0;
		}
		return result;
	} catch (e) {
		window.console.error(e);
		return 0;
	}
};

// Example usage
// const expression = "54545 * 45457";
// const result = evaluateMathExpression(expression);
// console.log("Evaluation Result:", result);
// Output: 2477148165

export default evaluateMathExpression;
