Files
kitchen-agent/public/js/common.js
2025-10-23 19:02:56 -04:00

60 lines
1.6 KiB
JavaScript

// Common utilities and functions
function showToast(message, type = 'success') {
const toast = document.getElementById('toast');
if (!toast) return;
toast.textContent = message;
toast.className = 'toast visible ' + type;
setTimeout(() => {
toast.classList.remove('visible');
}, 3000);
}
function formatTime(timestamp) {
const date = new Date(timestamp * 1000);
return date.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit'
});
}
function formatDateTime(timestamp) {
const date = new Date(timestamp * 1000);
return date.toLocaleString('en-US', {
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
}
function formatCurrency(amount) {
return '$' + (amount || 0).toFixed(2);
}
// Tab switching functionality
document.addEventListener('DOMContentLoaded', function() {
const tabButtons = document.querySelectorAll('.tab-btn');
const tabContents = document.querySelectorAll('.tab-content');
tabButtons.forEach(button => {
button.addEventListener('click', function() {
const targetTab = this.dataset.tab;
// Remove active class from all buttons and contents
tabButtons.forEach(btn => btn.classList.remove('active'));
tabContents.forEach(content => content.classList.remove('active'));
// Add active class to clicked button and corresponding content
this.classList.add('active');
const targetContent = document.getElementById(targetTab + '-tab');
if (targetContent) {
targetContent.classList.add('active');
}
});
});
});