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

const NewHost = ({ onOk }) => {
  return (
    <NewObjectForm
      type={'host'}
      defaultValues={{ active: true, state: { type: 'offline' } }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='host'
                column={1}
                bordered={false}
                isEditing={true}
                required={true}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Optional',
            key: 'optional',
            content: (
              <ObjectInfo
                type='host'
                column={1}
                bordered={false}
                isEditing={true}
                required={false}
                objectData={objectData}
                visibleProperties={{
                  _id: false,
                  createdAt: false,
                  updatedAt: false,
                  operatingSystem: false,
                  'deviceInfo.os': false,
                  'deviceInfo.os.hostname': false,
                  'deviceInfo.cpu': false,
                  'deviceInfo.cpu.model': false,
                  'deviceInfo.user.username': false,
                  'deviceInfo.user.homedir': false,
                  'deviceInfo.process.nodeVersion': false,
                  files: false
                }}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='host'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  createdAt: false,
                  updatedAt: false,
                  operatingSystem: false,
                  'deviceInfo.os': false,
                  'deviceInfo.os.hostname': false,
                  'deviceInfo.cpu': false,
                  'deviceInfo.cpu.model': false,
                  'deviceInfo.user.username': false,
                  'deviceInfo.user.homedir': false,
                  'deviceInfo.process.nodeVersion': false,
                  files: false,
                  connectedAt: false,
                  online: false
                }}
                isEditing={false}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New Host'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result) {
                onOk()
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewHost
