import { jsx } from "react/jsx-runtime";
import { useState, useEffect } from "react";
import { Dropzone } from "./Dropzone.mjs";
import classes from "./Dropzone.module.css.mjs";
import { getDefaultZIndex } from "../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/utils/get-default-z-index/get-default-z-index.mjs";
import { factory } from "../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/factory/factory.mjs";
import { useProps } from "../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/MantineProvider/use-props/use-props.mjs";
import { useStyles } from "../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/styles-api/use-styles/use-styles.mjs";
import { useResolvedStylesApi } from "../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/styles-api/use-resolved-styles-api/use-resolved-styles-api.mjs";
import { useDisclosure } from "../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-disclosure/use-disclosure.mjs";
import { OptionalPortal } from "../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Portal/OptionalPortal.mjs";
import { Box } from "../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/Box/Box.mjs";
const defaultProps = {
  loading: false,
  maxSize: Infinity,
  activateOnClick: false,
  activateOnDrag: true,
  dragEventsBubbling: true,
  activateOnKeyboard: true,
  active: true,
  zIndex: getDefaultZIndex("max"),
  withinPortal: true
};
const DropzoneFullScreen = factory((_props, ref) => {
  const props = useProps("DropzoneFullScreen", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    vars,
    active,
    onDrop,
    onReject,
    zIndex,
    withinPortal,
    portalProps,
    ...others
  } = props;
  const getStyles = useStyles({
    name: "DropzoneFullScreen",
    classes,
    props,
    className,
    style,
    classNames,
    styles,
    unstyled,
    rootSelector: "fullScreen"
  });
  const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi({
    classNames,
    styles,
    props
  });
  const [counter, setCounter] = useState(0);
  const [visible, { open, close }] = useDisclosure(false);
  const handleDragEnter = (event) => {
    var _a;
    if ((_a = event.dataTransfer) == null ? void 0 : _a.types.includes("Files")) {
      setCounter((prev) => prev + 1);
      open();
    }
  };
  const handleDragLeave = () => {
    setCounter((prev) => prev - 1);
  };
  useEffect(() => {
    counter === 0 && close();
  }, [counter]);
  useEffect(() => {
    if (!active) {
      return void 0;
    }
    document.addEventListener("dragenter", handleDragEnter, false);
    document.addEventListener("dragleave", handleDragLeave, false);
    return () => {
      document.removeEventListener("dragenter", handleDragEnter, false);
      document.removeEventListener("dragleave", handleDragLeave, false);
    };
  }, [active]);
  return /* @__PURE__ */ jsx(OptionalPortal, { ...portalProps, withinPortal, children: /* @__PURE__ */ jsx(
    Box,
    {
      ...getStyles("fullScreen", {
        style: { opacity: visible ? 1 : 0, pointerEvents: visible ? "all" : "none", zIndex }
      }),
      ref,
      children: /* @__PURE__ */ jsx(
        Dropzone,
        {
          ...others,
          classNames: resolvedClassNames,
          styles: resolvedStyles,
          unstyled,
          className: classes.dropzone,
          onDrop: (files) => {
            onDrop == null ? void 0 : onDrop(files);
            close();
            setCounter(0);
          },
          onReject: (files) => {
            onReject == null ? void 0 : onReject(files);
            close();
            setCounter(0);
          }
        }
      )
    }
  ) });
});
DropzoneFullScreen.classes = classes;
DropzoneFullScreen.displayName = "@mantine/dropzone/DropzoneFullScreen";
export {
  DropzoneFullScreen
};
