"use strict";
const React = require("react");
const classNames = require("../_util/classNames.js");
const index$3 = require("../Button/index.js");
const index$2 = require("../../icon/react-icon/IconUpload/index.js");
const index$1 = require("../../icon/react-icon/IconPlus/index.js");
const index = require("../ConfigProvider/index.js");
const util = require("./util.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var TriggerNode = function(props) {
  var _a, _b;
  var locale = React.useContext(index.ConfigContext).locale;
  var _c = __read(React.useState(false), 2), isDragging = _c[0], setIsDragging = _c[1];
  var _d = __read(React.useState(0), 2), dragEnterCount = _d[0], setDragEnterCount = _d[1];
  var tip = props.tip, children = props.children, disabled = props.disabled, drag = props.drag, listType = props.listType, prefixCls = props.prefixCls, accept = props.accept, multiple = props.multiple;
  var nodeProps = {
    disabled
  };
  React.useEffect(function() {
    setDragEnterCount(0);
  }, [isDragging]);
  return children === null ? null : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
    className: prefixCls + "-trigger",
    onClick: disabled ? void 0 : props.onClick,
    onDragEnter: function() {
      setDragEnterCount(dragEnterCount + 1);
    },
    onDragLeave: function(e) {
      e.preventDefault();
      if (dragEnterCount === 0) {
        setIsDragging(false);
      } else {
        setDragEnterCount(dragEnterCount - 1);
      }
    },
    onDrop: function(e) {
      e.preventDefault();
      if (!disabled) {
        setIsDragging(false);
        if (props.directory) {
          util.loopDirectory(e.dataTransfer.items, accept, function(files2) {
            props.onDragFiles && props.onDragFiles(files2);
          });
        } else {
          var files = util.getFiles(e.dataTransfer.files, accept);
          props.onDragFiles && props.onDragFiles(multiple ? files : files.slice(0, 1));
        }
        props.onDrop && props.onDrop(e);
      }
    },
    onDragOver: function(e) {
      e.preventDefault();
      if (!disabled && !isDragging) {
        setIsDragging(true);
      }
    },
    children: React__default.default.isValidElement(children) ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
      className: classNames((_a = {}, _a[prefixCls + "-trigger-custom-active"] = isDragging, _a)),
      children: React__default.default.cloneElement(children, nodeProps)
    }) : listType === "picture-card" ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
      className: prefixCls + "-trigger-picture-wrapper",
      children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        className: prefixCls + "-trigger-picture",
        children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
          className: prefixCls + "-trigger-picture-text",
          children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$1, {})
        })
      })
    }) : drag ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs("div", {
      className: classNames(prefixCls + "-trigger-drag", (_b = {}, _b[prefixCls + "-trigger-drag-active"] = isDragging, _b)),
      children: [/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$1, {}), /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("p", {
        className: prefixCls + "-trigger-drag-text",
        children: isDragging ? locale.Upload.dragHover : locale.Upload.drag
      }), tip && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        className: prefixCls + "-trigger-tip",
        children: tip
      })]
    }) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs(index$3, {
      ...__assign({}, nodeProps, {
        type: "primary",
        className: prefixCls + "-trigger-with-icon"
      }),
      children: [/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$2, {}), locale.Upload.upload]
    })
  });
};
const TriggerNode$1 = TriggerNode;
module.exports = TriggerNode$1;
//# sourceMappingURL=trigger-node.js.map
