(() => {
  const message = 'Read-only demonstration: changes are disabled.';
  document.querySelectorAll('form').forEach((form) => {
    const method = (form.getAttribute('method') || 'get').toLowerCase();
    const action = (form.getAttribute('action') || '').toLowerCase();
    const isLogin = action.includes('login.php') || form.closest('.login-card');
    const isRoleSwitch = action.includes('role_switch.php');
    if (method !== 'post' || isLogin || isRoleSwitch) return;
    form.dataset.demoLocked = '1';
    form.addEventListener('submit', (event) => {
      event.preventDefault();
      window.alert(message);
    });
    form.querySelectorAll('input, select, textarea, button').forEach((control) => {
      if (control.type === 'hidden') return;
      control.disabled = true;
      control.title = message;
    });
  });
  document.querySelectorAll('[data-open], .quick-create, a[href*="action=create"], a[href*="walkin=1"]').forEach((node) => {
    if (node.matches('a,button,summary')) {
      node.setAttribute('aria-disabled', 'true');
      node.addEventListener('click', (event) => {
        event.preventDefault();
        window.alert(message);
      });
    }
  });
})();
