document.addEventListener('DOMContentLoaded', function () {
  document.querySelectorAll('[data-toggle-password]').forEach(function (button) {
    button.addEventListener('click', function () {
      const group = this.closest('.input-group');
      const input = group ? group.querySelector('input') : null;

      if (! input) {
        return;
      }

      const icon = this.querySelector('i');
      const showPassword = input.type === 'password';

      input.type = showPassword ? 'text' : 'password';

      if (icon) {
        icon.classList.toggle('bi-eye', ! showPassword);
        icon.classList.toggle('bi-eye-slash', showPassword);
      }
    });
  });
});
