/**
 * PostThreadButton component
 *
 * Generated by coz on 2017-01-03,
 * from a template provided by apeman-asset-templates.
 *
 * @function PostThreadButton
 */
'use strict'

import React from 'react'
import defineDebug from 'debug'
import classnames from 'classnames'
import { ApButton } from 'apeman-react-basic'

import { IconClasses } from 'ore-fol-enums'
import { isDark } from 'acolor'
import { asPure, asServed, combine } from '../../wrappers'
const { THREAD_ICON } = IconClasses

const debug = defineDebug('project:fragment:post-thread-button')

const styleForThread = ({ color }) => ({
  backgroundColor: color,
  color: isDark(color) ? 'white' : '#333'
})

/** @lends PostThreadButton */
const PostThreadButton = ({
  srvc,
  post,
  active = false,
  onTap
}) => {
  const { urlForThread } = srvc.urlService
  return (
    <ApButton className={ classnames('post-thread-button', {
      'post-thread-button-active': active
    }) }
              onTap={ onTap }
              href={ onTap ? null : urlForThread(post.thread) }
              style={ styleForThread(post.thread) }
              onClick={ (e) => e.preventDefault() }
              title={ post.thread.name }
    >
      <i className={ classnames('post-thread-button-icon', THREAD_ICON) }
      />
      <span className="post-thread-button">
    </span>
    </ApButton>
  )
}

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