import { Environment } from "../../../vendor/cel-js/lib/index.js";
import { registerFormVariablesIfAbsent } from "./form-vars.js";
function probeCELContext(register) {
  const probe = new Environment({ unlistedVariablesAreDyn: false });
  const baseline = new Set(probe.getDefinitions().variables.map((v) => v.name));
  register(probe);
  const out = {};
  for (const v of probe.getDefinitions().variables) {
    if (baseline.has(v.name)) continue;
    out[v.name] = {
      type: v.type,
      label: v.label ?? v.name,
      description: v.description ?? void 0,
      value: void 0
    };
  }
  return out;
}
export function buildFormCelScope(configure) {
  return probeCELContext((env) => {
    registerFormVariablesIfAbsent(env);
    configure(env);
  });
}
export function buildFormRuntimeScope(values) {
  const out = probeCELContext(registerFormVariablesIfAbsent);
  for (const [name, value] of Object.entries(values)) {
    if (out[name]) out[name].value = value;
  }
  return out;
}
