"use strict";
(function () {
  const
    control_isNotaryPublic = document.getElementById('IsNotaryPublic'),
    control_isPrincipal = document.getElementById('IsPrincipal'),
    control_lawyerFields = document.getElementById('LawyerFields'),
    control_registerButtonText = document.getElementById('RegisterButtonText'),
    control_roleType = document.getElementById('RoleType'),
    x = 1;

  function _bindEvents() {
    control_isNotaryPublic.addEventListener('change', _roleTypeChanged);
    control_isPrincipal.addEventListener('change', _roleTypeChanged);
  }

  function _roleTypeChanged(sender) {
    let roleType = sender?.target?.value ?? sender?.value ?? 'Principal';
    control_roleType.value = roleType;
    control_registerButtonText.textContent = 'Register as ' + roleType;
    if (roleType !== 'Principal') {
      control_lawyerFields.style.display = 'block';
      let requiredFields = control_lawyerFields.querySelectorAll('[required]');
      requiredFields.forEach(f => f.disabled = false);
    }
    else {
      control_lawyerFields.style.display = 'none';
      let requiredFields = control_lawyerFields.querySelectorAll('[required]');
      requiredFields.forEach(f => f.disabled = true);
    }
  }

  function _init() {
    _roleTypeChanged(control_roleType);
    _bindEvents();
  }

  _init();
})();