/** * Help Button Component * Provides context-aware help based on the current page */ class HelpButton { constructor(options = {}) { this.options = Object.assign({ position: 'bottom-right', icon: 'question-circle', text: 'Help', autoDetect: true }, options); this.pageToTourMap = { '/inventory/': 'inventory_overview', '/inventory/add/': 'add_new_car', '/inventory/edit/': 'edit_car', '/finance/invoices/': 'manage_invoices', '/finance/invoices/create/': 'create_new_invoice', '/customers/': 'manage_customers', '/customers/add/': 'add_new_customer' }; this.render(); this.attachEvents(); } render() { // Create the help button const button = document.createElement('div'); button.className = `help-button ${this.options.position}`; button.innerHTML = ` `; // Add styles const style = document.createElement('style'); style.textContent = ` .help-button { position: fixed; z-index: 1000; } .help-button.bottom-right { bottom: 20px; right: 20px; } .help-button.bottom-left { bottom: 20px; left: 20px; } .help-button.top-right { top: 20px; right: 20px; } .help-button.top-left { top: 20px; left: 20px; } `; document.head.appendChild(style); document.body.appendChild(button); } attachEvents() { const helpButton = document.getElementById('context-help-btn'); if (!helpButton) return; helpButton.addEventListener('click', () => { this.showContextHelp(); }); // Initialize tooltip new bootstrap.Tooltip(helpButton); } showContextHelp() { // Detect current page and show appropriate tour if (this.options.autoDetect) { const currentPath = window.location.pathname; let tourSlug = null; // Find the best match for the current path for (const [path, slug] of Object.entries(this.pageToTourMap)) { if (currentPath.includes(path)) { tourSlug = slug; break; } } if (tourSlug) { window.tourManager.loadTour(tourSlug); return; } } // If no specific tour found or autoDetect is off, show help menu this.showHelpMenu(); } showHelpMenu() { // Create a modal with available help options const modal = document.createElement('div'); modal.className = 'modal fade'; modal.id = 'helpModal'; modal.setAttribute('tabindex', '-1'); modal.innerHTML = ` `; document.body.appendChild(modal); const modalInstance = new bootstrap.Modal(modal); modalInstance.show(); // Remove modal from DOM after it's hidden modal.addEventListener('hidden.bs.modal', () => { modal.remove(); }); } } // Initialize help button on all pages document.addEventListener('DOMContentLoaded', () => { window.helpButton = new HelpButton(); }); // export { HelpButton };