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

const NewPrinter = ({ onOk }) => {
  return (
    <NewObjectForm
      type={'printer'}
      defaultValues={{
        moonraker: {
          port: 7125,
          protocol: 'ws'
        },
        active: true
      }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='printer'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Optional',
            key: 'optional',
            content: (
              <ObjectInfo
                type='printer'
                column={1}
                bordered={false}
                isEditing={true}
                required={false}
                objectData={objectData}
                visibleProperties={{
                  firmware: false,
                  currentFilamentStock: false,
                  'currentFilamentStock._id': false,
                  currentJob: false,
                  'currentJob._id': false,
                  currentSubJob: false,
                  'currentSubJob._id': false,
                  alerts: false
                }}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='printer'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  createdAt: false,
                  updatedAt: false,
                  connectedAt: false,
                  state: false,
                  firmware: false,
                  currentFilamentStock: false,
                  'currentFilamentStock._id': false,
                  currentJob: false,
                  'currentJob._id': false,
                  currentSubJob: false,
                  'currentSubJob._id': false,
                  alerts: false
                }}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Printer'
            onSubmit={() => {
              handleSubmit()
              onOk()
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewPrinter
