/**
 * Header for view.
 * @class ApViewHeader
 */

'use strict'

import React, {Component, PropTypes as types} from 'react'
import classnames from 'classnames'

import ApViewHeaderButton from './ap_view_header_button'
import ApViewHeaderTitle from './ap_view_header_title'
import {ApContainer} from 'apeman-react-container'

/** @lends ApViewHeader */
class ApViewHeader extends Component {
  render () {
    const s = this
    let { props } = s

    return (
      <div className={ classnames('ap-view-header', props.className) }
           style={ Object.assign({}, props.style) }>
        <ApContainer className='ap-view-header-inner'>
          <ApViewHeaderButton icon={ props.leftIcon }
                              text={ props.leftText }
                              onTap={ props.onLeftTap }
                              className='ape-view-header-button-left'
          />
          <div className='ap-view-header-content'>
            <ApViewHeaderTitle icon={ props.titleIcon }
                               text={ props.titleText }
                               onTap={ props.onTap }
            />
            { props.children }
          </div>
          <ApViewHeaderButton icon={ props.rightIcon }
                              text={ props.rightText }
                              onTap={ props.onRightTap }
                              className='ape-view-header-button-right'
          />
        </ApContainer>
      </div>
    )
  }
}

Object.assign(ApViewHeader, {
  // --------------------
  // Specs
  // --------------------

  propTypes: {
    /** Handler of left button tap */
    onLeftTap: types.func,
    /** Text of left button */
    leftText: types.string,
    /** Icon of left button */
    leftIcon: types.string,
    /** Text of title */
    titleText: types.string,
    /** Title of icon */
    titleIcon: types.string,
    /** Text of right button */
    rightText: types.string,
    /** Icon of right button */
    rightIcon: types.string,
    /** Handler of right button tap */
    onRightTap: types.func
  },

  defaultProps: {
    leftText: null,
    leftIcon: null,
    onLeftTap: null,
    titleText: null,
    titleIcon: null,
    rightText: null,
    rightIcon: null,
    onRightTap: null
  },

  // From http://ionicons.com/
  BACK_ICON: 'ion ion-chevron-left',
  NEXT_ICON: 'ion ion-chevron-right',
  ADD_ICON: 'ion ion-plus-round',
  UP_ICON: 'ion ion-chevron-up',
  CLOSE_ICON: 'ion ion-android-close',
  DOWN_ICON: 'ion ion-chevron-down',
  SHARE_ICON: 'ion ion-share',
  COMPOSE_ICON: 'ion ion-compose',
  MENU_ICON: 'ion ion-navicon-round',

  /**
   * Get icon for view pop.
   * @param {string} way - View push way.
   * @returns {string} - Pop icon for a way
   */
  popIcon (way) {
    switch (String(way).toUpperCase()) {
      case 'PUSH_LEFT':
        return ApViewHeader.BACK_ICON
      default:
        return ApViewHeader.CLOSE_ICON
    }
  }

})

export default ApViewHeader
