import { SmartTables } from '../optional/smartTables/smartTables.bundle.js'; // Wait for the DOM to load before initializing document.addEventListener('DOMContentLoaded', () => { console.log('Initializing SmartTables with JSON data source'); function getEmailProviderIcon(email) { const domain = email.toLowerCase().split('@')[1]?.split('.')[0]; // Extract domain (e.g., "hotmail" from "user@hotmail.com") switch (domain) { case 'hotmail': case 'outlook': return 'fab fa-microsoft'; // Microsoft icon for Hotmail/Outlook case 'gmail': return 'fab fa-google'; // Google icon for Gmail case 'yahoo': return 'fab fa-yahoo'; // Yahoo icon for Yahoo default: return 'fas fa-envelope'; // Default email icon for other providers } } // Initialize SmartTables with the table ID and options const table = new SmartTables('myTable', { data: { type: "json", source: "json/smarttable-data.json", columns: [ { data: "ID", title: "ID" }, { data: "FirstName", title: "First Name" }, { data: "LastName", title: "Last Name" }, { data: "Gender", title: "Gender" }, { data: "Phone", title: "Phone" }, { data: "Status", title: "Payment", render: function(value) { let statusClass = { "Success": "badge bg-success", "Pending": "badge bg-warning text-dark", "Rejected": "badge bg-danger", "Cash": "badge bg-secondary" }[value] || "badge bg-dark"; return '' + value + ''; } }, { data: "Due", title: "Sales", render: function(value) { return '$' + parseFloat(value).toFixed(2); } }, { data: "Product", title: "Product", render: function(value, row) { if (!value) return ''; // Handle null/undefined values // Check if the row has a ProductImage if (row.ProductImage) { return `${value}`; } return value; // Return the product name as plain text if no image } }, { data: "Department", title: "POS" }, { data: "Email", title: "Email", render: function (value) { if (!value) return ''; // Handle null/undefined values const lowerCaseEmail = value.toLowerCase(); // Convert email to lowercase const iconClass = getEmailProviderIcon(lowerCaseEmail); // Get the appropriate icon return `${lowerCaseEmail}`; } }, { data: "City", title: "Area" }, { data: "Address", title: "Address" }, { data: "Company", title: "Company" }, { data: "CreatedDate", title: "Created Date" } ] }, perPage: 15, search: true, sort: true, pagination: true, export: true, print: true, import: true, debug: false, responsive: { enabled: true, breakpoint: 768, columnPriorities: { 0: 1, // ID - highest priority (never hide) 1: 2, // First Name - second highest priority 2: 3, // Last Name - third priority 3: 4, // Gender - fourth priority 4: 5, // Phone - fifth priority 5: 6 // Status - lowest priority (hide first) } }, hooks: { beforeInit: function() { console.log('SmartTables: Before initialization'); }, afterInit: function() { console.log('SmartTables: After initialization complete'); }, afterDraw: function() { console.log('SmartTables: Table drawn'); // Initialize popovers for products with images const popoverElements = document.querySelectorAll('.product-name'); popoverElements.forEach(element => { // Destroy any existing popover to avoid duplicates if (element._popover) { bootstrap.Popover.getInstance(element).dispose(); } // Initialize new popover with explicit top placement and high z-index new bootstrap.Popover(element, { placement: 'top', // Forces the popover to appear on top trigger: 'hover', // Ensures popover appears on hover customClass: 'popover-body-p-0', // Custom class to control styling }); }); } } }); });