import { useMemo, createElement, Fragment } from "react";
import { Component } from "@contember/binding";
import { useStaticSingleChoiceField } from "../fields/ChoiceField/hooks/useStaticSingleChoiceField.js";
import { useNormalizedBlocks } from "./useNormalizedBlocks.js";
import { NativeSelectFieldInner } from "../fields/SelectField/NativeSelectField.js";
import { StaticSingleChoiceField } from "../fields/ChoiceField/StaticSingleChoiceField.js";
const DiscriminatedBlocks = Component((props) => {
  const normalizedBlocks = useNormalizedBlocks(props.children);
  const blocksArray = useMemo(() => Array.from(normalizedBlocks.values()), [normalizedBlocks]);
  const transformedBlockList = useMemo(() => blocksArray.map((item) => ({
    ...item,
    label: item.datum.label,
    value: item.discriminateBy,
    searchKeywords: typeof item.datum.label === "string" ? item.datum.label : ""
  })), [blocksArray]);
  const metadata = useStaticSingleChoiceField({
    ...props,
    options: transformedBlockList
  });
  return /* @__PURE__ */ createElement(Fragment, null, props.allowBlockTypeChange !== false && /* @__PURE__ */ createElement(NativeSelectFieldInner, {
    ...metadata,
    label: props.label,
    placeholder: "Choose\u2026"
  }), metadata.currentValue && normalizedBlocks.get(metadata.currentValue.value)?.datum.children);
}, (props) => /* @__PURE__ */ createElement(Fragment, null, /* @__PURE__ */ createElement(StaticSingleChoiceField, {
  ...props,
  options: [],
  arity: "single",
  isNonbearing: true
}), props.children), "DiscriminatedBlocks");
export { DiscriminatedBlocks };
//# sourceMappingURL=DiscriminatedBlocks.js.map
