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

const NewJob = ({ onOk, defaultValues }) => {
  return (
    <NewObjectForm
      type={'job'}
      defaultValues={{
        state: { type: 'draft' },
        ...defaultValues
      }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='job'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='job'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  createdAt: false,
                  updatedAt: false,
                  startedAt: false
                }}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Job'
            onSubmit={() => {
              handleSubmit()
              onOk()
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewJob
