import { Effect } from "effect";
import { renderMarkdown } from "../../../utils/markdown.js";
export const JUSTIFY_CLASS = {
  left: "justify-start",
  center: "justify-center",
  right: "justify-end"
};
const INTERPOLATION_RE = /\{\{(.*?)\}\}/gs;
function stringifyCelResult(value) {
  if (value === null || value === void 0) return "";
  if (typeof value === "object") return JSON.stringify(value);
  return String(value);
}
export function interpolateMarkdown(template, $cel, context) {
  return template.replace(INTERPOLATION_RE, (_, expr) => {
    const trimmed = expr.trim();
    if (!trimmed) return "";
    try {
      return stringifyCelResult(Effect.runSync($cel(trimmed, context)));
    } catch (e) {
      console.error("[shwfed-table] markdown interpolation failed", e);
      return "";
    }
  });
}
export function evaluateMarkdown(template, $cel, context) {
  return renderMarkdown(interpolateMarkdown(template, $cel, context));
}
