// function datePickerInit(id){
//   var hideDatePicker = function() {
//     $('#mddtp-picker__date').addClass('mddtp-picker--inactive');
//     $('.ftr-main').removeClass('overlay');
//   }

//   datePicker.trigger = document.getElementById(id);
//   document.getElementById(id).addEventListener('click', function() {
//     datePicker.show();
//     $('.ftr-main').addClass('overlay');
//     // datePicker._switchToDateView(datePicker._sDialog.years, datePicker); // inicia com a escolha do ano
//     onClickOut($('#mddtp-picker__date'), null, hideDatePicker, null, true, true);
//   });
//   document.getElementById(id).addEventListener('onOk', function() {
//     $(this).find('.ftr-js-field__entry').val(datePicker.time.format('DD/MM/YYYY')).addClass('on');
//     $(this).find('input[type=hidden]').val(datePicker.time.format('DD/MM/YYYY'));
//     $('.ftr-main').removeClass('overlay');
//   });
// }

// var datePicker = new mdDateTimePicker.default({
//   type: 'date',
//   // init: moment('2016-03-3', 'YYYY-MM-DD'),
//   init: moment().subtract(10, 'years'), // para data de nascimento
//   orientation: 'PORTRAIT',
//   future: moment().add(21, 'years'),
//   past: moment().subtract(150, 'years'), // para data de nascimento
//   autoClose: true
// });
// datePickerInit('input-date');// parametro = id do elemento sem #

function hiddenPix(){
  const confirBox = document.querySelector('.js-box-confirmation');
  if(confirBox.classList.contains('ftr-hidden')){
    confirBox.classList.remove('ftr-hidden');
  }else{
    confirBox.classList.add('ftr-hidden');
  }
}

function reloadPix(){
  $.ajax({
    url: 'index.php?route=payment/getnet/reloadPix',
    type: 'get',
    dataType: 'json',
    timeout: 3000,
    contentType: 'application/json; charset=utf-8',
    error: function(xhr, ajaxOptions, thrownError) {
      console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
    },
    success: function(json) {
      if(json){
        var imgQR = document.querySelector('.js-imgQr');
        var spanQr = document.querySelector('.js-copy-content');
        imgQR.setAttribute('src','https://chart.googleapis.com/chart?chs=400x400&cht=qr&chl='+json.additional_data.qr_code);
        spanQr.textContent = json.additional_data.qr_code;
      }
    },
  });
}
setInterval( paymentStatus, 5000);

function paymentStatus(){
  var imgQR = document.querySelector('.js-imgQr');
  if(imgQR && !(imgQR.getAttribute('src') == 'image/qrcode_pago.png')){
    $.ajax({
      url: 'index.php?route=checkout/success/verifyPaymentPix',
      type: 'get',
      dataType: 'json',
      timeout: 3000,
      contentType: 'application/json; charset=utf-8',
      error: function(xhr, ajaxOptions, thrownError) {
        console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
      },
      success: function(json) {
        if(json){
          imgQR.setAttribute('src','image/qrcode_pago.png');
        }
      },
    });
  }
}