<script setup>
import { Effect } from "effect";
import { useI18n } from "vue-i18n";
import { cel as _rawCel } from "../../../../../utils/cel";
import { celBindings, injectCELContext } from "../../../../../utils/cel-context";
import { getLocalizedText } from "../../../../../share/locale";
import { dispatchTriggers, useEventChannel } from "../../../../../share/event-bus";
import ShwfedActionDefinition from "../../../components/definition.vue";
import { executeHttpRequestBatch } from "../../../utils/resolve";
defineOptions({ name: "ShwfedHttpRequestBatchActionRuntime" });
const props = defineProps({
  buttonId: { type: String, required: true },
  config: { type: null, required: true }
});
const { locale } = useI18n();
const inherited = injectCELContext();
const $cel = (expression, context) => _rawCel(expression, { ...celBindings(inherited), ...context });
const channel = useEventChannel();
const effect = Effect.suspend(
  () => Effect.andThen(
    dispatchTriggers(channel, props.config.before, $cel),
    () => executeHttpRequestBatch(props.config.expression, $cel, {
      messageExpression: props.config.messageExpression,
      resultExpression: props.config.resultExpression,
      continueOnError: props.config.continueOnError,
      markdown: getLocalizedText(props.config.markdown, locale.value) ?? ""
    })
  )
);
</script>

<template>
  <ShwfedActionDefinition
    :action-id="buttonId"
    :effect="effect"
  />
</template>
