"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
require("clsx");
const useProps = require("../../core/MantineProvider/use-props/use-props.cjs");
const useMergedRef = require("../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-merged-ref/use-merged-ref.cjs");
const defaultProps = {
  multiple: false
};
const FileButton = React.forwardRef(
  (props, ref) => {
    const {
      onChange,
      children,
      multiple,
      accept,
      name,
      form,
      resetRef,
      disabled,
      capture,
      inputProps,
      ...others
    } = useProps.useProps("FileButton", defaultProps, props);
    const inputRef = React.useRef(null);
    const onClick = () => {
      var _a;
      !disabled && ((_a = inputRef.current) == null ? void 0 : _a.click());
    };
    const handleChange = (event) => {
      if (multiple) {
        onChange(Array.from(event.currentTarget.files));
      } else {
        onChange(event.currentTarget.files[0] || null);
      }
    };
    const reset = () => {
      if (inputRef.current) {
        inputRef.current.value = "";
      }
    };
    useMergedRef.assignRef(resetRef, reset);
    return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
      children({ onClick, ...others }),
      /* @__PURE__ */ jsxRuntime.jsx(
        "input",
        {
          style: { display: "none" },
          type: "file",
          accept,
          multiple,
          onChange: handleChange,
          ref: useMergedRef.useMergedRef(ref, inputRef),
          name,
          form,
          capture,
          ...inputProps
        }
      )
    ] });
  }
);
FileButton.displayName = "@mantine/core/FileButton";
exports.FileButton = FileButton;
