<script setup>
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { Effect } from "effect";
import { cel } from "../../../../../utils/cel";
import { celBindings, injectCELContext } from "../../../../../utils/cel-context";
import { getLocalizedText } from "../../../../../share/locale";
import { Markdown } from "../../../../ui/markdown";
defineOptions({ name: "ShwfedBlockMarkdownRuntime" });
const block = defineModel("block", { type: null, ...{ required: true } });
const { locale } = useI18n();
const source = computed(() => getLocalizedText(block.value.content, locale.value) ?? "");
const inheritedContext = injectCELContext();
function evalStyle(expression) {
  if (!expression) return void 0;
  try {
    const r = Effect.runSync(cel(expression, celBindings(inheritedContext)));
    if (r === null || r === void 0) return void 0;
    if (typeof r === "string") return r;
    if (typeof r === "object") return r;
    return String(r);
  } catch {
    return void 0;
  }
}
const styleValue = computed(() => evalStyle(block.value.style));
</script>

<template>
  <Markdown
    v-if="source"
    :source="source"
    block
    class="prose prose-sm prose-zinc max-w-none"
    :style="styleValue"
  />
</template>
