import { ConfirmActions } from '@any-ui/core'
import React, { FC, memo } from 'react'
import { useFormContext } from '../lib/FormContext'

const FormActionsBase: FC = () => {
  const {
    isNew,
    submitLabel = isNew ? 'Add' : 'Update',
    cancelLabel = 'Cancel',
    submitting,
    triggerCancel,
    submitDisabled,
    hideCancel,
  } = useFormContext()

  return (
    <ConfirmActions
      disableGutters
      variant="dense"
      onCancel={triggerCancel}
      cancelProps={{
        hide: hideCancel,
        disabled: submitting,
        label: cancelLabel,
      }}
      confirmProps={{
        disabled: submitDisabled,
        label: submitLabel,
        type: 'submit',
      }}
    />
  )
}
export const FormActions = memo(FormActionsBase)
export default FormActions
