import React from 'react';
import {TouchableOpacity, StyleSheet} from 'react-native';
import {SwipeActionProps} from './types';
import {useTheme} from '../../theme/ThemeContext';

/**
 * Individual right swipe action component
 * Extends TouchableOpacity so it accepts all touchable props
 * 
 * @example
 * ```tsx
 * <SwipeableListItem.SwipeRightAction
 *   backgroundColor="#FF3B30"
 *   width={80}
 *   onPress={() => console.log('Delete pressed')}>
 *   <View style={{alignItems: 'center'}}>
 *     <Icon name="trash" />
 *     <Text>Delete</Text>
 *   </View>
 * </SwipeableListItem.SwipeRightAction>
 * ```
 */
export const SwipeableListItemSwipeRightAction: React.FC<SwipeActionProps> = ({
  children,
  backgroundColor,
  width = 80,
  style,
  ...touchableProps
}) => {
  const {colors} = useTheme();

  return (
    <TouchableOpacity
      style={[
        styles.actionContainer,
        {
          backgroundColor: backgroundColor ?? colors.red,
          width,
        },
        style,
      ]}
      activeOpacity={0.7}
      {...touchableProps}>
      {children}
    </TouchableOpacity>
  );
};

const styles = StyleSheet.create({
  actionContainer: {
    height: '100%',
    justifyContent: 'center',
    alignItems: 'center',
    paddingHorizontal: 8,
  },
});
