import { Alert, Pressable, Text, View } from 'react-native';
import * as Clipboard from 'expo-clipboard';
import * as Haptics from 'expo-haptics';

export const CopyRow = ({
  label,
  value,
}: {
  label: string;
  value?: string;
}) => {
  if (!value) return null;
  const copy = async () => {
    await Clipboard.setStringAsync(value);
    await Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
    Alert.alert('Copied', `${label} copied to clipboard.`);
  };
  return (
    <Pressable className='border-border border-b py-3' onPress={copy}>
      <Text className='text-muted-foreground text-xs'>{label}</Text>
      <View className='mt-1 flex-row items-center justify-between gap-3'>
        <Text className='text-foreground min-w-0 flex-1 text-sm'>{value}</Text>
        <Text className='text-primary text-sm font-semibold'>Copy</Text>
      </View>
    </Pressable>
  );
};
