import { Component } from 'react'

import resolveStyles from './resolve-styles'

const defaultConfig = {
  webOnly: false,
}

const enhancer = (config, component) => {
  // Handle stateless functional components
  const ComposedComponent = (component.render || component.prototype.render) ?
    component :
    class extends Component {
      render() {
        return component(this.props, this.context)
      }
    }

  class Uranium extends ComposedComponent {
    constructor(props) {
      super(props)

      this.state = {
        _styles: {},
      }
    }

    render() {
      return resolveStyles(super.render(), this.forceUpdate.bind(this), config)
    }
  }

  /* eslint-disable prefer-template */
  Uranium.displayName =
    'Uranium(' +
    (ComposedComponent.displayName || ComposedComponent.name || 'Component') +
    ')'
  /* eslint-enable prefer-template */

  return Uranium
}

// Support both Uranium(MyComponent) and Uranium({ config })(MyComponent)
export default configOrComponent => {
  if (typeof configOrComponent === 'function') return enhancer(defaultConfig, configOrComponent)

  const newConfig = { ...defaultConfig, ...configOrComponent }
  return enhancer.bind(null, newConfig)
}

@@ -461,110 +461,8 @@
 t %7B%0A
-    constructor(props) %7B%0A      super(props)%0A%0A      this.state = %7B%0A        _styles: %7B%7D,%0A      %7D%0A    %7D%0A%0A
     

Remove old state._styles