/**
 * PostStarButton component
 *
 * Generated by coz on 2016-12-21,
 * from a template provided by apeman-asset-templates.
 *
 * @function PostStarButton
 */
'use strict'

import React from 'react'
import classnames from 'classnames'
import defineDebug from 'debug'
import { ApButton } from 'apeman-react-basic'
import { IconClasses } from 'ore-fol-enums'

import { asPure, asServed, combine } from '../../wrappers'
const debug = defineDebug('project:fragment:star-button')

const {
  STAR_ICON,
  STAR_DISABLED_ICON,
  STAR_SPINNING_ICON
} = IconClasses

const starIconClass = ({ spinning, active }) => {
  if (spinning) {
    return STAR_SPINNING_ICON
  }
  return active ? STAR_ICON : STAR_DISABLED_ICON
}

/** @lends PostStarButton */
const PostStarButton = ({
  srvc,
  post,
  onTap,
  active = false,
  spinning = false
}) => {
  const { countString } = srvc.localeService
  return (
    <ApButton className={ classnames('post-star-button star-button', {
      'star-button-active': active,
      'star-button-spinning': spinning
    }) }
              onTap={ onTap }
    >
      <i className={ classnames('star-button-icon', starIconClass({ spinning, active })) }/>
      <span className='star-button-text'>
    { countString(post.starCount, { max: 1000 }) }
    </span>
    </ApButton>
  )
}

export default combine(
  asPure(),
  asServed.proxy()
)(PostStarButton)
