if (typeof MauticFormCallback == 'undefined') {
  var MauticFormCallback = {};
}

document.querySelectorAll('.webmecanik_form form').forEach((el, index) => {
    var formName = el.getAttribute('data-mautic-form');
    var refel = 'mauticform_input_' + formName + '_ref';
    var followModalId = '#followupMod_' + el.parentNode.siblings()[0].value;
    mauticCallback(formName, refel, followModalId);
});

function mauticCallback(mauticForm, mauticRef, followMod){
  MauticFormCallback[mauticForm] = {
    onValidateStart: function () {
      if (document.getElementById(mauticRef)) {
        document.getElementById(mauticRef).value = document.URL;
      }
    },
    onResponseStart: function (response) {
      require(['jquery'], function($) {
        $('.modal').modal('hide');
        $(followMod).modal('show');
      });
    },
  };
}
