/* Applies editable site settings (phone/email/address) to the shared chrome
   that common.js injects. Runs after the footer/topbar are in the DOM. */
(function () {
  var s = window.NTPPA_SETTINGS;
  if (!s) return;
  function apply() {
    try {
      if (s.phone) document.querySelectorAll('a[href^="tel:"]').forEach(function (a) {
        a.textContent = s.phone; a.setAttribute('href', 'tel:' + s.phone.replace(/[^0-9+]/g, ''));
      });
      if (s.email) document.querySelectorAll('a[href^="mailto:"]').forEach(function (a) {
        a.textContent = s.email; a.setAttribute('href', 'mailto:' + s.email);
      });
      var addr = document.querySelector('.topbar-addr');
      if (addr && s.address) addr.innerHTML = s.address.replace(/,\s*/g, '<br>');
      if (s.facebook) document.querySelectorAll('a[href*="facebook.com"]').forEach(function (a) { a.setAttribute('href', s.facebook); });
      if (s.youtube)  document.querySelectorAll('a[href*="youtube.com"]').forEach(function (a) { a.setAttribute('href', s.youtube); });
    } catch (e) {}
  }
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', function () { setTimeout(apply, 60); });
  else setTimeout(apply, 60);
})();
