import PropTypes from 'prop-types'
import { Button, Flex } from 'antd'

const NewObjectButtons = ({
  currentStep,
  totalSteps,
  onPrevious,
  onNext,
  onSubmit,
  formValid,
  submitLoading,
  submitText = 'Done',
  disabled = false
}) => {
  return (
    <Flex justify='end'>
      {totalSteps > 1 ? (
        <Button
          style={{ margin: '0 8px' }}
          onClick={onPrevious}
          disabled={currentStep === 0}
        >
          Previous
        </Button>
      ) : null}

      {currentStep < totalSteps - 1 ? (
        <Button
          type='primary'
          disabled={!formValid || disabled}
          onClick={onNext}
        >
          Next
        </Button>
      ) : (
        <Button
          type='primary'
          loading={submitLoading}
          disabled={!formValid || disabled}
          onClick={onSubmit}
        >
          {submitText}
        </Button>
      )}
    </Flex>
  )
}

NewObjectButtons.propTypes = {
  currentStep: PropTypes.number.isRequired,
  totalSteps: PropTypes.number.isRequired,
  onPrevious: PropTypes.func.isRequired,
  onNext: PropTypes.func.isRequired,
  onSubmit: PropTypes.func.isRequired,
  formValid: PropTypes.bool.isRequired,
  submitLoading: PropTypes.bool,
  submitText: PropTypes.string,
  disabled: PropTypes.bool
}

export default NewObjectButtons
