function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React, { useContext, useRef } from 'react';
import { CSSTransition } from 'react-transition-group';
import clsx from 'clsx';
import { isDef } from '../utils';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';
import useLockScroll from '../hooks/use-lock-scroll';

var Overlay = function Overlay(props) {
  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('overlay', prefixCls),
      bem = _createNamespace[0];

  var nodeRef = useRef(null);
  var visible = props.visible,
      duration = props.duration;

  var renderOverlay = function renderOverlay() {
    var style = _extends({
      zIndex: props.zIndex !== undefined ? +props.zIndex : undefined,
      touchAction: props.lockScroll && 'none'
    }, props.style, props.customStyle);

    if (isDef(duration)) {
      style.animationDuration = duration + "ms";
    }

    return /*#__PURE__*/React.createElement("div", {
      ref: nodeRef,
      style: style,
      onClick: props.onClick,
      className: clsx(bem(), props.className)
    }, props.children);
  };

  useLockScroll(nodeRef, visible && props.lockScroll);
  return /*#__PURE__*/React.createElement(CSSTransition, {
    nodeRef: nodeRef,
    mountOnEnter: true,
    unmountOnExit: true,
    in: visible,
    timeout: duration,
    classNames: prefixCls + "-fade"
  }, renderOverlay());
};

Overlay.defaultProps = {
  lockScroll: true,
  duration: 300
};
export default Overlay;