/**
 * Button for header.
 * @class ApViewHeaderButton
 */

'use strict'

import React, { PropTypes as types } from 'react'
import classnames from 'classnames'
import { ApIcon } from 'apeman-react-icon'
import { withTouch } from 'apeman-react-touchable'
import { shallowEqual } from 'asobj'

/** @lends ApViewHeaderButton */
const ApViewHeaderButton = React.createClass({

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

  propTypes: {
    /** Text of button */
    text: types.string,
    /** Text of icon */
    icon: types.string
  },

  getDefaultProps () {
    return {
      text: null,
      icon: null
    }
  },

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

    let { text, icon } = props

    let isEmpty = !(text || icon)
    if (isEmpty) {
      return <span className='ap-view-header-button-alt'></span>
    }

    return (
      <a className={ classnames('ap-view-header-button', props.className) }
         style={ Object.assign({}, props.style) }>
                    <span className='ap-view-header-button-inner'>
                        <span className='ap-view-header-button-aligner'>&ngbsp;</span>
                        <ApIcon className={ classnames('ap-view-header-ion', icon) }/>
                        <span className='ap-view-header-button-text'>{ text }</span>
                      { props.children }
                    </span>
      </a>
    )
  },

  shouldComponentUpdate (nextProps, nextState) {
    const s = this
    let { props, state } = s
    return !shallowEqual(props, nextProps) || shallowEqual(state, nextState)
  }

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

})

export default withTouch(ApViewHeaderButton)
