"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactBinding = require("@contember/react-binding");
const ui = require("@contember/ui");
const react = require("react");
const SelectFileDialog = require("./SelectFileDialog.cjs");
const SelectFileInput = reactBinding.Component(
  ({
    formatMessage,
    insertSelectedText,
    onSelectConfirm,
    selectButtonComponent: SelectButton = ui.Button,
    selectButtonComponentExtraProps,
    selectButtonProps,
    selectButtonText: selectButtonTextProp,
    isMultiple,
    fileSelection
  }) => {
    const { openDialog } = ui.useDialog();
    const selectButtonText = formatMessage(selectButtonTextProp, "upload.selectButton.text");
    const accessorTree = reactBinding.useAccessorTreeState();
    const onClick = react.useCallback(async (event) => {
      event.stopPropagation();
      const selectedEntities = await openDialog({
        type: "captivating",
        bare: true,
        content: (props) => /* @__PURE__ */ jsxRuntime.jsx(reactBinding.AccessorTree, { state: accessorTree, children: /* @__PURE__ */ jsxRuntime.jsx(
          SelectFileDialog.SelectFileDialog,
          {
            formatMessage,
            onCancel: () => props.resolve(),
            onSelect: props.resolve,
            insertSelectedText,
            selectButtonText,
            isMultiple,
            ...fileSelection
          }
        ) })
      });
      if (selectedEntities !== void 0) {
        onSelectConfirm(selectedEntities);
      }
    }, [accessorTree, fileSelection, formatMessage, insertSelectedText, isMultiple, onSelectConfirm, openDialog, selectButtonText]);
    return /* @__PURE__ */ jsxRuntime.jsx(
      SelectButton,
      {
        ...selectButtonComponentExtraProps,
        size: "small",
        children: selectButtonText,
        onClick,
        ...selectButtonProps
      }
    );
  },
  () => {
    return null;
  },
  "SelectFileInput"
);
exports.SelectFileInput = SelectFileInput;
//# sourceMappingURL=SelectFileInput.cjs.map
