import _extends from 'babel-runtime/helpers/extends';
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';
import * as React from 'react';
import LocaleProvider, { ANT_MARK } from 'antd/es/locale-provider';
import LocaleReceiver from 'antd/es/locale-provider/LocaleReceiver';
import { ConfigConsumer, ConfigContext } from 'antd/es/config-provider/context';
import PagePoint from '../page-point';
export { ConfigConsumer };
export var configConsumerProps = ['getPopupContainer', 'rootPrefixCls', 'getPrefixCls', 'renderEmpty', 'csp', 'autoInsertSpaceInButton', 'locale', 'pageHeader', 'pagePoint'];

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

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

        var _this = _possibleConstructorReturn(this, (ConfigProvider.__proto__ || Object.getPrototypeOf(ConfigProvider)).apply(this, arguments));

        _this.getPrefixCls = function (suffixCls, customizePrefixCls) {
            var _this$props$prefixCls = _this.props.prefixCls,
                prefixCls = _this$props$prefixCls === undefined ? 'ant' : _this$props$prefixCls;

            if (customizePrefixCls) return customizePrefixCls;
            return suffixCls ? prefixCls + '-' + suffixCls : prefixCls;
        };
        _this.renderProvider = function (context, legacyLocale) {
            var _this$props = _this.props,
                children = _this$props.children,
                getPopupContainer = _this$props.getPopupContainer,
                renderEmpty = _this$props.renderEmpty,
                csp = _this$props.csp,
                autoInsertSpaceInButton = _this$props.autoInsertSpaceInButton,
                locale = _this$props.locale,
                pageHeader = _this$props.pageHeader,
                pagePoint = _this$props.pagePoint;

            var config = _extends(_extends({}, context), { getPrefixCls: _this.getPrefixCls, csp: csp,
                autoInsertSpaceInButton: autoInsertSpaceInButton,
                pagePoint: pagePoint });
            var setPagePoint = PagePoint.setPagePoint;

            if (getPopupContainer) {
                config.getPopupContainer = getPopupContainer;
            }
            if (renderEmpty) {
                config.renderEmpty = renderEmpty;
            }
            if (pageHeader) {
                config.pageHeader = pageHeader;
            }
            if (typeof pagePoint === 'boolean') {
                setPagePoint({ enable: pagePoint });
            }
            return React.createElement(
                ConfigContext.Provider,
                { value: config },
                React.createElement(
                    LocaleProvider,
                    { locale: locale || legacyLocale, _ANT_MARK__: ANT_MARK },
                    children
                )
            );
        };
        return _this;
    }

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

            return React.createElement(
                LocaleReceiver,
                null,
                function (_, __, legacyLocale) {
                    return React.createElement(
                        ConfigConsumer,
                        null,
                        function (context) {
                            return _this2.renderProvider(context, legacyLocale);
                        }
                    );
                }
            );
        }
    }]);

    return ConfigProvider;
}(React.Component);

export default ConfigProvider;