const fs = require('fs'); const path = require('path'); const BOOTSTRAP_ICON_CSS_PATH = path.join(__dirname, '..', 'web', 'public', 'adminlte', 'bootstrap-icons', 'css', 'bootstrap-icons.min.css'); const DEFAULT_ANNOUNCEMENT_ICON_KEYS = [ 'megaphone-fill', 'megaphone', 'bell-fill', 'bell', 'exclamation-triangle-fill', 'exclamation-triangle', 'info-circle-fill', 'info-circle', 'check-circle-fill', 'check-circle', 'lightbulb-fill', 'lightbulb', 'calendar-event-fill', 'calendar-event', 'clock-fill', 'clock', 'wifi-off', 'wifi', 'hdd-network', 'hdd-network-fill', 'speaker-fill', 'speaker', 'shield-fill', 'shield', 'collection-play-fill', 'collection-play', 'broadcast', 'broadcast-pin', 'plug-fill', 'plug', 'lightning-charge-fill', 'lightning-charge', 'car-front-fill', 'car-front', 'lamp-fill', 'lamp', 'envelope-fill', 'envelope', 'people-fill', 'people', 'browser-chrome', 'browser-edge', 'browser-firefox', 'browser-safari', 'cone', 'cone-striped', 'cup-straw', 'fire' ]; function humanizeBootstrapIconLabel(iconKey) { return String(iconKey || '') .trim() .replace(/[-_]+/g, ' ') .replace(/\b\w/g, function (character) { return character.toUpperCase(); }); } function loadBootstrapIconCatalog() { try { const css = fs.readFileSync(BOOTSTRAP_ICON_CSS_PATH, 'utf8'); const keys = Array.from(new Set((css.match(/\.bi-([a-z0-9-]+)::?before/g) || []).map(function (match) { return String(match || '') .replace(/^\.bi-/, '') .replace(/::?before$/, '') .trim() .toLowerCase(); }).filter(Boolean))); return keys.map(function (value) { return { value: value, label: humanizeBootstrapIconLabel(value) }; }).sort(function (left, right) { return left.value.localeCompare(right.value); }); } catch (_error) { return DEFAULT_ANNOUNCEMENT_ICON_KEYS.map(function (value) { return { value: value, label: humanizeBootstrapIconLabel(value) }; }); } } const ANNOUNCEMENT_ICON_CATALOG = loadBootstrapIconCatalog(); const ANNOUNCEMENT_ICON_OPTIONS = DEFAULT_ANNOUNCEMENT_ICON_KEYS.map(function (value) { const catalogOption = ANNOUNCEMENT_ICON_CATALOG.find(function (option) { return option.value === value; }); return catalogOption || { value: value, label: humanizeBootstrapIconLabel(value) }; }); const ANNOUNCEMENT_ICON_KEYS = DEFAULT_ANNOUNCEMENT_ICON_KEYS.slice(); const ANNOUNCEMENT_ICON_CATALOG_KEYS = ANNOUNCEMENT_ICON_CATALOG.map(function (option) { return option.value; }); const ANNOUNCEMENT_ICON_LABELS = ANNOUNCEMENT_ICON_OPTIONS.reduce(function (labels, option) { labels[option.value] = option.label; return labels; }, Object.create(null)); ANNOUNCEMENT_ICON_CATALOG.forEach(function (option) { if (!Object.prototype.hasOwnProperty.call(ANNOUNCEMENT_ICON_LABELS, option.value)) { ANNOUNCEMENT_ICON_LABELS[option.value] = option.label; } }); const DEFAULT_ANNOUNCEMENT_ICON = 'megaphone-fill'; function normalizeAnnouncementIcon(value) { const normalized = String(value || '').trim().toLowerCase(); return ANNOUNCEMENT_ICON_CATALOG_KEYS.includes(normalized) ? normalized : DEFAULT_ANNOUNCEMENT_ICON; } module.exports = { DEFAULT_ANNOUNCEMENT_ICON_KEYS, ANNOUNCEMENT_ICON_OPTIONS, ANNOUNCEMENT_ICON_KEYS, ANNOUNCEMENT_ICON_CATALOG, ANNOUNCEMENT_ICON_CATALOG_KEYS, ANNOUNCEMENT_ICON_LABELS, DEFAULT_ANNOUNCEMENT_ICON, humanizeBootstrapIconLabel, normalizeAnnouncementIcon };