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

'use strict'

import React, { Component, 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 ApViewHeaderTitle */
class ApViewHeaderTitle extends Component {
  shouldComponentUpdate (nextProps, nextState) {
    const s = this
    let { props, state } = s
    return !shallowEqual(props, nextProps) || shallowEqual(state, nextState)
  }

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

    let { text, icon } = props

    let isEmpty = !(text || icon)
    if (isEmpty) {
      return null
    }

    return (
      <h3 className={ classnames('ap-view-header-title', props.className) }
          style={ Object.assign({}, props.style) }>
          <span className='ap-view-header-title-inner'>
              <ApIcon className={ icon }/>
              <span className='ap-view-header-title-text'>{ text }</span>
            { props.children }
          </span>
      </h3>
    )
  }
}

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

  propTypes: {
    /** Text of the title */
    text: types.string,
    /** Icon of the title */
    icon: types.string
  },

  defaultProps: {
    text: null,
    icon: null
  }

})

export default withTouch(ApViewHeaderTitle)
