import React, { forwardRef } from 'react';
import { TextInput, View, Text, type TextInputProps } from 'react-native';
import { cn } from '@/lib/utils';

interface InputProps extends TextInputProps {
  label?:     string;
  error?:     string;
  className?: string;
}

export const Input = forwardRef<TextInput, InputProps>(
  ({ label, error, className, ...props }, ref) => (
    <View className="w-full gap-1">
      {label && (
        <Text className="text-muted text-sm font-medium mb-1">{label}</Text>
      )}
      <TextInput
        ref={ref}
        placeholderTextColor="#8b949e"
        className={cn(
          'bg-surfaceHigh border border-border rounded-xl px-4 py-3 text-white text-base',
          error && 'border-destructive',
          className,
        )}
        {...props}
      />
      {error && (
        <Text className="text-destructive text-xs mt-1">{error}</Text>
      )}
    </View>
  ),
);

Input.displayName = 'Input';
