/**
 * Contact Card Widget
 * 
 * Displays contact information in a styled card.
 * Uses the shared ContactCard component.
 * 
 * @updated 1.6.0 - Migrated to shared component
 */

import { ContactCard } from '@shared/components/widgets/ContactCard';
import type { GlobalValues } from '@/utils/resolveAppearance';
import type { ContactCardWidgetSettings } from '@shared/components/widgets/ContactCard';

interface ContactInfo {
  name: string
  title?: string
  phone?: string
  email?: string
  location?: string
  whatsapp?: string
  avatar?: string
}

interface ContactCardWidgetProps {
  config: {
    contact?: ContactInfo
    contacts?: ContactInfo[]
    show_call_button?: boolean
    show_message_button?: boolean
    is_rtl?: boolean
  }
  widgetSettings?: ContactCardWidgetSettings
  globalValues?: GlobalValues
  language?: string
  onCall?: (phone: string) => void
  onMessage?: (contact: { name: string; email?: string; whatsapp?: string }) => void
}

export function ContactCardWidget({ 
  config, 
  widgetSettings, 
  globalValues = {},
  language,
  onCall, 
  onMessage 
}: ContactCardWidgetProps) {
  const { 
    contact: singleContact, 
    contacts: multipleContacts,
    show_call_button = true, 
    show_message_button = true, 
    is_rtl = true 
  } = config || {};

  const contact = singleContact || (multipleContacts && multipleContacts.length > 0 ? multipleContacts[0] : undefined);

  if (!contact || !contact.name) {
    return null;
  }

  return (
    <>
      <ContactCard
        globalValues={globalValues as any}
        widgetSettings={widgetSettings as any}
        context="live"
        isRTL={is_rtl}
        language={language}
        contact={contact}
        showCallButton={show_call_button}
        showMessageButton={show_message_button}
        onCall={onCall}
        onMessage={onMessage}
      />
      {multipleContacts && multipleContacts.length > 1 && multipleContacts.slice(1).map((c, i) => (
        <ContactCard
          key={`contact-${i}`}
          globalValues={globalValues as any}
          widgetSettings={widgetSettings as any}
          context="live"
          isRTL={is_rtl}
          language={language}
          contact={c}
          showCallButton={show_call_button}
          showMessageButton={show_message_button}
          onCall={onCall}
          onMessage={onMessage}
        />
      ))}
    </>
  );
}

export default ContactCardWidget;

