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

const NewPartSku = ({ onOk, reset, defaultValues }) => {
  return (
    <NewObjectForm
      type='partSku'
      reset={reset}
      defaultValues={{
        overrideCost: false,
        overridePrice: false,
        ...defaultValues
      }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='partSku'
                column={1}
                labelWidth={70}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
                visibleProperties={{
                  description: false,
                  priceMode: false,
                  cost: false,
                  costWithTax: false,
                  costTaxRate: false,
                  price: false,
                  priceWithTax: false,
                  overrideCost: false,
                  overridePrice: false,
                  margin: false,
                  amount: false,
                  priceTaxRate: false,
                  vendor: false
                }}
              />
            )
          },
          {
            title: 'Pricing',
            key: 'pricing',
            content: (
              <ObjectInfo
                type='partSku'
                column={1}
                labelWidth={120}
                visibleProperties={{
                  overrideCost: true,
                  cost: true,
                  costTaxRate: true,
                  costWithTax: true,
                  overridePrice: true,
                  priceMode: true,
                  price: true,
                  margin: true,
                  priceTaxRate: true,
                  priceWithTax: true
                }}
                bordered={false}
                isEditing={true}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Optional',
            key: 'optional',
            content: (
              <ObjectInfo
                type='partSku'
                column={1}
                labelWidth={100}
                visibleProperties={{
                  barcode: true,
                  description: true
                }}
                bordered={false}
                isEditing={true}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='partSku'
                column={1}
                visibleProperties={{
                  createdAt: false,
                  updatedAt: false,
                  _id: false,
                  _reference: false
                }}
                labelWidth={120}
                bordered={false}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Part SKU'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result) {
                onOk()
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewPartSku
