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

const NewFilament = ({ onOk }) => {
  return (
    <NewObjectForm type={'filament'}>
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='filament'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                labelWidth={120}
                objectData={objectData}
                visibleProperties={{
                  cost: false,
                  costTaxRate: false,
                  costWithTax: false
                }}
              />
            )
          },
          {
            title: 'Cost',
            key: 'cost',
            content: (
              <ObjectInfo
                type='filament'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                labelWidth={120}
                objectData={objectData}
                visibleProperties={{
                  cost: true,
                  costTaxRate: true,
                  costWithTax: true
                }}
              />
            )
          },
          {
            title: 'Optional',
            key: 'optional',
            content: (
              <ObjectInfo
                type='filament'
                column={1}
                bordered={false}
                isEditing={true}
                required={false}
                labelWidth={90}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='filament'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  _reference: false,
                  createdAt: false,
                  updatedAt: false
                }}
                labelWidth={120}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Filament'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result) {
                onOk()
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewFilament
