"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactBinding = require("@contember/react-binding");
const react = require("react");
const reactChoiceFieldUi = require("@contember/react-choice-field-ui");
const useNormalizedBlocks = require("./useNormalizedBlocks.cjs");
const DiscriminatedBlocks = reactBinding.Component(
  (props) => {
    const normalizedBlocks = useNormalizedBlocks.useNormalizedBlocks(props.children);
    const blocksArray = react.useMemo(() => Array.from(normalizedBlocks.values()), [normalizedBlocks]);
    const transformedBlockList = react.useMemo(
      () => blocksArray.map((item) => ({
        ...item,
        label: item.datum.label,
        value: item.discriminateBy,
        searchKeywords: typeof item.datum.label === "string" ? item.datum.label : ""
      })),
      [blocksArray]
    );
    const metadata = reactChoiceFieldUi.useStaticSingleChoiceField({
      ...props,
      options: transformedBlockList
    });
    return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
      props.allowBlockTypeChange !== false && /* @__PURE__ */ jsxRuntime.jsx(
        reactChoiceFieldUi.SelectFieldInner,
        {
          ...metadata,
          label: props.label,
          placeholder: "Choose…"
        }
      ),
      metadata.currentValue && normalizedBlocks.get(metadata.currentValue.value)?.datum.children
    ] });
  },
  (props) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Field, { ...props, isNonbearing: true }),
    props.children
  ] }),
  "DiscriminatedBlocks"
);
exports.DiscriminatedBlocks = DiscriminatedBlocks;
//# sourceMappingURL=DiscriminatedBlocks.cjs.map
