"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-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__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: [
      props.allowBlockTypeChange !== false && /* @__PURE__ */ jsxDevRuntime.jsxDEV(
        reactChoiceFieldUi.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__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: [
    /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactBinding.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"
);
exports.DiscriminatedBlocks = DiscriminatedBlocks;
//# sourceMappingURL=DiscriminatedBlocks.cjs.map
