/**
 * AdminServerInfo view
 *
 * Generated by coz on 11/5/2016,
 * from a template provided by apeman-asset-templates.
 *
 * @function AdminServerInfoView
 */
'use strict'

import React, { Component, PropTypes as types } from 'react'
import defineDebug from 'debug'
import {
  ApView, ApViewHeader, ApViewBody, ApViewFooter,
  ApInfo, ApInfoHeader, ApInfoBody, ApInfoItem
} from 'apeman-react-basic'
import {
  forOne,
  asConnected,
  asView,
  asLocaled,
  asServed,
  forSpin,
  combine
} from '../../wrappers'
import { IconClasses } from 'ore-fol-enums'

const { SERVER_ICON } = IconClasses
const debug = defineDebug('project:view:admin-server-info')

/** @lends AdminServerInfoView */
class AdminServerInfoView extends Component {
  // --------------------
  // Specs
  // --------------------
  static get propTypes () {
    return {}
  }

  static get defaultProps () {
    return {}
  }

  render () {
    const s = this
    const {
      props,
      l
    } = s
    let {
      os
    } = props
    return (
      <ApView id='admin-server-info-view'
              className='view'
              spinning={ props.spinning }
              way={ props.way }
      >
        <ApViewHeader onLeftTap={ s.handlePop }
                      leftText={ null }
                      leftIcon={ props.popIcon }
                      titleText={ null }
                      titleIcon={ SERVER_ICON }
                      onRightTap={ null }
                      rightIcon={ null }
                      rightText={ null }
        />

        <ApViewBody>
          {
            os ? (
                <ApInfo>
                  <ApInfoHeader>{ l('headings.OS') }</ApInfoHeader>
                  <ApInfoBody>
                    <ApInfoItem label={ l('labels.OS_PLATFORM') }
                                value={ `${os.platform}` }/>
                    <ApInfoItem label={ l('labels.OS_RELEASE') }
                                value={ `${os.release}` }/>
                    <ApInfoItem label={ l('labels.OS_HOSTNAME') }
                                value={ `${os.hostname}` }/>
                  </ApInfoBody>
                </ApInfo>
              ) : null
          }

        </ApViewBody>
      </ApView>
    )
  }

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

  componentWillMount () {
    debug('willMount')
    const s = this
  }

  componentDidMount () {
    debug('didMount')
    const s = this
    s.loadServerInfo()
  }

  componentWillUnmount () {
    debug('willUnmount')
    const s = this
  }

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

  loadServerInfo () {
    const s = this
    const { use } = s.service('apiService')
    return s.applySpinWhile(() =>
      use('serverApi').then((serverApi) =>
        s.applyOneLoad({
          os: () => serverApi.os()
        })
      )
    )
  }

  // --------------------
  // For redux
  // --------------------
  static mapStateToProps (state, ownProps) {
    return {}
  }

}

export default combine(
  forOne(),
  asServed(), forSpin(),
  asLocaled(),
  asView(),
  asConnected()
)(AdminServerInfoView)

