"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-runtime");
const reactUtils = require("@contember/react-utils");
const ui = require("@contember/ui");
const react = require("react");
const SelectFileDialog = ({
  onSelect,
  onCancel,
  formatMessage,
  insertSelectedText,
  selectButtonText,
  isMultiple,
  dialogComponent: Component,
  dialogProps
}) => {
  const heading = reactUtils.useChildrenAsLabel(selectButtonText);
  const [selectedEntities, setEntities] = react.useState([]);
  const onToggleSelect = react.useCallback((entity) => {
    setEntities((current) => {
      const index = current.findIndex((it) => it.entity.id === entity.entity.id);
      if (index >= 0) {
        const newValues = [...current];
        newValues.splice(index, 1);
        return newValues;
      }
      if (isMultiple) {
        return [...current, entity];
      } else {
        return [entity];
      }
    });
  }, [isMultiple]);
  const onConfirm = react.useCallback(() => {
    onSelect(selectedEntities);
  }, [onSelect, selectedEntities]);
  const selectedEntityIds = react.useMemo(() => selectedEntities.map((it) => it.entity.id), [selectedEntities]);
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(
    ui.DialogModal,
    {
      layout: "wide",
      onClose: onCancel,
      header: /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Heading, { children: heading }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/internalComponents/selection/SelectFileDialog.tsx",
        lineNumber: 72,
        columnNumber: 5
      }, void 0) }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/internalComponents/selection/SelectFileDialog.tsx",
        lineNumber: 71,
        columnNumber: 12
      }, void 0),
      footer: /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(
        ui.Button,
        {
          distinction: "primary",
          onClick: onConfirm,
          children: formatMessage(insertSelectedText, "upload.insertSelected.text")
        },
        void 0,
        false,
        {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/internalComponents/selection/SelectFileDialog.tsx",
          lineNumber: 75,
          columnNumber: 5
        },
        void 0
      ) }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/internalComponents/selection/SelectFileDialog.tsx",
        lineNumber: 74,
        columnNumber: 12
      }, void 0),
      children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(
        Component,
        {
          ...dialogProps,
          onToggleSelectConnector: onToggleSelect,
          selectedEntityIds
        },
        void 0,
        false,
        {
          fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/internalComponents/selection/SelectFileDialog.tsx",
          lineNumber: 83,
          columnNumber: 4
        },
        void 0
      )
    },
    void 0,
    false,
    {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/internalComponents/selection/SelectFileDialog.tsx",
      lineNumber: 68,
      columnNumber: 3
    },
    void 0
  ) }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/internalComponents/selection/SelectFileDialog.tsx",
    lineNumber: 67,
    columnNumber: 9
  }, void 0);
};
exports.SelectFileDialog = SelectFileDialog;
//# sourceMappingURL=SelectFileDialog.cjs.map
