import PropTypes from 'prop-types'
import ObjectInfo from '../../common/ObjectInfo'
import NewObjectForm from '../../common/NewObjectForm'
import WizardView from '../../common/WizardView'

const NewProduct = ({ onOk, defaultValues }) => {
  return (
    <NewObjectForm
      type={'product'}
      defaultValues={{ priceMode: 'margin', ...defaultValues }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='product'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
                visibleProperties={{
                  priceMode: false,
                  margin: false,
                  amount: false,
                  priceTaxRate: false,
                  cost: false,
                  costTaxRate: false,
                  costWithTax: false,
                  price: false,
                  priceWithTax: false
                }}
              />
            )
          },
          {
            title: 'Pricing',
            key: 'pricing',
            content: (
              <ObjectInfo
                type='product'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
                visibleProperties={{
                  priceMode: true,
                  margin: true,
                  amount: true,
                  priceTaxRate: true,
                  cost: true,
                  costTaxRate: true,
                  costWithTax: true,
                  price: true,
                  priceWithTax: true
                }}
              />
            )
          },
          {
            title: 'Optional',
            key: 'optional',
            content: (
              <ObjectInfo
                type='product'
                column={1}
                bordered={false}
                isEditing={true}
                required={false}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='product'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  _reference: false,
                  createdAt: false,
                  updatedAt: false
                }}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Product'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result) {
                onOk()
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewProduct
