/**
 * 测试用例页通用 UI 组件:文本输入 Field 与操作按钮 ActionButton。
 *
 * 供 pages/TestCase_*.tsx 复用,保证所有用例页交互一致、带可定位的 testID,
 * 供黑盒验证(DroidRun)与 Hypium 在真机定位。
 */
import React from 'react';
import { View, Text, TextInput, TouchableOpacity, StyleSheet } from 'react-native';

export function Field(props: {
  label: string;
  value: string;
  onChangeText: (text: string) => void;
  placeholder?: string;
  testID?: string;
  multiline?: boolean;
}) {
  return (
    <View style={styles.field}>
      <Text style={styles.fieldLabel}>{props.label}</Text>
      <TextInput
        style={props.multiline ? [styles.input, styles.multilineInput] : styles.input}
        value={props.value}
        onChangeText={props.onChangeText}
        placeholder={props.placeholder}
        placeholderTextColor="#999999"
        testID={props.testID}
        autoCapitalize="none"
        autoCorrect={false}
        multiline={props.multiline}
      />
    </View>
  );
}

export function ActionButton(props: {
  testID: string;
  label: string;
  onPress: () => void;
  color?: string;
}) {
  return (
    <TouchableOpacity
      testID={props.testID}
      style={[styles.actionButton, props.color ? { backgroundColor: props.color } : null]}
      onPress={props.onPress}>
      <Text style={styles.actionButtonText}>{props.label}</Text>
    </TouchableOpacity>
  );
}

const styles = StyleSheet.create({
  field: { marginBottom: 10 },
  fieldLabel: { fontSize: 13, color: '#374151', fontWeight: '600', marginBottom: 4 },
  input: {
    borderWidth: 1,
    borderColor: '#D1D5DB',
    borderRadius: 6,
    paddingHorizontal: 10,
    paddingVertical: 8,
    fontSize: 14,
    color: '#111827',
    backgroundColor: '#fff',
  },
  multilineInput: { minHeight: 60, textAlignVertical: 'top' },
  actionButton: {
    padding: 12,
    backgroundColor: '#2196F3',
    borderRadius: 8,
    alignItems: 'center',
    marginBottom: 8,
  },
  actionButtonText: { color: '#fff', fontWeight: 'bold', fontSize: 14 },
});