/**
 * React component for main.
 * @class Main
 *
 * Generated by {{generator}} on {{today}},
 * from a template provided by {{ pkg.name }}.
 *
 * @see https://facebook.github.io/react/
 */

'use strict'

import React, {PropTypes as types} from 'react'
import classnames from 'classnames'
import {ApMain} from 'apeman-react-basic'
import {ApLocaleMixin, ApLayoutMixin, ApStackMixin} from 'apeman-react-mixins'
import defineDebug from 'debug'

import mixins from '../../mixins'

const debug = defineDebug('project:react:main')

/** @lends Main */
let Main = React.createClass({

  // --------------------
  // Specs
  // --------------------

  propTypes: {
    /** Callback for layout change */
    onLayout: types.func
  },

  mixins: [
    ApLocaleMixin,
    ApLayoutMixin,
    ApStackMixin
  ],

  statics: {},

  getInitialState () {
    return {}
  },

  getDefaultProps () {
    return {}
  },

  render () {
    const s = this
    let {state, props} = s

    let l = s.getLocale()
    return (
      <ApMain className={ classnames('main', props.className)}>
        {s.renderStack()}
        { props.children }
      </ApMain>
    )
  },

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

  componentWillMount () {
    const s = this
  },

  componentDidMount () {
    const s = this
  },

  componentWillReceiveProps (nextProps) {
    const s = this
  },

  shouldComponentUpdate (nextProps, nextState) {
    const s = this
    return true
  },

  componentWillUpdate (nextProps, nextState) {
    const s = this
  },

  componentDidUpdate (prevProps, prevState) {
    const s = this
  },

  componentWillUnmount () {
    const s = this
  },

  // ------------------
  // Custom
  // ------------------

  // Called by ApStackMixin
  stackedViewDidPush() {
    const s = this
    s.layout()
  },

  // Called by ApStackMixin
  stackedViewDidPop() {
    const s = this
    s.layout()
  },

  // Called by ApLayoutMixin
  doLayout() {
    const s = this,
      {props} = s
    let layout = {
      scrollWidth: s.getStackedScrollWidth()
    }
    if (props.onLayout) {
      props.onLayout(layout)
    }
  }

  // ------------------
  // Private
  // ------------------
})

export default Main
