'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _jsx = function () { var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7; return function createRawReactElement(type, props, key, children) { var defaultProps = type && type.defaultProps; var childrenLength = arguments.length - 3; if (!props && childrenLength !== 0) { props = {}; } if (props && defaultProps) { for (var propName in defaultProps) { if (props[propName] === void 0) { props[propName] = defaultProps[propName]; } } } else if (!props) { props = defaultProps || {}; } if (childrenLength === 1) { props.children = children; } else if (childrenLength > 1) { var childArray = Array(childrenLength); for (var i = 0; i < childrenLength; i++) { childArray[i] = arguments[i + 3]; } props.children = childArray; } return { $$typeof: REACT_ELEMENT_TYPE, type: type, key: key === undefined ? null : '' + key, ref: null, props: props, _owner: null }; }; }();

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _Teleport = require('../Teleport');

var _AutoClosable = require('../AutoClosable');

var _AutoClosable2 = _interopRequireDefault(_AutoClosable);

var _Transition = require('../Transition');

var _Transition2 = _interopRequireDefault(_Transition);

var _styles = require('../helpers/styles');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var PopoverContent = function (_React$Component) {
    _inherits(PopoverContent, _React$Component);

    function PopoverContent() {
        _classCallCheck(this, PopoverContent);

        return _possibleConstructorReturn(this, (PopoverContent.__proto__ || Object.getPrototypeOf(PopoverContent)).apply(this, arguments));
    }

    _createClass(PopoverContent, [{
        key: '_getAppearClassName',
        value: function _getAppearClassName() {
            var currentPreset = this.props.currentPreset;


            if (/middle|inside-left|inside-right/.test(currentPreset.xAxis) && currentPreset.yAxis === 'outside-bottom') {
                return styles.fromBottomAppear;
            }

            if (/middle|inside-left|inside-right/.test(currentPreset.xAxis) && currentPreset.yAxis === 'outside-top') {
                return styles.fromTopAppear;
            }

            if (currentPreset.xAxis === 'outside-left' && /middle|inside-top|inside-bottom/.test(currentPreset.yAxis)) {
                return styles.fromLeftAppear;
            }

            if (currentPreset.xAxis === 'outside-right' && /middle|inside-top|inside-bottom/.test(currentPreset.yAxis)) {
                return styles.fromRightAppear;
            }

            return styles.zoomAppear;
        }
    }, {
        key: '_renderPopup',
        value: function _renderPopup() {
            var _this2 = this;

            var _props = this.props,
                children = _props.children,
                isAnimated = _props.isAnimated,
                toggle = _props.toggle,
                currentPreset = _props.currentPreset;

            var popup = _react2.default.cloneElement(children, { onClose: function onClose() {
                    return toggle();
                } });

            if (!isAnimated) {
                return popup;
            }

            return _jsx('div', {
                style: { visibility: !currentPreset ? 'hidden' : 'visible' }
            }, void 0, currentPreset ? _jsx(_Transition2.default, {}, void 0, function (_ref) {
                var isAppear = _ref.isAppear,
                    isEnter = _ref.isEnter,
                    isLeave = _ref.isLeave,
                    isUpdate = _ref.isUpdate;
                return _jsx('div', {
                    className: (0, _styles.css)(styles.popupContainer, isAppear && _this2._getAppearClassName({ isAppear: isAppear, isEnter: isEnter, isLeave: isLeave, isUpdate: isUpdate }))
                }, void 0, popup);
            }) : popup);
        }
    }, {
        key: 'render',
        value: function render() {
            var props = this.props;

            return _jsx(_AutoClosable2.default, {
                onClose: function onClose() {
                    return props.isAutoClosable && props.toggle();
                },
                parentDOMNode: props.parentDOMNode
            }, void 0, _jsx(_Teleport.TeleportContext, {}, void 0, this._renderPopup()));
        }
    }]);

    return PopoverContent;
}(_react2.default.Component);

exports.default = PopoverContent;


var styles = _styles.StyleSheet.create({
    popupContainer: {
        transition: 'all .15s ease-in',
        opacity: 1,
        transform: 'translate3d(0, 0, 0) scale(1)'
    },
    fromBottomAppear: {
        opacity: 0,
        transform: 'translate3d(0, 10%, 0)'
    },
    fromTopAppear: {
        opacity: 0,
        transform: 'translate3d(0, -10%, 0)'
    },
    fromLeftAppear: {
        opacity: 0,
        transform: 'translate3d(-10%, 0, 0)'
    },
    fromRightAppear: {
        opacity: 0,
        transform: 'translate3d(10%, 0, 0)'
    },
    zoomAppear: {
        opacity: 0,
        transform: 'scale(.8)'

    }
});