const departMinutes = 2
let temps = departMinutes * 60
let t = true;

const timerElement = document.getElementById("timer")


const intervalId = setInterval(() => {

  $.get(url, function( data ) {
    console.log(data)
    
    if(data.status == 'success'){
      document.getElementById('stepin').style.display = 'none';
      document.getElementById('success').style.display = 'block';
      clearInterval(intervalId);
    }
    
  });


  let minutes = parseInt(temps / 60, 10)
  let secondes = parseInt(temps % 60, 10)

  minutes = minutes < 10 ? "0" + minutes : minutes
  secondes = secondes < 10 ? "0" + secondes : secondes

  timerElement.innerText = `${minutes}:${secondes}`
  temps = temps <= 0 ? 0 : temps - 1
  if(temps === 0){
    setTimeout(()=>{
        console.log('Temps écoulé');
        clearInterval(intervalId);
        timerElement.innerText = `00:00`
        document.getElementById('stepin').style.display = 'none';
        if(faild){
            document.getElementById('faild').style.display = 'block';
        }else{
            document.getElementById('stepoff').style.display = 'block';
        }
       
    },1000)
   
  }
}, 1000)