import PropTypes from 'prop-types'
import ObjectInfo from '../../common/ObjectInfo'
import NewObjectForm from '../../common/NewObjectForm'
import WizardView from '../../common/WizardView'
const NewPurchaseOrder = ({ onOk, reset, defaultValues }) => {
  return (
    <NewObjectForm
      type={'purchaseOrder'}
      reset={reset}
      defaultValues={{
        state: { type: 'draft' },
        ...defaultValues
      }}
    >
      {({ 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={{
                  _reference: false,
                  items: false,
                  cost: false
                }}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='purchaseOrder'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  createdAt: false,
                  updatedAt: false,
                  _reference: false,
                  totalAmount: false,
                  totalAmountWithTax: false,
                  totalTaxAmount: false,
                  postedAt: false,
                  acknowledgedAt: false,
                  shippingAmount: false,
                  shippingAmountWithTax: false,
                  grandTotalAmount: false
                }}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Purchase Order'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result) {
                onOk()
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewPurchaseOrder
