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

import React from 'react'
import defineDebug from 'debug'
import ThreadCard from './thread_card'
import { uniqueEntities } from 'ore-fol-helpers'
import { asPure, asServed, asLocaled, combine } from '../../wrappers'
import classnames from 'classnames'

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

/** @lends ThreadCardCollection */
const ThreadCardCollection = ({
  srvc,
  threads,
  heading,
  className
}) => {
  const { urlForThread } = srvc.urlService
  return (
    <div className={ classnames('thread-card-collection-list-container', className) }>
      {
        heading ? (
            <h5 className="thread-card-collection-list-heading">{ heading } </h5>
          ) : null
      }
      <div className="thread-card-collection-list">
        {
          uniqueEntities(threads).map((thread) => (
            <a href={ urlForThread(thread) }
               className="thread-card-collection-list-item"
               key={ thread.id }
            >
              <ThreadCard thread={ thread }/>
              <span className="thread-card-collection-list-item-title">
                  { thread.name }
                </span>
            </a>
          ))
        }
      </div>
    </div>
  )
}

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