"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-runtime");
const reactBinding = require("@contember/react-binding");
const ui = require("@contember/ui");
const react = require("react");
const DimensionsRenderer = require("./DimensionsRenderer.cjs");
const DimensionsStateRenderer = (props) => {
  if (props.accessorTreeState.name === "initialized") {
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: props.children }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/environment/DimensionsSwitcher/DimensionsSwitcher.tsx",
      lineNumber: 28,
      columnNumber: 10
    }, void 0);
  }
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Spinner, {}, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/environment/DimensionsSwitcher/DimensionsSwitcher.tsx",
    lineNumber: 30,
    columnNumber: 9
  }, void 0);
};
const DimensionsSwitcher = react.memo((props) => {
  const minItems = props.minItems === void 0 ? 1 : props.minItems;
  const maxItems = props.maxItems === void 0 ? 2 : props.maxItems;
  if (minItems > maxItems) {
    throw new reactBinding.BindingError(
      `DimensionSwitcher: 'minItems' for dimension ${props.dimension} must be no greater than 'maxItems'.`
    );
  }
  if (minItems < 1) {
    throw new reactBinding.BindingError(`DimensionSwitcher: 'minItems' for dimension ${props.dimension} must be at least 1.`);
  }
  const environment = reactBinding.useEnvironment();
  const qualifiedEntityList = reactBinding.QueryLanguage.desugarQualifiedEntityList(
    {
      orderBy: props.orderBy,
      entities: props.optionEntities
    },
    environment
  );
  const key = react.useMemo(() => JSON.stringify(qualifiedEntityList), [qualifiedEntityList]);
  const labelFactory = /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactBinding.Field, { field: props.labelField }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/environment/DimensionsSwitcher/DimensionsSwitcher.tsx",
    lineNumber: 58,
    columnNumber: 23
  }, void 0);
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactBinding.DataBindingProvider, { stateComponent: DimensionsStateRenderer, children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(
    reactBinding.EntityListSubTree,
    {
      entities: qualifiedEntityList,
      orderBy: qualifiedEntityList.orderBy,
      offset: qualifiedEntityList.offset,
      limit: qualifiedEntityList.limit,
      listComponent: DimensionsRenderer.DimensionsRenderer,
      listProps: {
        buttonProps: props.buttonProps,
        dimension: props.dimension,
        labelFactory,
        minItems,
        maxItems,
        renderSelected: props.renderSelected,
        slugField: props.slugField
      },
      children: [
        labelFactory,
        /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactBinding.Field, { field: props.slugField }, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/environment/DimensionsSwitcher/DimensionsSwitcher.tsx",
          lineNumber: 79,
          columnNumber: 5
        }, void 0)
      ]
    },
    void 0,
    true,
    {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/environment/DimensionsSwitcher/DimensionsSwitcher.tsx",
      lineNumber: 62,
      columnNumber: 4
    },
    void 0
  ) }, key, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/environment/DimensionsSwitcher/DimensionsSwitcher.tsx",
    lineNumber: 61,
    columnNumber: 3
  }, void 0);
});
DimensionsSwitcher.displayName = "DimensionsSwitcher";
exports.DimensionsSwitcher = DimensionsSwitcher;
//# sourceMappingURL=DimensionsSwitcher.cjs.map
