import { Alert } from '@blueprintjs/core'
import type { PropsWithChildren } from 'react'
import { type Dispatch, type FC, type SetStateAction } from 'react'

interface StartAlertProps extends PropsWithChildren {
  open: boolean
  setOpen: Dispatch<SetStateAction<boolean>>
  onSubmit: () => void
  loading?: boolean
}

const StartAlert: FC<StartAlertProps> = ({
  open,
  setOpen,
  children,
  onSubmit,
  loading,
}) => (
  <Alert
    isOpen={open}
    canEscapeKeyCancel
    canOutsideClickCancel
    cancelButtonText='Cancel'
    onCancel={() => setOpen(false)}
    confirmButtonText='Start'
    icon='warning-sign'
    intent='warning'
    onConfirm={onSubmit}
    onClose={() => setOpen(false)}
    loading={loading}
  >
    {children}
  </Alert>
)

export default StartAlert
