import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
import { useTheme } from '@theme';
import { getStyles } from './customerDetailHeader.styles';
import { CustomerDetailHeaderProps } from './customerDetailHeader.props';
import { getInitials, formatDate } from '@utils';

export const CustomerDetailHeader: React.FC<CustomerDetailHeaderProps> = ({
  company,
  fullname,
  active,
  datecreated,
  email,
  phonenumber,
  website,
  onEmailPress,
  onPhonePress,
  onWebsitePress,
}) => {
  const { theme: colors } = useTheme();
  const styles = getStyles(colors);

  const displayName = company || fullname || 'Customer';
  const initials = getInitials(displayName);

  return (
    <View style={styles.headerCard}>
      <View style={styles.avatarCircle}>
        <Text style={styles.avatarInitial}>{initials}</Text>
      </View>

      <Text style={styles.companyName}>{displayName}</Text>
      {fullname && company ? (
        <Text style={styles.fullName}>{fullname}</Text>
      ) : null}

      <View style={styles.badgeRow}>
        <View
          style={[
            styles.badge,
            active === '1' ? styles.activeBadge : styles.inactiveBadge,
          ]}>
          <Text
            style={[
              styles.badgeText,
              active === '1' ? styles.activeBadgeText : styles.inactiveBadgeText,
            ]}>
            {active === '1' ? 'Active Customer' : 'Inactive'}
          </Text>
        </View>

        {datecreated ? (
          <Text style={styles.dateText}>
            Added {formatDate(datecreated)}
          </Text>
        ) : null}
      </View>

      {/* Quick Actions */}
      <View style={styles.actionRow}>
        {phonenumber ? (
          <TouchableOpacity
            style={[styles.actionBtn, styles.primaryBtn]}
            onPress={onPhonePress}>
            <Icon name="call" size={16} color="#FFFFFF" />
            <Text style={styles.primaryBtnText}>Call</Text>
          </TouchableOpacity>
        ) : null}

        {email ? (
          <TouchableOpacity
            style={[styles.actionBtn, styles.secondaryBtn]}
            onPress={onEmailPress}>
            <Icon name="mail" size={16} color={colors.text} />
            <Text style={styles.secondaryBtnText}>Email</Text>
          </TouchableOpacity>
        ) : null}

        {website ? (
          <TouchableOpacity
            style={[styles.actionBtn, styles.secondaryBtn]}
            onPress={onWebsitePress}>
            <Icon name="globe" size={16} color={colors.text} />
            <Text style={styles.secondaryBtnText}>Website</Text>
          </TouchableOpacity>
        ) : null}
      </View>
    </View>
  );
};
