import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
var _jsxFileName = 'src/loading/Loading.jsx';
/**
 * Spin.jsx
 *
 * @Author: apple
 * @Date: 2018/1/22 22:48
 */

import React from 'react';
import PropTypes from 'prop-types';
import Icon from '../icon';
import classNames from 'classnames';
import { Transition } from 'react-transition-group';

/** Loading*/

var Loading = function (_React$PureComponent) {
    _inherits(Loading, _React$PureComponent);

    function Loading(props, context) {
        _classCallCheck(this, Loading);

        var _this = _possibleConstructorReturn(this, (Loading.__proto__ || Object.getPrototypeOf(Loading)).call(this, props, context));

        _this.duration = 300;
        return _this;
    }

    _createClass(Loading, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                prefixCls = _props.prefixCls,
                type = _props.type,
                shadow = _props.shadow,
                children = _props.children,
                loadingText = _props.loadingText,
                show = _props.show,
                className = _props.className,
                style = _props.style,
                indicator = _props.indicator;


            return React.createElement(
                'div',
                {
                    className: classNames(prefixCls, _defineProperty({}, prefixCls + '-show', show), className),
                    style: style, __source: {
                        fileName: _jsxFileName,
                        lineNumber: 54
                    },
                    __self: this
                },
                React.createElement(
                    Transition,
                    { 'in': show, timeout: this.duration, __source: {
                            fileName: _jsxFileName,
                            lineNumber: 63
                        },
                        __self: this
                    },
                    function (state) {
                        var _classNames2;

                        return React.createElement(
                            'div',
                            {
                                className: classNames(prefixCls + '-loader ' + prefixCls + '-fade', (_classNames2 = {}, _defineProperty(_classNames2, prefixCls + '-shadow', shadow), _defineProperty(_classNames2, prefixCls + '-fade-' + state, state), _classNames2)), __source: {
                                    fileName: _jsxFileName,
                                    lineNumber: 65
                                },
                                __self: _this2
                            },
                            type ? React.createElement('span', {
                                className: classNames(_defineProperty({}, prefixCls + '-loader-' + type, type)),
                                __source: {
                                    fileName: _jsxFileName,
                                    lineNumber: 71
                                },
                                __self: _this2
                            }) : indicator,
                            React.createElement(
                                'span',
                                { className: prefixCls + '-text', __source: {
                                        fileName: _jsxFileName,
                                        lineNumber: 79
                                    },
                                    __self: _this2
                                },
                                loadingText
                            )
                        );
                    }
                ),
                React.Children.map(children, function (child) {
                    return child !== null ? React.cloneElement(child, {
                        className: classNames(prefixCls + '-container', child.props.className)
                    }) : null;
                })
            );
        }
    }]);

    return Loading;
}(React.PureComponent);

Loading.displayName = 'NeatUI.Loading';
Loading.propTypes = {
    /** loading的图标，可自定义*/
    indicator: PropTypes.node,
    /** 控制显示的图标字体大小*/
    size: PropTypes.string,
    prefixCls: PropTypes.string,
    /** @ignore*/
    custom: PropTypes.bool,
    /** 控制显示背景*/
    shadow: PropTypes.bool,
    /** 控制显示*/
    show: PropTypes.bool,
    /** 控制显示的文字*/
    loadingText: PropTypes.string,
    /** loading样式类型*/
    type: PropTypes.oneOf(['organ'])
};
Loading.defaultProps = {
    prefixCls: 'ne-loading',
    indicator: React.createElement(Icon, { type: 'loading', __source: {
            fileName: _jsxFileName,
            lineNumber: 38
        },
        __self: this
    }),
    size: 'medium',
    shadow: true,
    show: false,
    loadingText: '加载中...'
};


export default Loading;