import { Component, useAccessorTreeState, AccessorTree } from "@contember/binding";
import { useDialog, DropdownContentContainerProvider, Button } from "@contember/ui";
import { useCallback } from "react";
import { SelectFileDialog } from "./SelectFileDialog.js";
import { jsxDEV } from "react/jsx-dev-runtime";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/internalComponents/selection/SelectFileInput.tsx";
const SelectFileInput = Component(({
  formatMessage,
  insertSelectedText,
  onSelectConfirm,
  selectButtonComponent: SelectButton = Button,
  selectButtonComponentExtraProps,
  selectButtonProps,
  selectButtonText: selectButtonTextProp,
  isMultiple,
  fileSelection
}) => {
  const {
    openDialog
  } = useDialog();
  const selectButtonText = formatMessage(selectButtonTextProp, "upload.selectButton.text");
  const accessorTree = useAccessorTreeState();
  const onClick = useCallback(async (event) => {
    event.stopPropagation();
    const selectedEntities = await openDialog({
      type: "captivating",
      bare: true,
      content: (props) => /* @__PURE__ */ jsxDEV(DropdownContentContainerProvider, {
        children: /* @__PURE__ */ jsxDEV(AccessorTree, {
          state: accessorTree,
          children: /* @__PURE__ */ jsxDEV(SelectFileDialog, {
            formatMessage,
            onCancel: () => props.resolve(),
            onSelect: props.resolve,
            insertSelectedText,
            selectButtonText,
            isMultiple,
            ...fileSelection
          }, void 0, false, {
            fileName: _jsxFileName,
            lineNumber: 62,
            columnNumber: 8
          }, void 0)
        }, void 0, false, {
          fileName: _jsxFileName,
          lineNumber: 61,
          columnNumber: 7
        }, void 0)
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 60,
        columnNumber: 6
      }, void 0)
    });
    if (selectedEntities !== void 0) {
      onSelectConfirm(selectedEntities);
    }
  }, [accessorTree, fileSelection, formatMessage, insertSelectedText, isMultiple, onSelectConfirm, openDialog, selectButtonText]);
  return /* @__PURE__ */ jsxDEV(SelectButton, {
    ...selectButtonComponentExtraProps,
    size: "small",
    children: selectButtonText,
    onClick,
    ...selectButtonProps
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 81,
    columnNumber: 4
  }, void 0);
}, () => {
  return null;
}, "SelectFileInput");
export {
  SelectFileInput
};
//# sourceMappingURL=SelectFileInput.js.map
