/**
 * Footer for view.
 * @class ApViewFooter
 */

'use strict'

import React, {PropTypes as types} from 'react'
import ReactDOM from 'react-dom'
import classnames from 'classnames'
import {ApLayoutMixin} from 'apeman-react-mixin-layout'
import {ApContainer} from 'apeman-react-container'

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

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

  propTypes: {
    /** Fixed to bottom */
    fixed: types.bool
  },

  mixins: [
    ApLayoutMixin
  ],

  statics: {},

  getInitialState () {
    return {}
  },

  getDefaultProps () {
    return {
      fixed: false
    }
  },

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

    return (
      <div className={ classnames('ap-view-footer', {
        'ap-view-footer-fixed': props.fixed
      }, props.className) }
           style={ Object.assign({}, props.style) }>

        <div className='ap-view-footer-space'
             ref='state'
             style={ layouts.space }
        >
        </div>
        <div className='ap-view-footer-content'
             ref='content'
             style={ layouts.content }
        >
          <ApContainer className='ap-view-footer-inner'>
            { props.children }
          </ApContainer>
        </div>
      </div>
    )
  },
  // --------------------
  // Lifecycle
  // --------------------

  // ------------------
  // For ApLayoutMixin
  // ------------------

  getInitialLayouts () {
    const s = this
    return {
      space: {
        height: 'auto'
      },
      content: {}
    }
  },

  calcLayouts () {
    const s = this

    let content = ReactDOM.findDOMNode(s.refs[ 'content' ])
    let contentRect = content.getBoundingClientRect()
    return {
      space: {
        height: contentRect.height
      },
      content: {}
    }
  }

  // ------------------
  // Private
  // ------------------

})

export default ApViewFooter
