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

import React from 'react'
import classnames from 'classnames'
import defineDebug from 'debug'
import {
  ApList, ApListHeader, ApListBody, ApListFooter, ApListMoreButton
} from 'apeman-react-basic'
import ThreadListItem from './thread_list_item'
import { uniqueEntities } from 'ore-fol-helpers'
import { asPure } from '../../wrappers'

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

/** @lends ThreadList */
const ThreadList = ({
  heading,
  threads,
  spinning = false,
  onDetail,
  hasMore,
  moreText,
  moreSpinning,
  onMore,
  alt,
  horizontal = false
}) => (
  <ApList empty={ threads.length === 0}
          className={ classnames('thread-list', {
            'thread-list-horizontal': horizontal,
            'thread-list-spinning': spinning
          }) }
          alt={ alt }
  >
    {
      heading ? (
        <ApListHeader>{ heading }</ApListHeader>
      ) : null
    }
    <ApListBody>
      {
        uniqueEntities(threads).map((thread) => (
          <ThreadListItem key={ thread.id }
                          thread={ thread }
                          onDetail={ onDetail }/>
        ))
      }
    </ApListBody>
    <ApListFooter spinning={ moreSpinning }>
      <ApListMoreButton enabled={ hasMore }
                        onTap={ onMore }
                        text={ moreText }
      />
    </ApListFooter>
  </ApList>
)

export default asPure()(ThreadList)
