import React from 'react';
import { StyleSheet, Pressable, PressableProps, DimensionValue } from 'react-native';
import ThemedView from '@/components/theme/default/ThemedView';
import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';

const DEFAULT_WIDTH = 320;
const DEFAULT_HEIGHT = 68;

type ThemedButtonProps = PressableProps & {
  width?: DimensionValue;
  height?: DimensionValue;
  backgroundColor?: string;
  containerStyle?: object;
  buttonStyle?: object;
};

const ThemedButton: React.FC<ThemedButtonProps> = ({
  width = DEFAULT_WIDTH,
  height = DEFAULT_HEIGHT,
  backgroundColor = Colors[useColorScheme() ?? 'dark'].text,
  children,
  containerStyle,
  buttonStyle,
  style,
  ...restProps // This now includes onPress automatically
}) => {
  return (
    <ThemedView
      style={[
        styles.buttonContainer,
        {
          width,
          height,
        },
        containerStyle,
      ]}
    >
      <Pressable
        style={[styles.button, { backgroundColor }, buttonStyle, style]}
        {...restProps} // This passes onPress and all other Pressable props
      >
        {children}
      </Pressable>
    </ThemedView>
  );
};

export default ThemedButton;

const styles = StyleSheet.create({
  buttonContainer: {
    alignItems: 'center',
    justifyContent: 'center',
    padding: 3,
  },
  button: {
    borderRadius: 10,
    width: '100%',
    height: '100%',
    alignItems: 'center',
    justifyContent: 'center',
    flexDirection: 'row',
  },
});
