import React, {useState} from 'react';
import {
  Modal,
  View,
  Text,
  TextInput,
  TouchableOpacity,
  StyleSheet,
  Image,
} from 'react-native';
import R from '../../../../assets/R';

const EditReportModal = ({visible, onClose, onSubmit, initialContent = ''}) => {
  const [reportContent, setReportContent] = useState(initialContent);

  const handleSubmit = () => {
    if (reportContent.trim()) {
      onSubmit(reportContent);
      onClose();
    }
  };

  const handleCancel = () => {
    setReportContent(initialContent);
    onClose();
  };

  return (
    <Modal
      visible={visible}
      transparent={true}
      animationType="slide"
      onRequestClose={onClose}>
      <View style={styles.overlay}>
        <View style={styles.modalContainer}>
          <Text style={styles.title}>Chỉnh sửa báo cáo</Text>
          
          <Text style={styles.description}>
            Bạn đã nộp yêu cầu nhưng thành thời khoa chưa trong
            thông cho cần đánh giá môn học các công việc và
            lịch hẹn quan
          </Text>

          <Text style={styles.label}>Tài liệu đính kèm</Text>
          <View style={styles.attachedFileContainer}>
            <Text style={styles.fileName}>
              Quyết định thông báo đào tạo - QD347583
            </Text>
            <TouchableOpacity>
              <Image source={R.images.icDelete} style={styles.deleteIcon} />
            </TouchableOpacity>
          </View>

          <TouchableOpacity style={styles.attachmentContainer}>
            <Image source={R.images.icUpload} style={styles.uploadIcon} />
            <Text style={styles.attachmentText}>Thêm tài liệu</Text>
          </TouchableOpacity>

          <View style={styles.buttonContainer}>
            <TouchableOpacity style={styles.cancelButton} onPress={handleCancel}>
              <Text style={styles.cancelButtonText}>Hủy</Text>
            </TouchableOpacity>
            <TouchableOpacity 
              style={styles.submitButton} 
              onPress={handleSubmit}>
              <Text style={styles.submitButtonText}>Cập nhật</Text>
            </TouchableOpacity>
          </View>
        </View>
      </View>
    </Modal>
  );
};

const styles = StyleSheet.create({
  overlay: {
    flex: 1,
    backgroundColor: 'rgba(0, 0, 0, 0.5)',
    justifyContent: 'center',
    alignItems: 'center',
  },
  modalContainer: {
    backgroundColor: 'white',
    borderRadius: 12,
    padding: 20,
    width: '90%',
    maxWidth: 400,
  },
  title: {
    fontSize: 18,
    fontWeight: '600',
    color: R.colors.blue,
    textAlign: 'center',
    marginBottom: 16,
  },
  description: {
    fontSize: 14,
    color: R.colors.black,
    lineHeight: 20,
    marginBottom: 20,
    textAlign: 'left',
  },
  label: {
    fontSize: 14,
    fontWeight: '500',
    color: R.colors.black,
    marginBottom: 8,
  },
  attachedFileContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    backgroundColor: '#f5f5f5',
    borderRadius: 8,
    padding: 12,
    marginBottom: 12,
  },
  fileName: {
    fontSize: 14,
    color: R.colors.black,
    flex: 1,
  },
  deleteIcon: {
    width: 20,
    height: 20,
    tintColor: R.colors.red,
  },
  attachmentContainer: {
    borderWidth: 1,
    borderColor: R.colors.gray,
    borderRadius: 8,
    borderStyle: 'dashed',
    padding: 20,
    alignItems: 'center',
    marginBottom: 20,
  },
  uploadIcon: {
    width: 40,
    height: 40,
    tintColor: R.colors.blue,
    marginBottom: 8,
  },
  attachmentText: {
    fontSize: 14,
    color: R.colors.blue,
    fontWeight: '500',
  },
  buttonContainer: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    gap: 12,
  },
  cancelButton: {
    flex: 1,
    backgroundColor: R.colors.orange,
    borderRadius: 8,
    paddingVertical: 12,
    alignItems: 'center',
  },
  submitButton: {
    flex: 1,
    backgroundColor: R.colors.blue,
    borderRadius: 8,
    paddingVertical: 12,
    alignItems: 'center',
  },
  cancelButtonText: {
    color: 'white',
    fontSize: 16,
    fontWeight: '600',
  },
  submitButtonText: {
    color: 'white',
    fontSize: 16,
    fontWeight: '600',
  },
});

export default EditReportModal;
