import { jsxs, Fragment, jsx } from "react/jsx-runtime";
import { forwardRef, useRef } from "react";
import "clsx";
import { useProps } from "../../core/MantineProvider/use-props/use-props.mjs";
import { assignRef, useMergedRef } from "../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-merged-ref/use-merged-ref.mjs";
const defaultProps = {
  multiple: false
};
const FileButton = forwardRef(
  (props, ref) => {
    const {
      onChange,
      children,
      multiple,
      accept,
      name,
      form,
      resetRef,
      disabled,
      capture,
      inputProps,
      ...others
    } = useProps("FileButton", defaultProps, props);
    const inputRef = 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 = "";
      }
    };
    assignRef(resetRef, reset);
    return /* @__PURE__ */ jsxs(Fragment, { children: [
      children({ onClick, ...others }),
      /* @__PURE__ */ jsx(
        "input",
        {
          style: { display: "none" },
          type: "file",
          accept,
          multiple,
          onChange: handleChange,
          ref: useMergedRef(ref, inputRef),
          name,
          form,
          capture,
          ...inputProps
        }
      )
    ] });
  }
);
FileButton.displayName = "@mantine/core/FileButton";
export {
  FileButton
};
