import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { Component } from "@contember/binding";
import { useMemo } from "react";
import { useStaticSingleChoiceField } from "../fields/ChoiceField/hooks/useStaticSingleChoiceField.js";
import { useNormalizedBlocks } from "./useNormalizedBlocks.js";
import { SelectFieldInner } from "../fields/SelectField/SelectField.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__ */ 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: 54,
          columnNumber: 6
        },
        globalThis
      ),
      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: 52,
      columnNumber: 4
    }, globalThis);
  },
  (props) => /* @__PURE__ */ jsxDEV(Fragment, { children: [
    /* @__PURE__ */ jsxDEV(StaticSingleChoiceField, { ...props, options: [], arity: "single", isNonbearing: true }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/blocks/DiscriminatedBlocks.tsx",
      lineNumber: 66,
      columnNumber: 4
    }, globalThis),
    props.children
  ] }, void 0, true, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/blocks/DiscriminatedBlocks.tsx",
    lineNumber: 65,
    columnNumber: 3
  }, globalThis),
  "DiscriminatedBlocks"
);
export {
  DiscriminatedBlocks
};
//# sourceMappingURL=DiscriminatedBlocks.js.map
