import { Component } from "@contember/binding";
import { useMemo } from "react";
import { useStaticSingleChoiceField } from "../fields/ChoiceField/hooks/useStaticSingleChoiceField.js";
import { useNormalizedBlocks } from "./useNormalizedBlocks.js";
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { SelectFieldInner } from "../fields/SelectField/SelectField.js";
import { StaticSingleChoiceField } from "../fields/ChoiceField/StaticSingleChoiceField.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/blocks/DiscriminatedBlocks.tsx";
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\u2026"
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 34,
      columnNumber: 6
    }, void 0), metadata.currentValue && normalizedBlocks.get(metadata.currentValue.value)?.datum.children]
  }, void 0, true);
}, (props) => /* @__PURE__ */ jsxDEV(Fragment, {
  children: [/* @__PURE__ */ jsxDEV(StaticSingleChoiceField, {
    ...props,
    options: [],
    arity: "single",
    isNonbearing: true
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 46,
    columnNumber: 4
  }, void 0), props.children]
}, void 0, true), "DiscriminatedBlocks");
export {
  DiscriminatedBlocks
};
//# sourceMappingURL=DiscriminatedBlocks.js.map
