import { pendingQuestionColor } from '../pendingQuestionColor' ; let timeoutId = - 1 ; let overContainer = false ; let questionContainer ; export const watchForMouseMovementInQuestionContainer = ( questionContainerParam ) => { questionContainer = questionContainerParam ; questionContainer . addEventListener ( 'mouseenter' , ( ) => { window . clearTimeout ( timeoutId ) ; overContainer = true ; } ) ; questionContainer . addEventListener ( 'mouseleave' , ( ) => { window . clearTimeout ( timeoutId ) ; timeoutId = window . setTimeout ( removeLastQuestionDiv , 10000 ) ; overContainer = false ; } ) ; } ; export const removeLastQuestionDivAfterDebounce = ( ) => { window . clearTimeout ( timeoutId ) ; if ( ! overContainer ) { timeoutId = window . setTimeout ( removeLastQuestionDiv , 10000 ) ; } } ; const removeLastQuestionDiv = ( ) => { const questionDivs = [ ... questionContainer . children ] as Array < HTMLElement > ; if ( ! questionDivs . length || questionDivs . some ( div => div . style . backgroundColor === pendingQuestionColor ) ) { return ; } questionContainer . lastElementChild ! . remove ( ) ; timeoutId = window . setTimeout ( removeLastQuestionDiv , 10000 ) ; } ;