import PropTypes from 'prop-types'
import { useMessageContext } from '../../context/MessageContext'
import ObjectInfo from '../../common/ObjectInfo'
import NewObjectForm from '../../common/NewObjectForm'
import WizardView from '../../common/WizardView'

const NewGCodeFile = ({ onOk, defaultValues }) => {
  return (
    <NewObjectForm
      type={'gcodeFile'}
      defaultValues={{
        state: { type: 'draft' },
        ...defaultValues
      }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Upload',
            key: 'upload',
            content: (
              <ObjectInfo
                type='gcodeFile'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
                visibleProperties={{ file: true }}
                showLabels={false}
              />
            )
          },
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='gcodeFile'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
                visibleProperties={{ file: false }}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='gcodeFile'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  _reference: false,
                  parts: false,
                  createdAt: false,
                  updatedAt: false,
                  startedAt: false
                }}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New GCode File'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result) {
                onOk()
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewGCodeFile
