import { Effect } from "effect";
const INTERPOLATION_RE = /\{\{(.*?)\}\}/gs;
export function stringifyCelResult(value) {
  if (value === null || value === void 0) return "";
  if (typeof value === "object") return JSON.stringify(value);
  return String(value);
}
export function interpolateMarkdown(source, $cel, context) {
  return source.replace(INTERPOLATION_RE, (_, expr) => {
    const trimmed = expr.trim();
    if (trimmed.length === 0) return "{{ }}";
    try {
      return stringifyCelResult(Effect.runSync($cel(trimmed, context)));
    } catch {
      return `{{${expr}}}`;
    }
  });
}
