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

import React from 'react'
import defineDebug from 'debug'
import { clone } from 'asobj'
import {
  ApForm,
  ApFieldSet,
  withForm
} from 'apeman-react-basic'
import TextField from '../fields/text_field'
import SubmitField from '../fields/submit_field'
import ColorSelectField from '../fields/color_select_field'
import { ThreadColorCodes } from 'ore-fol-codes'


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

/** @lends ThreadForm */
const ThreadForm = (props) => {
  let {
    values,
    labels,
    idOf,
    onUpdate,
    onSubmit,
    errorList,
    errorStyle
  } = props
  let formProps = clone(props, {
    without: [ 'onUpdate', 'onCancel', 'errors', 'labels' ]
  })
  let colors = Object.keys(ThreadColorCodes).map((name) => ThreadColorCodes[ name ])
  return (
    <ApForm { ...formProps }
            centered
            className='thread-form'>
      <ApFieldSet plain>
        { errorList }
        { errorStyle }
        <TextField id={ idOf('name') }
                   label={ labels.name }
                   name='name'
                   value={ values.name }
                   onUpdate={ onUpdate }
        />
        <TextField id={ idOf('description') }
                   rows={ 3 }
                   label={ labels.description }
                   name='description'
                   value={ values.description }
                   onUpdate={ onUpdate }
        />
        <ColorSelectField id={ idOf('color') }
                          label={ labels.color }
                          name='color'
                          value={ values.color || colors[ 0 ] }
                          onUpdate={ onUpdate }
                          options={ colors }
        />
        <br/>
        <SubmitField id={ idOf('submit')}
                     label={ labels.submit }
                     onSubmit={ onSubmit }
                     values={ values }
        />
      </ApFieldSet>
    </ApForm>
  )
}

export default withForm(ThreadForm)
