import { jsxs, Fragment, jsx } from "react/jsx-runtime";
import { Component, Field } from "@contember/react-binding";
import { useMemo } from "react";
import { useStaticSingleChoiceField, SelectFieldInner } from "@contember/react-choice-field-ui";
import { useNormalizedBlocks } from "./useNormalizedBlocks.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__ */ jsxs(Fragment, { children: [
      props.allowBlockTypeChange !== false && /* @__PURE__ */ jsx(
        SelectFieldInner,
        {
          ...metadata,
          label: props.label,
          placeholder: "Choose…"
        }
      ),
      metadata.currentValue && normalizedBlocks.get(metadata.currentValue.value)?.datum.children
    ] });
  },
  (props) => /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(Field, { ...props, isNonbearing: true }),
    props.children
  ] }),
  "DiscriminatedBlocks"
);
export {
  DiscriminatedBlocks
};
//# sourceMappingURL=DiscriminatedBlocks.js.map
