124 lines
4.8 KiB
TypeScript
124 lines
4.8 KiB
TypeScript
export function formatCurrency(amount: number, currency: string = 'IRR'): string {
|
|
if (currency === 'IRR') {
|
|
return `${amount.toLocaleString('fa-IR')} ریال`;
|
|
}
|
|
return `$${amount.toFixed(2)}`;
|
|
}
|
|
|
|
export function formatDate(dateString: string): string {
|
|
if (!dateString) return '-';
|
|
const date = new Date(dateString);
|
|
return date.toLocaleDateString('fa-IR', {
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
});
|
|
}
|
|
|
|
export function formatDateTime(dateString: string): string {
|
|
if (!dateString) return '-';
|
|
const date = new Date(dateString);
|
|
return date.toLocaleDateString('fa-IR', {
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
});
|
|
}
|
|
|
|
export function getStatusColor(status: string): string {
|
|
const colorMap: Record<string, string> = {
|
|
active: 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400',
|
|
inactive: 'bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400',
|
|
pending: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400',
|
|
accepted: 'bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400',
|
|
rejected: 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400',
|
|
delivered: 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400',
|
|
'assigned-sender-agent': 'bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400',
|
|
'assigned-receiver-agent': 'bg-indigo-100 text-indigo-800 dark:bg-indigo-900/30 dark:text-indigo-400',
|
|
'ready-to-return': 'bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-400',
|
|
returned: 'bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400',
|
|
enumerated: 'bg-teal-100 text-teal-800 dark:bg-teal-900/30 dark:text-teal-400',
|
|
draft: 'bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400',
|
|
completed: 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400',
|
|
paused: 'bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-400',
|
|
cancelled: 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400',
|
|
paid: 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400',
|
|
unpaid: 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400',
|
|
'waiting-to-pay': 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400',
|
|
processing: 'bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400',
|
|
preparing: 'bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400',
|
|
prepared: 'bg-indigo-100 text-indigo-800 dark:bg-indigo-900/30 dark:text-indigo-400',
|
|
'given-to-post': 'bg-cyan-100 text-cyan-800 dark:bg-cyan-900/30 dark:text-cyan-400',
|
|
'system-cancellation': 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400',
|
|
Success: 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400',
|
|
Failed: 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400',
|
|
frozen: 'bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400',
|
|
closed: 'bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400',
|
|
};
|
|
return colorMap[status] || 'bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400';
|
|
}
|
|
|
|
export function getStatusLabel(status: string): string {
|
|
const labelMap: Record<string, string> = {
|
|
'on-table': 'On Table',
|
|
cylindrical: 'Cylindrical',
|
|
'stand-up': 'Stand Up',
|
|
'assigned-sender-agent': 'Assigned Sender',
|
|
'assigned-receiver-agent': 'Assigned Receiver',
|
|
'ready-to-return': 'Ready to Return',
|
|
'given-to-post': 'Given to Post',
|
|
'system-cancellation': 'System Cancellation',
|
|
'waiting-to-pay': 'Waiting to Pay',
|
|
};
|
|
return labelMap[status] || status.charAt(0).toUpperCase() + status.slice(1).replace(/-/g, ' ');
|
|
}
|
|
|
|
export function getKindBoxTypeIcon(type: string): string {
|
|
const icons: Record<string, string> = {
|
|
'on-table': '📦',
|
|
cylindrical: '🥫',
|
|
'stand-up': '🗄️',
|
|
};
|
|
return icons[type] || '📦';
|
|
}
|
|
|
|
export function cn(...classes: (string | undefined | null | false)[]): string {
|
|
return classes.filter(Boolean).join(' ');
|
|
}
|
|
|
|
export function truncateText(text: string, maxLength: number): string {
|
|
if (text.length <= maxLength) return text;
|
|
return text.substring(0, maxLength) + '...';
|
|
}
|
|
|
|
export function generatePagination(currentPage: number, totalPages: number): (number | '...')[] {
|
|
if (totalPages <= 7) {
|
|
return Array.from({ length: totalPages }, (_, i) => i + 1);
|
|
}
|
|
|
|
const pages: (number | '...')[] = [];
|
|
|
|
pages.push(1);
|
|
|
|
if (currentPage > 3) {
|
|
pages.push('...');
|
|
}
|
|
|
|
const start = Math.max(2, currentPage - 1);
|
|
const end = Math.min(totalPages - 1, currentPage + 1);
|
|
|
|
for (let i = start; i <= end; i++) {
|
|
pages.push(i);
|
|
}
|
|
|
|
if (currentPage < totalPages - 2) {
|
|
pages.push('...');
|
|
}
|
|
|
|
pages.push(totalPages);
|
|
|
|
return pages;
|
|
}
|