import React, { PropTypes, PureComponent } from 'react'
import { connect } from 'react-redux'
import Mousetrap from 'mousetrap'
import { SHORTCUT_KEYS } from '../constants/application_types'
import { closeModal, closeAlert } from '../actions/modals'
import { Modal } from '../components/modals/Modal'

export function mapStateToProps(state) {
  return {
    classList: state.modal.get('classList'),
    component: state.modal.get('component'),
    isActive: state.modal.get('isActive'),
    kind: state.modal.get('kind'),
  }
}

class ModalContainer extends PureComponent {
  static propTypes = {
    classList: PropTypes.string,
    component: PropTypes.object,
    dispatch: PropTypes.func.isRequired,
    isActive: PropTypes.bool.isRequired,
    kind: PropTypes.string.isRequired,
  }

  componentDidMount() {
    Mousetrap.bind(SHORTCUT_KEYS.ESC, () => { this.close() })
  }

  componentDidUpdate() {
    const { isActive, kind } = this.props
    if (kind === 'Modal' && isActive) {
      document.body.classList.add('isModalActive')
    } else if (kind === 'Modal' && !isActive) {
      document.body.classList.remove('isModalActive')
    }
  }

  componentWillUnmount() {
    Mousetrap.unbind(SHORTCUT_KEYS.ESC)
  }

  onClickModal = (e) => {
    const classList = e.target.classList
    if (classList.contains('Modal') ||
        classList.contains('Alert') ||
        classList.contains('CloseModal')) {
      this.close()
    }
  }

  close() {
    const { dispatch, isActive, kind } = this.props
    if (isActive) {
      dispatch(kind === 'Modal' ? closeModal() : closeAlert())
    }
  }

  render() {
    const { isActive, classList, component, kind } = this.props
    const elementProps = { classList, component, isActive, kind }
    if (isActive) {
      elementProps.onClickModal = this.onClickModal
    }
    return <Modal {...elementProps} />
  }
}

export default connect(mapStateToProps)(ModalContainer)


@@ -778,24 +778,97 @@
 uired,%0A  %7D%0A%0A
+  static defaultProps = %7B%0A    classList: null,%0A    component: null,%0A  %7D%0A%0A
   componentD

Add default props to the ModalContainer