// @flow
import * as React from 'react'
import { useDispatch } from 'react-redux'
import { push } from 'connected-react-router'
import { AlertModal } from '@opentrons/components'

import type { Dispatch } from '../../types'
import { actions as robotActions } from '../../robot'

const HEADING = 'Are you sure you want to cancel this run?'
const CANCEL_TEXT = 'cancel run'
const BACK_TEXT = 'go back'

export default function ExitAlertModal() {
  const dispatch = useDispatch<Dispatch>()
  const back = () => {
    // $FlowFixMe(mc, 2019-07-01): RPC robotActions.resume is untyped
    dispatch(robotActions.resume())
    dispatch(push('/run'))
  }
  const cancel = () => {
    // $FlowFixMe(mc, 2019-07-01): RPC robotActions.cancel is untyped
    dispatch(robotActions.cancel())
    dispatch(push('/run'))
  }

  return (
    <AlertModal
      heading={HEADING}
      buttons={[
        { children: BACK_TEXT, onClick: back },
        { children: CANCEL_TEXT, onClick: cancel },
      ]}
      alertOverlay
    >
      <p>Doing so will terminate this run and home your robot.</p>
    </AlertModal>
  )
}

@@ -1072,16 +1072,185 @@
 ot.%3C/p%3E%0A
+      %3Cp%3E%0A        Additionally, any hardware modules used within the protocol will remain%0A        active and maintain their current states until deactivated.%0A      %3C/p%3E%0A
     %3C/Al

clarify module behavior in cancel modal (#4467)