import type { ProviderMapping } from '../types';

export function formatDate(dateString: string): string {
  return new Date(dateString).toLocaleDateString();
}

export function formatProviderMapping(mapping: ProviderMapping): string {
  return `${mapping.provider.toLowerCase()}(${mapping.provider_exchange_code})`;
}

export function getProviderMappingColor(mapping: ProviderMapping): string {
  return mapping.active ? 'text-green-500' : 'text-text-muted';
}

export function sortProviderMappings(mappings: ProviderMapping[]): ProviderMapping[] {
  return [...mappings].sort((a, b) => {
    // Active mappings first
    if (a.active && !b.active) {
      return -1;
    }
    if (!a.active && b.active) {
      return 1;
    }

    // Then by provider name
    return a.provider.localeCompare(b.provider);
  });
}

export function truncateText(text: string, maxLength: number): string {
  if (text.length <= maxLength) {
    return text;
  }
  return text.substring(0, maxLength) + '...';
}
