import React, { Component } from 'react';
// import cls from 'classnames';
import PropTypes from 'prop-types';
import { ConfigProvider as NextConfigProvider } from '@alifd/next';
// @ts-ignore
const originalContextTypes = NextConfigProvider.contextTypes;
// @ts-ignore
NextConfigProvider.contextTypes = Object.assign({}, originalContextTypes, { theme: PropTypes.string });
// @ts-ignore
const originalChildContextTypes = NextConfigProvider.childContextTypes;
// @ts-ignore
NextConfigProvider.childContextTypes = Object.assign({}, originalChildContextTypes, { theme: PropTypes.string });
// @ts-ignore
const originalGetChildContext = NextConfigProvider.prototype.getChildContext;
// @ts-ignore
NextConfigProvider.prototype.getChildContext = function () {
    const { theme } = this.props;
    const originProps = originalGetChildContext.call(this);
    return Object.assign({ theme }, originProps);
};
// function typeOf(obj) {
//   return Object.prototype.toString.call(obj).replace(/\[object\s|]/g, '');
// }
// function isClassComponent(component) {
//   return (
//     typeOf(component) === 'Function' && component.prototype && component.prototype.isReactComponent !== undefined
//   );
// }
// const originalConfig = NextConfigProvider.config;
// NextConfigProvider.config = (Component, options) => {
//   const ConfigedComponent = originalConfig(Component, options);
//   class WrapperComponent extends Component {
//     static contextTypes = {
//       theme: PropTypes.string,
//     };
//     _getInstance = ref => {
//       this._instance = ref;
//       if (options) {
//         if (this._instance && options.exportNames) {
//           options.exportNames.forEach(name => {
//             const field = this._instance[name];
//             if (typeof field === 'function') {
//               this[name] = field.bind(this._instance);
//             } else {
//               this[name] = field;
//             }
//           });
//         }
//       }
//     };
//     render() {
//       const { theme: propTheme } = this.props;
//       const { theme: contextTheme } = this.context;
//       const theme = propTheme ? propTheme : (contextTheme ? contextTheme : 'white');
//       // console.log(theme);
//       // console.log(this);
//       return (
//         <ConfigedComponent
//           {...this.props}
//           {...this.context}
//           theme = {theme}
//           ref={isClassComponent(ConfigedComponent) ? this._getInstance : null}
//         />
//       );
//     }
//   }
//   return WrapperComponent;
// };
const originalConfig = NextConfigProvider.config;
// @ts-ignore
NextConfigProvider.configFC = (OriginComponent, options) => {
    var _a;
    const ConfigedComponent = originalConfig(OriginComponent, options);
    return _a = class extends Component {
            render() {
                const { theme: contextTheme } = this.context;
                const theme = contextTheme ? contextTheme : 'white';
                return (React.createElement(ConfigedComponent, Object.assign({}, this.props, this.context, { theme: theme })));
            }
        },
        _a.contextTypes = {
            theme: PropTypes.string,
        },
        _a;
};
// @ts-ignore
const ConfigProvider = NextConfigProvider;
export default ConfigProvider;
