(function () {
  'use strict';

  function initialize() {
    try {
      const password = document.getElementById('pwd');
      const toggle = document.getElementById('pwd-toggle');
      const eyeShow = document.getElementById('eye-show');
      const eyeHide = document.getElementById('eye-hide');

      if (!password || !toggle) {
        return;
      }

      toggle.addEventListener('click', function (event) {
        event.preventDefault();
        event.stopPropagation();

        const showing = password.type === 'text';
        const label = showing
          ? String(toggle.dataset.labelShow || '')
          : String(toggle.dataset.labelHide || '');

        password.type = showing ? 'password' : 'text';
        toggle.setAttribute('aria-pressed', String(!showing));

        if (label) {
          toggle.setAttribute('aria-label', label);
        }

        if (eyeShow) {
          eyeShow.style.display = showing ? 'block' : 'none';
        }

        if (eyeHide) {
          eyeHide.style.display = showing ? 'none' : 'block';
        }
      });
    } catch (error) {}
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', initialize);
  } else {
    initialize();
  }
}());
