/**
 * Service Icon Mapping Utility
 *
 * Maps internal service identifiers to icon React components.
 * Supports both simple-icons and custom icon components.
 * Provides centralized icon resolution with fallback support.
 *
 * Note: Not all services have dedicated icons in simple-icons.
 * Services without icons will return null and use fallback rendering.
 *
 * @module serviceIconMapping
 */

import {
  SiMailchimp,
  SiDiscord,
  SiHubspot,
  SiWordpress,
  SiWoo,
  SiZapier,
  SiAirtable,
  SiKit,
  SiCampaignmonitor,
  SiNotion,
} from '@icons-pack/react-simple-icons';

/**
 * Type definition for icon components (simple-icons or custom)
 */
type IconComponent = typeof SiMailchimp;

/**
 * Mapping of internal service identifiers to icon components.
 *
 * Services without dedicated icons are NOT included in this map
 * and will use fallback icons.
 *
 * @constant
 */
export const serviceIconMap: Record<string, IconComponent> = {
  // Email Marketing
  mailchimp: SiMailchimp,
  kit: SiKit,
  convertkit: SiKit,
  campaignmonitor: SiCampaignmonitor,
  'campaign-monitor': SiCampaignmonitor,

  // Communication
  discord: SiDiscord,

  // CRM
  hubspot: SiHubspot,

  // WordPress Ecosystem
  wordpress: SiWordpress,
  woocommerce: SiWoo,

  // Webhooks & Automation
  zapier: SiZapier,
  'zapier-webhooks': SiZapier,

  // Productivity
  notion: SiNotion,

  // Databases
  airtable: SiAirtable,
};

/**
 * Resolves a service identifier to its corresponding simple-icons component.
 *
 * Performs case-insensitive lookup to handle variations in service naming.
 * Returns null if no mapping exists, allowing callers to implement fallback logic.
 *
 * @param service - Service identifier (e.g., 'mailchimp', 'slack', 'WordPress')
 * @returns The icon component if found, null otherwise
 */
export const getIconComponent = (service: string): IconComponent | null => {
  const normalizedService = service.toLowerCase();
  return serviceIconMap[normalizedService] || null;
};
