/**
 * PostShare view
 *
 * Generated by coz on 2017-01-02,
 * from a template provided by apeman-asset-templates.
 *
 * @function PostShareView
 */
'use strict'

import React, { Component, PropTypes as types } from 'react'
import defineDebug from 'debug'
import {
  ApView, ApViewHeader, ApViewBody
} from 'apeman-react-basic'
import { PostCard, ShareForm } from '../../fragments'
import {
  asConnected,
  asLocaled,
  asView,
  asServed,
  forSpin,
  forOne,
  forEvent,
  ofPost,
  combine
} from '../../wrappers'

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

const { SHARE_ICON } = IconClasses
const debug = defineDebug('project:view:post-share')

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

  static get defaultProps () {
    return {}
  }

  render () {
    const s = this
    const {
      props,
      shareUrl,
      labels,
      l
    } = s
    let {
      post
    } = props
    let target = post ? (
        <PostCard post={ post }/>
      ) : null
    return (
      <ApView id='post-share-view'
              className='view'
              spinning={ props.spinning }
              way={ props.way }
      >
        <ApViewHeader onLeftTap={ s.handlePop }
                      leftText={ null }
                      leftIcon={ props.popIcon }
                      titleText={ l('titles.SHARE') }
                      titleIcon={ SHARE_ICON }
                      onRightTap={ null }
                      rightIcon={ null }
                      rightText={ null }
        />

        <ApViewBody>
          {
            post ? (
                <ShareForm labels={ labels }
                           target={ target }
                           url={ shareUrl }
                />
              ) : null
          }
        </ApViewBody>
      </ApView>
    )
  }

  // --------------------
  // Callbacks
  // --------------------

  postDidLoad (post) {
    const s = this
    const {reloadPostShareButtons} = s.service('shareService')
    reloadPostShareButtons()
  }

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

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

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

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

  // --------------------
  // Dynamic Variables
  // --------------------

  get labels () {
    const s = this
    const { l } = s
    return {
      target: l('labels.SHARE_TARGET_POST'),
      url: l('labels.SHARE_URL'),
      way: l('labels.SHARE_WAY')
    }
  }

  get shareUrl () {
    const s = this
    const { post } = s.props
    const { urlForPost, absoluteUrl } = s.service('urlService')
    return post && absoluteUrl(urlForPost(post))
  }

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

}

export default combine(
  asServed(),
  forSpin(),
  asLocaled(),
  asView(),
  forOne(),
  ofPost(),
  forEvent(),
  asConnected()
)(PostShareView)

