/**
 * ResignReason view
 *
 * Generated by coz on 11/5/2016,
 * from a template provided by apeman-asset-templates.
 *
 * @function ResignReasonView
 */
'use strict'

import React, { Component, PropTypes as types } from 'react'
import defineDebug from 'debug'
import {
  ApView, ApViewHeader, ApViewBody, ApViewFooter
} from 'apeman-react-basic'
import {
  asConnected,
  asView,
  asLocaled,
  forEntry,
  asServed,
  forSpin,
  combine
} from '../../wrappers'
import { ResignReasonForm } from '../../fragments'

import { IconClasses } from 'ore-fol-enums'

const { RESIGN_ICON } = IconClasses
const debug = defineDebug('project:view:resign-reason')

/** @lends ResignReasonView */
class ResignReasonView extends Component {
  // --------------------
  // Specs
  // --------------------
  static get propTypes () {
    return {}
  }

  static get defaultProps () {
    return {}
  }

  render () {
    const s = this
    const {
      props
    } = s
    return (
      <ApView id='resign-reason-view'
              className='view'
              spinning={ props.spinning }
              way={ props.way }
      >
        <ApViewHeader onLeftTap={ null }
                      leftText={ null }
                      leftIcon={ null }
                      titleText={ l('titles.RESIGN') }
                      titleIcon={ RESIGN_ICON }
                      onRightTap={ null }
                      rightIcon={ null }
                      rightText={ null }
        />

        <ApViewBody>
          <ResignReasonForm onCancel={ s.handlePop }
                            onSubmit={ s.handleSubmit }
                            onUpdate={ s.handleEntryUpdate }
                            values={ props.entryValues }
          />
        </ApViewBody>
      </ApView>
    )
  }

  // --------------------
  // Lifecycle
  // --------------------

  componentWillMount () {
    debug('willMount')
    const s = this
  }

  componentDidMount () {
    debug('didMount')
    const s = this
  }

  componentWillUnmount () {
    debug('willUnmount')
    const s = this
  }

  // --------------------
  // Handlers
  // --------------------

  handleSubmit () {
    const s = this
    const { use } = s.service('apiService')
    const { props } = s
    return s.applySpinWhile(() =>
      use('signApi').then((signApi) =>
        signApi.signdel(props.entryValues)
          .then(() => {
            s.handlePush('ResignDoneView')
          })
      )
    )
  }

  // --------------------
  // For redux
  // --------------------
  static mapStateToProps (state, ownProps) {
    return {}
  }

}

export default combine(
  forEntry(),
  asServed(),
  forSpin(),
  asLocaled(),
  asView(),
  asConnected()
)(ResignReasonView)

