(function () {
  'use strict';

  function bind(form) {
    var jsField = form.querySelector('[data-myron-verification-js]');
    var interactionField = form.querySelector('[data-myron-verification-interactions]');
    var nonceField = form.querySelector('[name="myron_verification_nonce"]');
    if (!jsField || !interactionField || !nonceField) {
      return;
    }
    var interactions = 0;
    function markInteraction() {
      interactions += 1;
      interactionField.value = String(interactions);
      jsField.value = nonceField.value + ':active';
    }
    ['input', 'change', 'pointerdown', 'keydown'].forEach(function (eventName) {
      form.addEventListener(eventName, markInteraction, { passive: true });
    });
    form.addEventListener('submit', markInteraction);
  }

  document.addEventListener('DOMContentLoaded', function () {
    document.querySelectorAll('[data-myron-verification-form]').forEach(function (node) {
      var form = node.closest('form');
      if (form) {
        bind(form);
      }
    });
  });
})();

