var Wick = Wick || {};
Wick.HomeMovers = {
  NOTIFICATION_ERROR: 'Please fill the fields',
  el: {
    $homeMovers: $('.home-movers'),
    $homeMoversForm: $('#home-movers-form'),
    $homeMoversHero: $('.home-movers__hero'),
    $homeMoversThank: $('.home-movers__thank'),
    notification: '.notification',
    notificationContainer: '.globalMessages .container',
  },
  validateForm: function (e) {
    e.preventDefault();

    Wick.HomeMovers.isFormValid()
      ? Wick.HomeMovers.showThankYouState()
      : Wick.Notification.show({
        text: Wick.HomeMovers.NOTIFICATION_ERROR,
        container: Wick.HomeMovers.el.notificationContainer,
        type: 'error',
        closeBtn: true,
        noScrolling: true,
      });
  },
  showThankYouState: function () {
    Wick.HomeMovers.el.$homeMoversHero.hide();
    Wick.HomeMovers.el.$homeMoversThank.show();
    Wick.HomeMovers.scrollToPageTop();
    $(Wick.HomeMovers.el.notification).remove();
  },
  isFormValid: function () {
    let isValid = true;
    Wick.HomeMovers.el.$homeMoversForm.find('[data-row-required] input').each(function () {
      if ($(this).val() === '')
        isValid = false;
    });
    return isValid;
  },
  scrollToPageTop: function () {
    $('html, body').animate({scrollTop: 0}, 300);
  },
  init: function () {
    Wick.HomeMovers.el.$homeMoversForm.on('submit', Wick.HomeMovers.validateForm);
  }
};


$(document).ready(function () {
  function init() {
    if (!Wick.HomeMovers.el.$homeMovers.length) {
      return;
    }

    Wick.HomeMovers.init();
  }

  init();
});
