/**
 * Mixin to handle resize.
 * @mixin ApResizeMixin
 */

'use strict'

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

const HANDLER_NOT_IMPLEMENTED_WARNING = '[ApResizeMixin] Should implement windowDidResize method.'

/** @lends ApResizeMixin */
let ApResizeMixin = {

  // --------------------
  // Custom
  // --------------------
  $apResizeMixed: true,

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

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

  componentDidMount () {
    const s = this
    if (s.windowDidResize) {
      window.addEventListener('resize', s.windowDidResize)
    } else {
      console.warn(HANDLER_NOT_IMPLEMENTED_WARNING)
    }
  },

  componentWillUnmount () {
    const s = this
    if (s.windowDidResize) {
      window.removeEventListener('resize', s.windowDidResize)
    }
  }

}

export default Object.freeze(ApResizeMixin)
