/**
 * React component for devtool.
 * @class Devtool
 *
 * Generated by {{generator}} on {{today}},
* from a template provided by {{ pkg.name }}.
*
* @see https://facebook.github.io/react/
 */

'use strict'

import React, {PropTypes as types} from 'react'
import classnames from 'classnames'
import {ApDevtool} from 'apeman-react-basic'
import {ApLocaleMixin, ApEnvMixin, ApToastMixin, ApSpinMixin} from 'apeman-react-mixins'
import defineDebug from 'debug'

import mixins from '../../mixins'

const debug = defineDebug('project:react:devtool')

/** @lends Devtool */
let Devtool = React.createClass({

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

  propTypes: {},

  mixins: [
    ApLocaleMixin,
    ApEnvMixin,
    ApToastMixin,
    ApSpinMixin,
    mixins('SignMixin')
  ],

  statics: {},

  getInitialState () {
    return {}
  },

  getDefaultProps () {
    return {}
  },

  render () {
    const s = this
    let {state, props} = s
    if (s.isProductionEnv()) {
      return null
    }

    let signed = s.getSigned()
    let info = { signed: signed && `id: ${signed.id} username: ${signed.user.username}` }
    return (
      <ApDevtool { ...props }
             className={ classnames('devtool', props.className) }
             info={ info }
        >
        { props.children }
      </ApDevtool>
    )
  },

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

  signDidChange () {
    const s = this
    s.forceUpdate()
  }

  // ------------------
  // Private
  // ------------------
})

export default Devtool
