import { jsxDEV, Fragment } from "react/jsx-dev-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__ */ jsxDEV(Fragment, { children: [
      props.allowBlockTypeChange !== false && /* @__PURE__ */ jsxDEV(
        SelectFieldInner,
        {
          ...metadata,
          label: props.label,
          placeholder: "Choose…"
        },
        void 0,
        false,
        {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/blocks/DiscriminatedBlocks.tsx",
          lineNumber: 53,
          columnNumber: 6
        },
        void 0
      ),
      metadata.currentValue && normalizedBlocks.get(metadata.currentValue.value)?.datum.children
    ] }, void 0, true, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/blocks/DiscriminatedBlocks.tsx",
      lineNumber: 51,
      columnNumber: 4
    }, void 0);
  },
  (props) => /* @__PURE__ */ jsxDEV(Fragment, { children: [
    /* @__PURE__ */ jsxDEV(Field, { ...props, isNonbearing: true }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/blocks/DiscriminatedBlocks.tsx",
      lineNumber: 65,
      columnNumber: 4
    }, void 0),
    props.children
  ] }, void 0, true, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/blocks/DiscriminatedBlocks.tsx",
    lineNumber: 64,
    columnNumber: 3
  }, void 0),
  "DiscriminatedBlocks"
);
export {
  DiscriminatedBlocks
};
//# sourceMappingURL=DiscriminatedBlocks.js.map
