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

import React from 'react'
import classnames from 'classnames'
import defineDebug from 'debug'
import { asPure, asLocaled, asServed, combine } from '../../wrappers'

const debug = defineDebug('project:fragment:comment-list-item')

const nameOfUser = (user) => user && user.name || user.key

/** @lends CommentListItem */
const CommentListItem = ({
  srvc,
  comment,
  simple = false
}) => {
  const { relativeDateString } = srvc.localeService
  return (
    <div className={ classnames('comment-list-item', {
      'comment-list-item-simple': simple
    }) }>
      <div className='comment-list-item-row'>
        { comment.text }
      </div>
      {
        simple ? null : (
            <div className='comment-list-item-row'>
              <span className="comment-list-item-who">{ nameOfUser(comment.speaker) }</span>
              <span className="comment-list-item-date">{ relativeDateString(comment.createdAt) }</span>
            </div>
          )
      }
    </div>
  )
}

export default combine(
  asPure(),
  asLocaled.proxy(),
  asServed.proxy()
)(CommentListItem)
