;(function ($) {
  if ($('.anbarak-app').length < 1) return;
  if (!$('body').hasClass('full-page')) return;
  
  var LOAD_COUNT_KEY = 'anbarak_page_loads';
  var SHOWN_KEY = 'anbarak_review_modal_shown';
  var THRESHOLD = 20;

  var count = parseInt(localStorage.getItem(LOAD_COUNT_KEY) || '0', 10);
  count++;
  localStorage.setItem(LOAD_COUNT_KEY, count);

  if (count < THRESHOLD || localStorage.getItem(SHOWN_KEY) === '1') return;

  localStorage.setItem(SHOWN_KEY, '1');

  setTimeout(function () {
    MicroModal.show('modal-review-request');
  }, 3000);

  $(document).on('click', '#anbarak-review-remind-later', function () {
    localStorage.removeItem(SHOWN_KEY);
    localStorage.setItem(LOAD_COUNT_KEY, THRESHOLD - 2);
    MicroModal.close('modal-review-request');
  });
})(jQuery);
