text: import PropTypes from 'prop-types'
  import { Form } from '@admin'
  import React from 'react'
  
  class Edit extends React.PureComponent {
  
    static contextTypes = {
      form: PropTypes.object
    }
  
    static propTypes = {
      entity: PropTypes.string,
      fields: PropTypes.array,
      item: PropTypes.object,
      onDone: PropTypes.func
    }
  
    state = {
      config: {}
    }
  
    _handleCancel = this._handleCancel.bind(this)
    _handleSubmit = this._handleSubmit.bind(this)
  
    render() {
      return <Form { ...this._getForm() } />
    }
  
    _getForm() {
      const { entity, fields, item } = this.props
      return {
        title: `Edit ${entity}`,
        cancelIcon: 'chevron-left',
        onCancel: this._handleCancel,
        onSubmit: this._handleSubmit,
        sections: [
          {
            fields: fields.map(field => ({
              ...field,
              value: item[field.name]
            }))
          }
        ]
      }
    }
  
    _handleCancel() {
      this.context.form.pop()
    }
  
    _handleSubmit(item) {
      this.props.onDone(item)
      this.context.form.pop()
    }
  
  }
  
  export default Edit
  