<script setup>
import { cel as _rawCel } from "../../../../../utils/cel";
import { Effect } from "effect";
import { celBindings, injectCELContext, provideCELContext } from "../../../../../utils/cel-context";
import FormUnitRenderer from "../../../FormUnitRenderer.vue";
import { useDerived, useDerivedQuiescence } from "../../../utils/derived";
import { provideFormState } from "../../../utils/state";
import { provideSelectionsRegistry } from "../../../../../utils/selections-registry";
defineOptions({ name: "ShwfedListFieldRow" });
const state = defineModel({ type: null, ...{ required: true } });
const props = defineProps({
  unit: { type: Object, required: true },
  index: { type: Number, required: true }
});
const formState = provideFormState(state, "row");
const selections = provideSelectionsRegistry();
provideCELContext({
  item: {
    type: "dyn",
    label: "item",
    description: "\u5F53\u524D\u5217\u8868\u9879",
    value: () => state.value ?? {}
  },
  index: {
    type: "number",
    label: "index",
    description: "\u5F53\u524D\u5217\u8868\u9879\u7D22\u5F15\uFF0C\u4ECE 0 \u5F00\u59CB",
    value: () => props.index
  },
  selections: {
    type: "dyn",
    label: "\u9009\u4E2D\u9879",
    description: "\u672C\u5217\u8868\u9879\u5404\u9009\u62E9\u5B57\u6BB5\u5F53\u524D\u9009\u4E2D\u9879\u7684\u5B8C\u6574\u5BF9\u8C61\uFF08\u6309\u5B57\u6BB5\u6807\u8BC6\uFF09\u3002",
    value: () => selections.entries.value
  }
});
const inherited = injectCELContext();
const $cel = (expression, context) => _rawCel(expression, { ...celBindings(inherited), ...context });
useDerived({
  fields: () => props.unit.fields,
  evaluate: (expression) => $cel(expression),
  ready: Promise.resolve(),
  formState,
  quiescence: useDerivedQuiescence()
});
function evaluateMedia(expression) {
  return Effect.runSync($cel(expression));
}
</script>

<template>
  <FormUnitRenderer
    :unit="unit"
    :evaluate-media="evaluateMedia"
  />
</template>
