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

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

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

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

  return (
    <Modal
      visible={visible}
      transparent={true}
      animationType="slide"
      onRequestClose={onClose}>
      <View style={styles.overlay}>
        <View style={styles.modalContainer}>
          <Text style={styles.title}>Báo cáo công việc</Text>
         <TextMulti 
            placeholder="Nhập nội dung báo cáo..."
            title="Nội dung báo cáo"
            required={true}
            containerMarginBottom={10}
          />

          <Text style={styles.label}>Tài liệu đính kèm</Text>
          <TouchableOpacity style={styles.attachmentContainer}>
            <Image source={R.images.icDocument} style={styles.uploadIcon} />
            <Text style={styles.attachmentText}>Thêm tài liệu</Text>
          </TouchableOpacity>

          <View style={styles.buttonContainer}>
           <Button 
              title= 'Huỷ'
              height={35}
              width={100}
              backgroundColor={R.colors.orange}
              borderRadius={100}
              fontSize={R.fontsize.fontSizeContent}
              onPress={handleCancel}
              txtStyle={{
                color: R.colors.white,
                fontWeight: '600',
                fontFamily: R.fonts.fontMedium,
              }}
              marginRight={10}
           />
           <Button 
              title= 'Báo cáo'
              height={35}
              width={100}
              backgroundColor={R.colors.blue}
              borderRadius={100}
              fontSize={R.fontsize.fontSizeContent}
              onPress={handleSubmit}
              txtStyle={{
                color: R.colors.white,
                fontWeight: '600',
                fontFamily: R.fonts.fontMedium,
              }}
           />
          </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: R.fontsize.fontsSizeTitle,
    fontWeight: '600',
    color: R.colors.blue,
    textAlign: 'center',
  },  
  required: {
    color: R.colors.red,
    fontSize: 14,
    fontWeight: '500',
  },
  label: {
    fontSize: R.fontsize.fontSizeContent,
    fontWeight: '600',
    fontFamily: R.fonts.fontMedium,
    color: R.colors.black,
  },
  textInput: {
    borderWidth: 1,
    borderColor: R.colors.gray,
    borderRadius: 8,
    padding: 12,
    fontSize: 14,
    color: R.colors.black,
    marginBottom: 16,
    minHeight: 120,
  },
  attachmentContainer: {
    borderWidth: 1,
    borderColor: R.colors.blue,
    borderRadius: 8,
    padding: 20,
    alignItems: 'center',
    marginBottom: 20,
  },
  uploadIcon: {
    width: 23,
    height: 28,
    tintColor: R.colors.blue,
    marginBottom: 5,
  },
  attachmentText: {
    fontSize: 14,
    color: R.colors.blue,
    fontWeight: '500',
  },
  buttonContainer: {
    flexDirection: 'row',
    justifyContent: 'flex-end',
  },
  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',
  },
  disabledButton: {
    backgroundColor: R.colors.gray,
  },
  cancelButtonText: {
    color: 'white',
    fontSize: 16,
    fontWeight: '600',
  },
  submitButtonText: {
    color: 'white',
    fontSize: 16,
    fontWeight: '600',
  },
});

export default WorkReportModal;
