(function() {
	'use strict';

	var config = window.wppsRemoveAdminNotices || {};
	var settings = {
		hide_core: !!config.hide_core,
		hide_plugins: !!config.hide_plugins,
		hide_themes: !!config.hide_themes,
		hide_errors: !!config.hide_errors
	};
	var strings = config.strings || {};
	var strNotices = strings.notices || 'Notices';
	var strClose = strings.close || 'Close';
	var strPanelLabel = strings.panel_label || 'Admin notices panel';
	var strEmpty = strings.empty || 'No notices to display.';
	var strEmptySettings = strings.empty_settings || 'No notices to display. Select notice sources to hide in module settings.';

	var panel = null;
	var panelContent = null;
	var noticeCountEl = null;
	var observer = null;
	var dismissedNotices = {};
	var clickOutsideHandlerTimeout = null;
	var panelJustOpened = false;
	var panelOpenedAt = 0;
	var lastMenuClickTime = 0;
	var DISMISS_DURATION = 12 * 60 * 60 * 1000;
	var STORAGE_KEY = 'wpps_dismissed_notices_' + String(config.userId || 0);
	var LEGACY_STORAGE_KEY = 'wpps_dismissed_notices';

	function getNoticeHash(notice) {
		if (!notice) {
			return '';
		}
		var existing = notice.getAttribute('data-wpps-notice-hash');
		if (existing) {
			return existing;
		}
		var noticeText = (notice.textContent || '').trim();
		var noticeHtml = (notice.innerHTML || '').trim();
		if (!noticeText) {
			return '';
		}
		return noticeText.substring(0, 200).replace(/\s+/g, ' ') + '|' + noticeText.length + '|' + noticeHtml.length;
	}

	function hideNoticeElement(notice) {
		if (!notice) {
			return;
		}
		notice.classList.add('wpps-hide-notice');
		notice.style.cssText = 'display: none !important; visibility: hidden !important; opacity: 0 !important; height: 0 !important; margin: 0 !important; padding: 0 !important; overflow: hidden !important; pointer-events: none !important;';
		notice.setAttribute('data-wpps-dismissed', 'true');
	}

	function markMatchingNoticesDismissed(noticeHash) {
		if (!noticeHash) {
			return;
		}
		var allPossibleNotices = document.querySelectorAll('#wpbody-content .notice, #wpbody-content .notice-error, #wpbody-content .notice-warning, #wpbody-content .notice-info, #wpbody-content .notice-success, #wpbody-content .error, #wpbody-content .updated, #wpbody-content .update-nag');
		allPossibleNotices.forEach(function(possibleNotice) {
			if (panelContent && panelContent.contains(possibleNotice)) {
				return;
			}
			if (possibleNotice.closest('#wpadminbar') || possibleNotice.closest('#wpps-notices-panel')) {
				return;
			}
			if (getNoticeHash(possibleNotice) === noticeHash) {
				possibleNotice.setAttribute('data-wpps-notice-hash', noticeHash);
				hideNoticeElement(possibleNotice);
			}
		});
	}

	function applyPersistedDismissals() {
		var allNotices = document.querySelectorAll('#wpbody-content .notice, #wpbody-content .notice-error, #wpbody-content .notice-warning, #wpbody-content .notice-info, #wpbody-content .notice-success, #wpbody-content .error, #wpbody-content .updated, #wpbody-content .update-nag');
		allNotices.forEach(function(notice) {
			if (panelContent && panelContent.contains(notice)) {
				return;
			}
			if (notice.closest('#wpadminbar') || notice.closest('#wpps-notices-panel')) {
				return;
			}
			var noticeHash = getNoticeHash(notice);
			if (noticeHash && isNoticeDismissed(noticeHash)) {
				notice.setAttribute('data-wpps-notice-hash', noticeHash);
				hideNoticeElement(notice);
			}
		});
	}

	function loadDismissedNotices() {
		try {
			var stored = localStorage.getItem(STORAGE_KEY);
			if (!stored && LEGACY_STORAGE_KEY !== STORAGE_KEY) {
				stored = localStorage.getItem(LEGACY_STORAGE_KEY);
				if (stored) {
					localStorage.setItem(STORAGE_KEY, stored);
					localStorage.removeItem(LEGACY_STORAGE_KEY);
				}
			}
			if (stored) {
				var parsed = JSON.parse(stored);
				var now = Date.now();
				var cleaned = {};
				for (var hash in parsed) {
					if (Object.prototype.hasOwnProperty.call(parsed, hash)) {
						var dismissTime = parsed[hash];
						if (now - dismissTime < DISMISS_DURATION) {
							cleaned[hash] = dismissTime;
						}
					}
				}
				dismissedNotices = cleaned;
				saveDismissedNotices();
				return cleaned;
			}
		} catch (e) {
			console.error('Error loading dismissed notices:', e);
		}
		return {};
	}

	function saveDismissedNotices() {
		try {
			localStorage.setItem(STORAGE_KEY, JSON.stringify(dismissedNotices));
		} catch (e) {
			console.error('Error saving dismissed notices:', e);
		}
	}

	function isNoticeDismissed(noticeHash) {
		if (!noticeHash || !dismissedNotices[noticeHash]) {
			return false;
		}
		var dismissTime = dismissedNotices[noticeHash];
		var now = Date.now();
		var elapsed = now - dismissTime;
		if (elapsed >= DISMISS_DURATION) {
			delete dismissedNotices[noticeHash];
			saveDismissedNotices();
			return false;
		}
		return true;
	}

	function dismissNotice(noticeHash) {
		if (noticeHash) {
			dismissedNotices[noticeHash] = Date.now();
			saveDismissedNotices();
		}
	}

	dismissedNotices = loadDismissedNotices();

	function escAttr(value) {
		return String(value)
			.replace(/&/g, '&amp;')
			.replace(/"/g, '&quot;')
			.replace(/'/g, '&#39;')
			.replace(/</g, '&lt;');
	}

	function setPanelOpenState(isOpen) {
		if (!panel) {
			return;
		}
		if (isOpen) {
			panel.classList.add('is-open');
			document.body.classList.add('wpps-panel-open');
			panel.setAttribute('aria-hidden', 'false');
		} else {
			panel.classList.remove('is-open');
			document.body.classList.remove('wpps-panel-open');
			panel.setAttribute('aria-hidden', 'true');
		}
	}

	function initPanel() {
		if (document.getElementById('wpps-notices-panel')) {
			panel = document.getElementById('wpps-notices-panel');
			panelContent = document.getElementById('wpps-notices-panel-content');
			noticeCountEl = document.querySelector('#wp-admin-bar-wpps-admin-notices .wpps-notice-count');
			setupMenuHandlers();
			return;
		}

		if (!document.body) {
			setTimeout(initPanel, 50);
			return;
		}

		var panelHTML = '<div id="wpps-notices-panel" role="complementary" aria-label="' + escAttr(strPanelLabel) + '" aria-hidden="true">' +
			'<div id="wpps-notices-panel-header">' +
			'<h3>' + strNotices + '</h3>' +
			'<button id="wpps-notices-panel-close" type="button" aria-label="' + strClose + '" title="' + strClose + '"></button>' +
			'</div>' +
			'<div id="wpps-notices-panel-content"></div>' +
			'</div>';
		document.body.insertAdjacentHTML('beforeend', panelHTML);

		panel = document.getElementById('wpps-notices-panel');
		panelContent = document.getElementById('wpps-notices-panel-content');
		noticeCountEl = document.querySelector('#wp-admin-bar-wpps-admin-notices .wpps-notice-count');

		var closeBtn = document.getElementById('wpps-notices-panel-close');
		if (closeBtn) {
			closeBtn.addEventListener('click', function(e) {
				e.preventDefault();
				e.stopPropagation();
				e.stopImmediatePropagation();
				if (clickOutsideHandlerTimeout) {
					clearTimeout(clickOutsideHandlerTimeout);
					clickOutsideHandlerTimeout = null;
				}
				panelJustOpened = false;
				setPanelOpenState(false);
				return false;
			});
			closeBtn.addEventListener('mousedown', function(e) {
				e.preventDefault();
				e.stopPropagation();
				e.stopImmediatePropagation();
			});
		}

		if (panelContent) {
			function handleDismissClick(e) {
				var target = e.target;
				var checkElement = target;
				var dismissBtn = null;

				for (var i = 0; i < 15 && checkElement && checkElement !== panelContent && checkElement !== document.body; i++) {
					var isDismissButton = false;

					if (checkElement.classList) {
						isDismissButton = checkElement.classList.contains('notice-dismiss') ||
							checkElement.classList.contains('notice-dismiss-link') ||
							checkElement.classList.contains('dismiss') ||
							checkElement.getAttribute('data-wpps-dismiss') === 'true';
					}

					if (!isDismissButton && checkElement.getAttribute) {
						var ariaLabel = checkElement.getAttribute('aria-label') || '';
						isDismissButton = ariaLabel.toLowerCase().indexOf('dismiss') !== -1 ||
							ariaLabel.toLowerCase().indexOf('close') !== -1;
					}

					if (!isDismissButton && checkElement.className && typeof checkElement.className === 'string') {
						isDismissButton = checkElement.className.indexOf('dismiss') !== -1;
					}

					if (!isDismissButton && checkElement.tagName) {
						if ((checkElement.tagName === 'BUTTON' || checkElement.tagName === 'A') &&
							checkElement.className && checkElement.className.indexOf('dismiss') !== -1) {
							isDismissButton = true;
						}
					}

					if (!isDismissButton && checkElement.classList && checkElement.closest) {
						var parentNotice = checkElement.closest('.notice, .notice-error, .notice-warning, .notice-info, .notice-success, .error, .updated, .update-nag');
						if (parentNotice && parentNotice.contains(checkElement)) {
							var dismissInNotice = parentNotice.querySelector('.notice-dismiss, button[aria-label*="Dismiss"], button[aria-label*="dismiss"], a[aria-label*="Dismiss"], a[aria-label*="dismiss"], [data-wpps-dismiss="true"]');
							if (dismissInNotice && (dismissInNotice === checkElement || dismissInNotice.contains(checkElement))) {
								isDismissButton = true;
							}
						}
					}

					if (isDismissButton) {
						dismissBtn = checkElement;
						break;
					}

					checkElement = checkElement.parentElement;
				}

				if (dismissBtn) {
					e.preventDefault();
					e.stopPropagation();
					e.stopImmediatePropagation();

					var noticeElement = dismissBtn.closest ? dismissBtn.closest('.notice, .notice-error, .notice-warning, .notice-info, .notice-success, .error, .updated, .update-nag') : null;

					if (!noticeElement) {
						var parent = dismissBtn.parentElement;
						var maxDepth = 15;
						var depth = 0;
						while (parent && parent !== panelContent && parent !== document.body && depth < maxDepth) {
							if (parent.classList && (
								parent.classList.contains('notice') ||
								parent.classList.contains('notice-error') ||
								parent.classList.contains('notice-warning') ||
								parent.classList.contains('notice-info') ||
								parent.classList.contains('notice-success') ||
								parent.classList.contains('error') ||
								parent.classList.contains('updated') ||
								parent.classList.contains('update-nag')
							)) {
								noticeElement = parent;
								break;
							}
							parent = parent.parentElement;
							depth++;
						}
					}

					if (noticeElement && panelContent.contains(noticeElement)) {
						var noticeHash = getNoticeHash(noticeElement);

						if (noticeHash) {
							dismissNotice(noticeHash);
							markMatchingNoticesDismissed(noticeHash);
						}

						hideNoticeElement(noticeElement);

						setTimeout(function() {
							if (noticeElement && noticeElement.parentNode) {
								noticeElement.parentNode.removeChild(noticeElement);
							}
							collectNotices();
						}, 50);
					}

					return false;
				}
			}

			panelContent.addEventListener('click', handleDismissClick, true);
			panelContent.addEventListener('mousedown', handleDismissClick, true);
		}

		setupMenuHandlers();
		setupClickOutsideHandler();
	}

	var menuClickHandler = null;

	function setupMenuHandlers() {
		var menuItem = document.getElementById('wp-admin-bar-wpps-admin-notices');
		if (!menuItem) {
			var adminBar = document.getElementById('wpadminbar');
			if (adminBar) {
				menuItem = adminBar.querySelector('#wp-admin-bar-wpps-admin-notices');
			}
		}

		if (menuItem) {
			var link = menuItem.querySelector('a');
			if (link) {
				var existingHandler = link.getAttribute('data-wpps-handler');
				if (!existingHandler) {
					if (!menuClickHandler) {
						menuClickHandler = function(e) {
							lastMenuClickTime = Date.now();
							if (e) {
								e.preventDefault();
								e.stopPropagation();
								e.stopImmediatePropagation();
							}
							if (clickOutsideHandlerTimeout) {
								clearTimeout(clickOutsideHandlerTimeout);
								clickOutsideHandlerTimeout = null;
							}
							handleMenuClick(e);
							if (e) {
								return false;
							}
						};
					}
					link.removeEventListener('click', menuClickHandler);
					link.removeEventListener('mousedown', menuClickHandler);
					link.addEventListener('click', menuClickHandler, true);
					link.setAttribute('data-wpps-handler', 'true');
					link.setAttribute('href', '#');
					link.onclick = menuClickHandler;
				}
			} else {
				setTimeout(setupMenuHandlers, 100);
			}
		} else {
			setTimeout(setupMenuHandlers, 200);
		}
	}

	function handleMenuClick(e) {
		lastMenuClickTime = Date.now();

		if (e) {
			e.preventDefault();
			e.stopPropagation();
			e.stopImmediatePropagation();
			if (clickOutsideHandlerTimeout) {
				clearTimeout(clickOutsideHandlerTimeout);
				clickOutsideHandlerTimeout = null;
			}
		}

		if (!panel || !panelContent) {
			initPanel();
			setTimeout(function() {
				if (panel) {
					panelOpenedAt = Date.now();
					panelJustOpened = true;
					setPanelOpenState(true);
					setTimeout(collectNotices, 50);
					setTimeout(function() {
						panelJustOpened = false;
						setupClickOutsideHandler();
					}, 2000);
				}
			}, 50);
			if (e) {
				return false;
			}
			return;
		}

		var isOpen = panel.classList.contains('is-open');

		if (isOpen) {
			panelJustOpened = false;
			setPanelOpenState(false);
		} else {
			panelOpenedAt = Date.now();
			panelJustOpened = true;
			setPanelOpenState(true);
			setTimeout(collectNotices, 50);
			setTimeout(function() {
				panelJustOpened = false;
				setupClickOutsideHandler();
			}, 2000);
		}

		if (e) {
			return false;
		}
	}

	var clickOutsideHandler = null;
	var clickOutsideHandlerActive = false;

	function setupClickOutsideHandler() {
		if (clickOutsideHandlerActive) {
			return;
		}
		setTimeout(function() {
			clickOutsideHandler = function(e) {
				if (!panel || !panel.classList.contains('is-open')) {
					return;
				}
				var clickTime = Date.now();
				if (clickTime - lastMenuClickTime < 2000) {
					return;
				}
				var now = Date.now();
				if (now - panelOpenedAt < 2000) {
					return;
				}
				if (panelJustOpened) {
					return;
				}
				var target = e.target;
				if (!target) {
					return;
				}
				var menuItem = document.getElementById('wp-admin-bar-wpps-admin-notices');
				var clickedOnPanel = panel.contains(target);
				var clickedOnMenuItem = false;
				if (menuItem) {
					clickedOnMenuItem = (menuItem === target || menuItem.contains(target));
				}
				var clickedOnMenuItemLink = false;
				if (menuItem) {
					var link = menuItem.querySelector('a');
					if (link) {
						clickedOnMenuItemLink = (link === target || link.contains(target));
					}
				}
				var clickedOnCloseBtn = target.id === 'wpps-notices-panel-close' || (target.closest && target.closest('#wpps-notices-panel-close'));
				var isInsideAdminBar = target.closest && target.closest('#wpadminbar');

				if (clickedOnPanel || clickedOnMenuItem || clickedOnMenuItemLink || clickedOnCloseBtn || isInsideAdminBar) {
					if (clickOutsideHandlerTimeout) {
						clearTimeout(clickOutsideHandlerTimeout);
						clickOutsideHandlerTimeout = null;
					}
					return;
				}
				if (clickOutsideHandlerTimeout) {
					clearTimeout(clickOutsideHandlerTimeout);
				}
				clickOutsideHandlerTimeout = setTimeout(function() {
					if (panel && panel.classList.contains('is-open')) {
						var now2 = Date.now();
						if (now2 - panelOpenedAt >= 2000 && !panelJustOpened && now2 - lastMenuClickTime >= 2000) {
							setPanelOpenState(false);
						}
					}
					clickOutsideHandlerTimeout = null;
				}, 200);
			};
			document.addEventListener('click', clickOutsideHandler, false);
			clickOutsideHandlerActive = true;
		}, 3000);
	}

	function isErrorNotice(notice) {
		var classes = notice.className || '';
		return classes.indexOf('notice-error') !== -1 ||
			(classes.indexOf('error') !== -1 && classes.indexOf('notice') === -1) ||
			notice.classList.contains('notice-error');
	}

	function isExcludedNotice(notice) {
		if (!notice || !notice.classList) {
			return true;
		}
		if (notice.id === 'plugin-activated-successfully') {
			return true;
		}
		if (notice.classList.contains('system-notice') ||
			notice.classList.contains('hidden') ||
			notice.classList.contains('inline') ||
			notice.classList.contains('wcml-notice') ||
			notice.classList.contains('update-message')) {
			return true;
		}
		if (notice.closest && (
			notice.closest('.plugin-update-tr') ||
			notice.closest('#loco-notices') ||
			notice.closest('#loco-content') ||
			notice.closest('.active.update-message') ||
			notice.closest('.inactive.update-message')
		)) {
			return true;
		}
		return false;
	}

	function shouldHideNotice(notice) {
		if (!notice || isPowersuiteNotice(notice) || isExcludedNotice(notice)) {
			return false;
		}
		var isError = isErrorNotice(notice);
		if (isError) {
			return !!settings.hide_errors;
		}
		if (settings.hide_core && settings.hide_plugins && settings.hide_themes) {
			return true;
		}
		var source = detectNoticeSource(notice);
		if (source === 'core' && settings.hide_core) {
			return true;
		}
		if (source === 'plugin' && settings.hide_plugins) {
			return true;
		}
		if (source === 'theme' && settings.hide_themes) {
			return true;
		}
		return false;
	}

	function updateMenuCount(count) {
		if (!noticeCountEl) {
			noticeCountEl = document.querySelector('#wp-admin-bar-wpps-admin-notices .wpps-notice-count');
		}
		var menuItem = document.getElementById('wp-admin-bar-wpps-admin-notices');
		if (!menuItem) {
			return;
		}
		if (count > 0) {
			menuItem.classList.add('has-notices');
			menuItem.classList.remove('wpps-notices-menu-item--empty');
			if (noticeCountEl) {
				noticeCountEl.textContent = String(count);
				noticeCountEl.setAttribute('aria-hidden', 'false');
			}
		} else {
			menuItem.classList.remove('has-notices');
			menuItem.classList.add('wpps-notices-menu-item--empty');
			if (noticeCountEl) {
				noticeCountEl.textContent = '';
				noticeCountEl.setAttribute('aria-hidden', 'true');
			}
		}
	}

	function isPowersuiteNotice(notice) {
		if (notice.hasAttribute('data-wpps-plugin') && notice.getAttribute('data-wpps-plugin') === 'true') {
			return true;
		}
		var text = (notice.textContent || '').toLowerCase();
		var html = (notice.innerHTML || '').toLowerCase();
		if (text.match(/settings saved successfully|view mode saved successfully|column settings saved successfully|form saved successfully|custom post type saved successfully|plugin has been reset successfully/i) ||
			html.match(/settings saved successfully|view mode saved successfully|column settings saved successfully|form saved successfully|custom post type saved successfully|plugin has been reset successfully/i)) {
			notice.setAttribute('data-wpps-plugin', 'true');
			return true;
		}
		var parent = notice.parentElement;
		var maxDepth = 5;
		var depth = 0;
		while (parent && depth < maxDepth) {
			var parentClasses = parent.className || '';
			var parentId = parent.id || '';
			if (parentClasses.match(/wp-powersuite-settings|wp-powersuite-reset-modal|wp-powersuite-module-settings/i) || parentId.match(/wp-powersuite/i)) {
				notice.setAttribute('data-wpps-plugin', 'true');
				return true;
			}
			parent = parent.parentElement;
			depth++;
		}
		return false;
	}

	function detectNoticeSource(notice) {
		var classes = notice.className || '';
		var id = notice.id || '';
		var combined = classes + ' ' + id;
		var text = notice.textContent || '';
		var html = notice.innerHTML || '';

		if (notice.hasAttribute('data-plugin') ||
			notice.hasAttribute('data-slug') ||
			combined.match(/plugin|woocommerce|elementor|yoast|jetpack|akismet|contact-form|gravityforms|wpforms|ninja-forms|formidable|wp-rocket|w3-total-cache|wp-super-cache|wordfence|sucuri|ithemes|updraft|backupbuddy|duplicator|all-in-one-wp-migration|wp-migrate|redirection|really-simple-ssl|security|seo|optimize|cache|backup|migration|form|slider|gallery|builder|page-builder/i)) {
			if (!text.match(/wordpress.*update|core.*update|wordpress.*version|update.*wordpress/i)) {
				return 'plugin';
			}
		}

		if (combined.match(/theme|astra|generatepress|oceanwp|neve|kadence|blocksy|storefront|twentytwenty|twentytwentyone|twentytwentytwo|twentytwentythree|twentytwentyfour|twentytwentyfive/i) ||
			text.match(/(theme|template).*(activated|updated|installed|available)/i) ||
			html.match(/<strong>.*theme.*<\/strong>/i)) {
			return 'theme';
		}

		var parent = notice.parentElement;
		var maxDepth = 5;
		var depth = 0;
		while (parent && depth < maxDepth) {
			var parentClasses = parent.className || '';
			var parentId = parent.id || '';
			var parentCombined = parentClasses + ' ' + parentId;
			if (parentCombined.match(/plugin|woocommerce|elementor|yoast|jetpack/i)) {
				return 'plugin';
			}
			if (parentCombined.match(/theme|template/i)) {
				return 'theme';
			}
			parent = parent.parentElement;
			depth++;
		}

		if (text.match(/wordpress|core|update.*available|security.*update|maintenance.*mode|database.*update|translation.*update/i) ||
			html.match(/wordpress.*update|core.*update/i) ||
			classes.match(/update-nag|update-message/i)) {
			return 'core';
		}

		if (window.location.href.match(/plugins\.php|themes\.php/i)) {
			if (text.match(/activated|deactivated|updated|installed/i)) {
				if (window.location.href.match(/plugins\.php/i)) {
					return 'plugin';
				}
				if (window.location.href.match(/themes\.php/i)) {
					return 'theme';
				}
			}
		}

		return 'plugin';
	}

	var lastCollectTime = 0;
	var COLLECT_THROTTLE_MS = 1000;

	function collectNotices() {
		var now = Date.now();
		if (now - lastCollectTime < COLLECT_THROTTLE_MS) {
			return;
		}
		lastCollectTime = now;

		if (!panelContent) {
			setTimeout(collectNotices, 100);
			return;
		}

		if (!settings.hide_core && !settings.hide_plugins && !settings.hide_themes && !settings.hide_errors) {
			panelContent.innerHTML = '<div id="wpps-notices-panel-empty">' + strEmptySettings + '</div>';
			updateMenuCount(0);
			return;
		}

		var allNotices = document.querySelectorAll('#wpbody-content .notice, #wpbody-content .notice-error, #wpbody-content .notice-warning, #wpbody-content .notice-info, #wpbody-content .notice-success, #wpbody-content .error, #wpbody-content .updated, #wpbody-content .update-nag');

		var notices = Array.prototype.filter.call(allNotices, function(notice) {
			if (panelContent && panelContent.contains(notice)) {
				return false;
			}
			if (notice.closest('#wpadminbar')) {
				return false;
			}
			if (notice.closest('#wpps-notices-panel')) {
				return false;
			}
			if (isPowersuiteNotice(notice) || isExcludedNotice(notice)) {
				return false;
			}
			if (notice.getAttribute('data-wpps-dismissed') === 'true') {
				return false;
			}
			var noticeText = notice.textContent.trim();
			if (!noticeText || noticeText.length === 0) {
				return false;
			}
			if (noticeText.match(/^This widget requires JavaScript/i)) {
				return false;
			}
			var noticeHash = getNoticeHash(notice);
			if (noticeHash && isNoticeDismissed(noticeHash)) {
				return false;
			}
			return shouldHideNotice(notice);
		});

		var seen = [];
		var uniqueNotices = [];
		notices.forEach(function(notice) {
			var text = notice.textContent.trim();
			if (!text || text.length === 0) {
				return;
			}
			if (text.match(/^This widget requires JavaScript/i)) {
				return;
			}
			var html = notice.innerHTML.trim();
			var identifier = text + '|' + html.length;
			var hash = getNoticeHash(notice);
			if (hash && isNoticeDismissed(hash)) {
				return;
			}
			if (notice.getAttribute('data-wpps-dismissed') === 'true') {
				return;
			}
			if (text && seen.indexOf(identifier) === -1) {
				seen.push(identifier);
				uniqueNotices.push(notice);
			}
		});

		panelContent.innerHTML = '';

		if (uniqueNotices.length === 0) {
			panelContent.innerHTML = '<div id="wpps-notices-panel-empty">' + strEmpty + '</div>';
			updateMenuCount(0);
			return;
		}

		uniqueNotices.forEach(function(notice) {
			var noticeHash = getNoticeHash(notice);

			if (isNoticeDismissed(noticeHash)) {
				return;
			}

			notice.classList.add('wpps-hide-notice');
			notice.setAttribute('data-wpps-notice-hash', noticeHash);

			var clone = notice.cloneNode(true);
			clone.classList.remove('wpps-hide-notice');
			clone.setAttribute('data-wpps-notice-hash', noticeHash);
			clone.style.display = 'block';
			clone.style.visibility = 'visible';
			clone.style.opacity = '1';

			var dismissSelectors = [
				'.notice-dismiss', '.notice-dismiss-link', 'button.notice-dismiss', 'a.notice-dismiss',
				'[aria-label*="Dismiss"]', '[aria-label*="dismiss"]', '[aria-label*="Close"]', '[aria-label*="close"]'
			];

			dismissSelectors.forEach(function(selector) {
				try {
					var dismissElements = clone.querySelectorAll(selector);
					dismissElements.forEach(function(elem) {
						if (elem.tagName === 'A') {
							elem.setAttribute('href', 'javascript:void(0);');
							elem.removeAttribute('onclick');
						}
						if (elem.tagName === 'BUTTON') {
							elem.setAttribute('type', 'button');
						}
						elem.removeAttribute('onclick');
						elem.removeAttribute('data-dismiss');
						elem.setAttribute('data-wpps-dismiss', 'true');
						elem.style.cursor = 'pointer';
						elem.style.pointerEvents = 'auto';
						elem.onclick = null;
						elem.onmousedown = null;
					});
				} catch (e) {}
			});

			if (clone.querySelectorAll('[data-wpps-dismiss="true"]').length === 0) {
				var allButtons = clone.querySelectorAll('button, a');
				allButtons.forEach(function(btn) {
					if (btn.getAttribute('aria-label') && (
						btn.getAttribute('aria-label').toLowerCase().indexOf('dismiss') !== -1 ||
						btn.getAttribute('aria-label').toLowerCase().indexOf('close') !== -1
					)) {
						btn.setAttribute('data-wpps-dismiss', 'true');
						if (btn.tagName === 'A') {
							btn.setAttribute('href', 'javascript:void(0);');
						}
						btn.onclick = null;
						btn.onmousedown = null;
					}
				});
			}

			panelContent.appendChild(clone);
		});

		updateMenuCount(uniqueNotices.length);
	}

	function runInitialCollectPoll() {
		var startTime = Date.now();
		var pollInterval = setInterval(function() {
			hideNoticesBySource();
			if (panel && panel.classList.contains('is-open')) {
				collectNotices();
			} else {
				updateMenuCount(countHiddenNotices());
			}
			if (Date.now() - startTime > 1050) {
				clearInterval(pollInterval);
				hideNoticesBySource();
				updateMenuCount(countHiddenNotices());
			}
		}, 250);
	}

	function countHiddenNotices() {
		if (!settings.hide_core && !settings.hide_plugins && !settings.hide_themes && !settings.hide_errors) {
			return 0;
		}
		var allNotices = document.querySelectorAll('#wpbody-content .notice, #wpbody-content .notice-error, #wpbody-content .notice-warning, #wpbody-content .notice-info, #wpbody-content .notice-success, #wpbody-content .error, #wpbody-content .updated, #wpbody-content .update-nag');
		var count = 0;
		var seen = [];
		Array.prototype.forEach.call(allNotices, function(notice) {
			if (!shouldHideNotice(notice)) {
				return;
			}
			var text = (notice.textContent || '').trim();
			if (!text) {
				return;
			}
			var id = text + '|' + notice.innerHTML.length;
			if (seen.indexOf(id) === -1) {
				seen.push(id);
				count++;
			}
		});
		return count;
	}

	function markPowersuiteNotices() {
		var notices = document.querySelectorAll('.notice, .notice-error, .notice-warning, .notice-info, .notice-success, .error, .updated, .update-nag');
		notices.forEach(function(notice) {
			if (notice.hasAttribute('data-wpps-plugin')) {
				return;
			}
			var text = (notice.textContent || '').toLowerCase();
			var html = (notice.innerHTML || '').toLowerCase();
			if (text.match(/settings saved successfully|view mode saved successfully|column settings saved successfully|form saved successfully|custom post type saved successfully|plugin has been reset successfully|security warning.*disabling updates/i) ||
				html.match(/settings saved successfully|view mode saved successfully|column settings saved successfully|form saved successfully|custom post type saved successfully|plugin has been reset successfully|security warning.*disabling updates/i)) {
				notice.setAttribute('data-wpps-plugin', 'true');
				return;
			}
			var parent = notice.parentElement;
			var maxDepth = 5;
			var depth = 0;
			while (parent && depth < maxDepth) {
				var parentClasses = parent.className || '';
				var parentId = parent.id || '';
				if (parentClasses.match(/wp-powersuite-settings|wp-powersuite-reset-modal|wp-powersuite-module-settings/i) || parentId.match(/wp-powersuite/i)) {
					notice.setAttribute('data-wpps-plugin', 'true');
					return;
				}
				parent = parent.parentElement;
				depth++;
			}
		});
	}

	function initialize() {
		if (!document.body) {
			setTimeout(initialize, 50);
			return;
		}
		markPowersuiteNotices();
		applyPersistedDismissals();

		setInterval(function() {
			var now = Date.now();
			var cleaned = {};
			for (var hash in dismissedNotices) {
				if (Object.prototype.hasOwnProperty.call(dismissedNotices, hash)) {
					var dismissTime = dismissedNotices[hash];
					if (now - dismissTime < DISMISS_DURATION) {
						cleaned[hash] = dismissTime;
					}
				}
			}
			var wasCleaned = Object.keys(dismissedNotices).length !== Object.keys(cleaned).length;
			dismissedNotices = cleaned;
			if (wasCleaned) {
				saveDismissedNotices();
				if (panel && panel.classList.contains('is-open')) {
					collectNotices();
				}
			}
		}, 300000);

		initPanel();

		setTimeout(function() {
			setupMenuHandlers();
			hideNoticesBySource();
			updateMenuCount(countHiddenNotices());
			runInitialCollectPoll();
			if (panel && panel.classList.contains('is-open')) {
				collectNotices();
			}
		}, 500);
	}

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

	if (typeof jQuery !== 'undefined') {
		jQuery(document).ready(function() {
			setTimeout(function() {
				if (!panel) {
					initPanel();
				}
				setupMenuHandlers();
				if (panel && panel.classList.contains('is-open') && panelContent) {
					collectNotices();
				}
			}, 800);
		});
	}

	var lastHideTime = 0;
	var HIDE_THROTTLE_MS = 2000;

	function hideNoticesBySource() {
		var now = Date.now();
		if (now - lastHideTime < HIDE_THROTTLE_MS) {
			return;
		}
		lastHideTime = now;

		if (!settings.hide_core && !settings.hide_plugins && !settings.hide_themes && !settings.hide_errors) {
			var immediateStyle = document.getElementById('wpps-hide-notices-immediate');
			if (immediateStyle) {
				immediateStyle.remove();
			}
			var allNotices = document.querySelectorAll('#wpbody-content .notice, #wpbody-content .notice-error, #wpbody-content .notice-warning, #wpbody-content .notice-info, #wpbody-content .notice-success, #wpbody-content .error, #wpbody-content .updated, #wpbody-content .update-nag');
			allNotices.forEach(function(notice) {
				notice.classList.remove('wpps-hide-notice');
				notice.style.display = '';
				notice.style.visibility = '';
				notice.style.opacity = '';
			});
			return;
		}

		var tempStyle = document.createElement('style');
		tempStyle.id = 'wpps-temp-detect-notices';
		tempStyle.textContent = '.notice, .notice-error, .notice-warning, .notice-info, .notice-success, .error, .updated, .update-nag { display: block !important; visibility: visible !important; opacity: 1 !important; }';
		document.head.appendChild(tempStyle);

		var allNotices = document.querySelectorAll('#wpbody-content .notice, #wpbody-content .notice-error, #wpbody-content .notice-warning, #wpbody-content .notice-info, #wpbody-content .notice-success, #wpbody-content .error, #wpbody-content .updated, #wpbody-content .update-nag');

		allNotices.forEach(function(notice) {
			if (panelContent && panelContent.contains(notice)) {
				return;
			}
			if (notice.closest('#wpadminbar')) {
				return;
			}
			if (notice.closest('#wpps-notices-panel')) {
				return;
			}
			if (isPowersuiteNotice(notice) || isExcludedNotice(notice)) {
				return;
			}
			var noticeText = notice.textContent.trim();
			if (!noticeText || noticeText.length === 0) {
				return;
			}
			if (noticeText.match(/^This widget requires JavaScript/i)) {
				return;
			}
			var noticeHash = getNoticeHash(notice);
			if (noticeHash && isNoticeDismissed(noticeHash)) {
				hideNoticeElement(notice);
				return;
			}
			if (shouldHideNotice(notice)) {
				notice.classList.add('wpps-hide-notice');
			} else {
				notice.classList.remove('wpps-hide-notice');
				notice.style.display = '';
				notice.style.visibility = '';
				notice.style.opacity = '';
			}
		});

		setTimeout(function() {
			if (tempStyle.parentNode) {
				document.head.removeChild(tempStyle);
			}
		}, 50);
	}

	if (typeof MutationObserver !== 'undefined') {
		var observerThrottle = 0;
		var OBSERVER_THROTTLE_MS = 500;

		observer = new MutationObserver(function() {
			var now = Date.now();
			if (now - observerThrottle < OBSERVER_THROTTLE_MS) {
				return;
			}
			observerThrottle = now;
			var menuItem = document.getElementById('wp-admin-bar-wpps-admin-notices');
			if (menuItem && !menuItem.querySelector('a[data-wpps-handler]')) {
				setupMenuHandlers();
			}
			hideNoticesBySource();
			updateMenuCount(countHiddenNotices());
			if (panel && panel.classList.contains('is-open')) {
				collectNotices();
			}
		});

		function attachNoticeObserver() {
			var targetNode = document.getElementById('wpbody-content') || document.body;
			if (!targetNode) {
				return;
			}
			observer.observe(targetNode, {
				childList: true,
				subtree: true,
				attributes: false,
				characterData: false
			});
		}

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

	setTimeout(function() {
		hideNoticesBySource();
		updateMenuCount(countHiddenNotices());
	}, 300);

	setTimeout(function() {
		var menuItem = document.getElementById('wp-admin-bar-wpps-admin-notices');
		if (menuItem) {
			var link = menuItem.querySelector('a');
			if (link && !link.hasAttribute('data-wpps-initialized')) {
				link.setAttribute('data-wpps-initialized', 'true');
				setupMenuHandlers();
			}
		}
	}, 1000);
})();
