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

const NewPrinter = ({ onOk, defaultValues }) => {
  return (
    <NewObjectForm
      type={'printer'}
      defaultValues={{
        moonraker: {
          port: 7125,
          protocol: 'ws'
        },
        active: true,
        ...defaultValues
      }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='printer'
                column={1}
                labelWidth='100px'
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Optional',
            key: 'optional',
            content: (
              <ObjectInfo
                type='printer'
                column={1}
                bordered={false}
                isEditing={true}
                required={false}
                labelWidth='100px'
                objectData={objectData}
                visibleProperties={{
                  firmware: false,
                  currentFilamentStock: false,
                  'currentFilamentStock._id': false,
                  currentJob: false,
                  'currentJob._id': false,
                  currentSubJob: false,
                  'currentSubJob._id': false,
                  alerts: false,
                  queue: false
                }}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='printer'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  _reference: 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,
                  pendingSlicerUploads: false,
                  online: false,
                  queue: false
                }}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Printer'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result?._id) {
                onOk(result)
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewPrinter
