import { OverlayStart } from 'kibana/public' ; export type ConfirmHandlerCallback = ( result : boolean ) => void ; export type ConfirmHandler = ( message : string , callback : ConfirmHandlerCallback ) => void ; interface GetUserConfirmationHandlerParams { overlayPromise : Promise < OverlayStart > ; fallbackHandler ? : ConfirmHandler ; } export const getUserConfirmationHandler = ( { overlayPromise , fallbackHandler = windowConfirm , } ) : ConfirmHandler => { let overlayConfirm ; overlayPromise . then ( ( overlay ) => { overlayConfirm = getOverlayConfirmHandler ( overlay ) ; } , ( ) => { } ) ; return ( message , callback ) => { if ( overlayConfirm ) { overlayConfirm ( message , callback ) ; } else { fallbackHandler ( message , callback ) ; } } ; } ; const windowConfirm = ( message , callback ) => { const confirmed = window . confirm ( message ) ; callback ( confirmed ) ; } ; const getOverlayConfirmHandler = ( overlay ) : ConfirmHandler => { return ( message , callback ) => { overlay . openConfirm ( message , { title : ' ' , 'data-test-subj' : 'navigationBlockConfirmModal' } ) . then ( ( confirmed ) => { callback ( confirmed ) ; } , ( ) => { callback ( false ) ; } ) ; } ; } ;