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

const NewAppPassword = ({ onOk, reset, defaultValues = {} }) => {
  return (
    <NewObjectForm
      type='appPassword'
      reset={reset}
      defaultValues={{
        active: true,
        ...defaultValues
      }}
    >
      {({ handleSubmit, submitLoading, objectData, formValid }) => {
        const steps = [
          {
            title: 'Required',
            key: 'required',
            content: (
              <ObjectInfo
                type='appPassword'
                column={1}
                bordered={false}
                isEditing={true}
                labelWidth={75}
                required={true}
                objectData={objectData}
              />
            )
          },
          {
            title: 'Summary',
            key: 'summary',
            content: (
              <ObjectInfo
                type='appPassword'
                column={1}
                bordered={false}
                visibleProperties={{
                  _id: false,
                  _reference: false,
                  createdAt: false,
                  updatedAt: false,
                  secret: false
                }}
                isEditing={false}
                labelWidth={70}
                objectData={objectData}
              />
            )
          }
        ]
        return (
          <WizardView
            steps={steps}
            loading={submitLoading}
            formValid={formValid}
            title='New App Password'
            onSubmit={async () => {
              const result = await handleSubmit()
              if (result) {
                onOk()
              }
            }}
          />
        )
      }}
    </NewObjectForm>
  )
}

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

export default NewAppPassword
