import PropTypes from 'prop-types'
import ObjectInfo from '../../common/ObjectInfo'
import NewObjectForm from '../../common/NewObjectForm'
import WizardView from '../../common/WizardView'
import { getModelProperty } from '../../../../database/ObjectModels.js'
import ObjectProperty from '../../common/ObjectProperty.jsx'

const NewPurchaseOrder = ({ onOk, reset }) => {
  return (
    <NewObjectForm
      type={'purchaseOrder'}
      reset={reset}
      defaultValues={{ state: { type: 'new' } }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='purchaseOrder'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
                visibleProperties={{
                  items: false,
                  cost: false
                }}
              />
            )
          },
          {
            title: 'Items',
            key: 'items',
            content: (
              <ObjectProperty
                {...getModelProperty('purchaseOrder', 'items')}
                isEditing={true}
                objectData={objectData}
                loading={submitLoading}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='purchaseOrder'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  createdAt: false,
                  updatedAt: false,
                  items: false
                }}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Purchase Order'
            onSubmit={() => {
              handleSubmit()
              onOk()
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

NewPurchaseOrder.propTypes = {
  onOk: PropTypes.func.isRequired,
  reset: PropTypes.bool
}

export default NewPurchaseOrder
