/**
 * OtherTop view
 *
 * Generated by coz on 8/8/2016,
 * from a template provided by apeman-asset-templates.
 *
 * @class OtherTopView
 */
'use strict'

import React, { Component, PropTypes as types } from 'react'
import defineDebug from 'debug'
import {
  ApView, ApViewBody,
  ApMenu, ApMenuItem,
  ApList, ApListHeader, ApListBody, ApListItem
} from 'apeman-react-basic'
import { Footer } from '../../fragments'

import { IconClasses } from 'ore-fol-enums'

import { asView, asLocaled, asConnected, asServed, combine } from '../../wrappers'

const {
  SIGNIN_ICON,
  SIGNOUT_ICON,
  LOCALE_ICON,
  ABOUT_ICON,
  RESIGN_ICON,
  THREAD_ICON,
  POST_ICON,
  STAR_ICON,
  CRAWL_ICON,
  NEWS_ICON
} = IconClasses

const debug = defineDebug('project:view:other-menu')

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

  static get defaultProps () {
    return {}
  }

  render () {
    const s = this
    const {
      props,
      l
    } = s
    let {
      signed
    } = props
    let { profile, oauth } = (signed || {})
    return (
      <ApView id='other-top-view'
              className='view logo-back-view'
              way={ props.way }
              headerless
      >
        <ApViewBody>
          <ApList>
            <ApListHeader>{ l('titles.ACCOUNT_INFO') }</ApListHeader>
            <ApListBody>
              {
                signed ? (
                    <ApListItem disclosure
                                title={ profile && profile.name || signed.key }
                                subTitle={ signed.email }
                                onTap={ s.handleAccount }
                                imgSrc={ profile && profile.image }
                    >
                    </ApListItem>
                  ) : (
                    <ApListItem alt={ l('alt.NOT_SIGNED') }/>
                  )
              }
            </ApListBody>
          </ApList>
          <ApMenu>
            {
              signed ? null : (
                  <ApMenuItem icon={ SIGNIN_ICON }
                              text={ l('menus.SIGNIN') }
                              onTap={ s.handleSignin }/>
                )
            }
            {
              signed ? (
                  <ApMenuItem icon={ SIGNOUT_ICON }
                              text={ l('menus.SIGNOUT') }
                              onTap={ s.handleSignout }
                  />
                ) : null
            }
            {
              signed ? (
                  <ApMenuItem icon={ THREAD_ICON }
                              text={ l('menus.MY_THREADS') }
                              onTap={ s.handleMyThreads }
                  />
                ) : null
            }
            {
              signed ? (
                  <ApMenuItem icon={ POST_ICON }
                              text={ l('menus.MY_POSTS') }
                              onTap={ s.handleMyPosts }
                  />
                ) : null
            }

            {
              signed ? (
                  <ApMenuItem icon={ STAR_ICON }
                              text={ l('menus.MY_STARS') }
                              onTap={ s.handleMyStars }
                  />
                ) : null
            }
            {
              signed ? (
                  <ApMenuItem icon={ CRAWL_ICON }
                              text={ l('menus.CRAWL') }
                              onTap={ s.handleCrawl }
                  />
                ) : null
            }

            <ApMenuItem icon={ LOCALE_ICON }
                        text={ l('menus.LOCALE_SETTING') }
                        onTap={ s.handleLocale }
            />
            <ApMenuItem icon={ ABOUT_ICON }
                        text={ l('menus.ABOUT') }
                        onTap={ s.handleAbout }
            />
            <ApMenuItem icon={ NEWS_ICON }
                        text={ l('menus.NEWS') }
                        onTap={ s.handleNews }
            />
            {
              (signed && !oauth) ? (<ApMenuItem icon={ RESIGN_ICON }
                                                text={ l('menus.RESIGN') }
                                                onTap={ s.handleResign }/>) : null
            }
          </ApMenu>
          <Footer />
        </ApViewBody>
      </ApView>
    )
  }

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

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

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

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

  // --------------------
  // Handlers
  // --------------------

  handleSignin () {
    const s = this
    s.handlePushToModal('SignSigninView', {})
  }

  handleSignout () {
    const s = this
    s.handlePush('SignSignoutView', {})
  }

  handleLocale () {
    const s = this
    s.handlePush('AppLocaleView', {})
  }

  handleAbout () {
    const s = this
    s.handlePush('AboutTopView', {})
  }

  handleAccount () {
    const s = this
    s.handlePush('AccountDetailView', {})
  }

  handleResign () {
    const s = this
    s.handlePush('ResignLeadView', {})
  }

  handleMyThreads () {
    const s = this
    s.handlePush('MyThreadsView', {})
  }

  handleMyPosts () {
    const s = this
    s.handlePush('MyPostsView', {})
  }

  handleMyStars () {
    const s = this
    s.handlePush('MyStarsView', {})
  }

  handleCrawl () {
    const s = this
    s.handlePush('CrawlTopView', {})
  }

  handleNews () {
    const s = this
    s.handlePush('NewsListView', {})
  }
}

export default combine(
  asServed(),
  asLocaled(),
  asView(),
  asConnected()
)(OtherTopView)
