import React, { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import BottomSheet, { BottomSheetFlatList, BottomSheetModal } from '../../components/bottomSheet/bottom-sheet';
import chatStore from './ChatStore';
import CameraRollPicker from '../../components/cameraRollPicker';
import { observer } from 'mobx-react-lite';
import { Log, getRotation } from '../../utils';
import { Dimensions, FlatList, Image, Keyboard, KeyboardAvoidingView, Modal, PermissionsAndroid, Platform, SafeAreaView, TouchableOpacity, View, TextInput as TextInputNative, InputAccessoryView } from 'react-native';
import { MTextInput as TextInput } from '../../components';
import { MText as Text } from '../../components';
import { check, PERMISSIONS, RESULTS, request } from 'react-native-permissions';
import colors from '../../Styles';
import appStore from '../AppStore';
import MapView, { PROVIDER_GOOGLE, PROVIDER_DEFAULT, Marker } from 'react-native-maps';
import DocumentPicker, { types } from "../../components/documentPicker";
import uuid from "react-native-uuid";
import Geolocation from 'react-native-geolocation-service';
import quickMessageStore from "./QuickMessageStore";
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import inputStore from './InputStore';
import InputStore from './InputStore';
import ModalStyled from "react-native-modal";
import { toJS } from 'mobx';
import AppStore from '../AppStore';
const QuickMessageModal = observer(function QuickMessageModal(props) {
  const inputRef = useRef(null);
  const [isFocus, setIsFocus] = useState(false);
  const [isModalVisible, setModalVisible] = useState(false);
  const updateQuickMessage = () => {
    if (!(quickMessageStore.currentMessage.text && quickMessageStore.currentMessage.text.trim() !== '')) {
      return;
    }
    if (quickMessageStore.currentMessage._id) {
      quickMessageStore.update({
        ...quickMessageStore.currentMessage,
        ...{
          text: quickMessageStore.currentMessage.text
        }
      }, () => {
        quickMessageStore.showModal = false;
        quickMessageStore.currentMessage = {};
      });
    } else {
      quickMessageStore.create({
        text: quickMessageStore.currentMessage.text,
        type: "MESSAGE"
      }, () => {
        quickMessageStore.showModal = false;
        quickMessageStore.currentMessage = {};
      });
    }
  };
  const deleteQuickMessage = () => {
    quickMessageStore.delete(quickMessageStore.currentMessage, () => {
      quickMessageStore.showModal = false;
      quickMessageStore.currentMessage = {};
    });
  };
  return /*#__PURE__*/React.createElement(Modal, {
    visible: quickMessageStore.showModal,
    transparent: true,
    animationType: 'fade',
    onShow: () => {
      console.log(inputRef.current);
      inputRef.current.focus();
    }
  }, /*#__PURE__*/React.createElement(KeyboardAvoidingView, {
    style: {
      flex: 1
    },
    behavior: Platform.OS === 'ios' ? 'padding' : ''
  }, /*#__PURE__*/React.createElement(SafeAreaView, {
    style: {
      flex: 1,
      backgroundColor: '#00000059',
      justifyContent: 'flex-end'
    }
  }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
    style: {
      height: 56,
      flexDirection: 'row',
      alignItems: 'center',
      backgroundColor: '#F8F8FA'
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      position: 'absolute',
      width: '100%',
      textAlign: 'center',
      fontWeight: '600',
      fontSize: 17,
      color: '#44494D'
    }
  }, quickMessageStore.currentMessage._id ? 'Sửa' : 'Tạo', " tin chat nhanh"), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => {
      quickMessageStore.showModal = false;
    },
    style: {
      width: 56,
      height: 56,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: require('../../assets/ic_close.png'),
    style: {
      width: 24,
      height: 24,
      resizeMode: 'contain'
    },
    resizeMode: 'contain'
  })), /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  })), /*#__PURE__*/React.createElement(View, {
    style: {
      backgroundColor: 'white'
    }
  }, /*#__PURE__*/React.createElement(TextInput, {
    ref: inputRef,
    value: quickMessageStore.currentMessage.text,
    multiline: true
    // autoFocus={true}
    ,
    onFocus: () => setIsFocus(true),
    onBlur: () => setIsFocus(false),
    placeholder: 'Nhập nội dung tin nhắn',
    placeholderTextColor: '#B5B4B8'
    // numberOfLines={10}
    ,
    style: {
      textAlignVertical: 'top',
      fontWeight: '500',
      height: 132,
      margin: 16,
      lineHeight: 20,
      borderColor: isFocus ? '#B1C1D1' : '#DCE6F0',
      borderWidth: 1,
      borderRadius: 10,
      padding: 12
    },
    onChangeText: text => {
      quickMessageStore.currentMessage = {
        ...quickMessageStore.currentMessage,
        ...{
          text
        }
      };
    }
  }), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: updateQuickMessage,
    style: {
      margin: 16,
      marginBottom: 4,
      alignItems: 'center',
      justifyContent: 'center',
      padding: 16,
      backgroundColor: colors.primary,
      borderRadius: 10
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      color: 'white',
      fontWeight: '600',
      fontSize: 15
    }
  }, quickMessageStore.currentMessage._id ? 'Lưu chỉnh sửa' : 'Lưu chat nhanh')), quickMessageStore.currentMessage._id && /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => setModalVisible(true),
    style: {
      margin: 16,
      marginTop: 0,
      alignItems: 'center',
      justifyContent: 'center',
      padding: 16,
      backgroundColor: 'white',
      borderRadius: 10
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      color: colors.primary,
      fontWeight: '600',
      fontSize: 15
    }
  }, 'Xoá tin chat')))))), /*#__PURE__*/React.createElement(Modal, {
    visible: isModalVisible,
    animationType: 'fade',
    transparent: true,
    onModalShow: () => input.current.focus()
  }, /*#__PURE__*/React.createElement(KeyboardAvoidingView, {
    style: {
      flex: 1,
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      padding: 16,
      backgroundColor: 'white',
      justifyContent: 'center',
      borderRadius: 16
    }
  }, /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => setModalVisible(false),
    style: {
      width: 36,
      height: 36,
      alignItems: 'center',
      justifyContent: 'center',
      position: 'absolute',
      left: 16,
      top: 16
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: require('../../assets/ic_close.png'),
    style: {
      width: 24,
      height: 24,
      resizeMode: 'contain'
    }
  })), /*#__PURE__*/React.createElement(View, {
    style: {
      flexDirection: 'row',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      padding: 16,
      borderRadius: 35,
      backgroundColor: colors.primary,
      marginTop: 20,
      marginBottom: 35,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: require('../../assets/ic_trash.png'),
    style: {
      width: 38,
      height: 38,
      resizeMode: 'contain'
    }
  }))), /*#__PURE__*/React.createElement(Text, {
    style: {
      fontSize: 17,
      lineHeight: 24,
      fontWeight: '600',
      color: colors.primaryText,
      marginBottom: 50,
      textAlign: 'center'
    }
  }, "Qu\xFD kh\xE1ch c\xF3 ch\u1EAFc ch\u1EAFn mu\u1ED1n xo\xE1 tin chat nhanh n\xE0y kh\xF4ng?"), /*#__PURE__*/React.createElement(View, {
    style: {
      flexDirection: 'row',
      alignItems: 'center'
    }
  }, /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => setModalVisible(false),
    style: {
      flex: 1,
      marginRight: 12,
      paddingVertical: 10,
      borderRadius: 4,
      borderColor: colors.primary,
      borderWidth: 1,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      fontSize: 15,
      lineHeight: 24,
      fontWeight: '600',
      color: colors.primary
    }
  }, "B\u1ECF qua")), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => {
      setModalVisible(false);
      deleteQuickMessage();
    },
    style: {
      flex: 1,
      paddingVertical: 10,
      backgroundColor: colors.primary,
      borderRadius: 4,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      fontSize: 15,
      lineHeight: 24,
      fontWeight: '600',
      color: 'white'
    }
  }, "Xo\xE1 tin")))))));
});
const QuickMessage = observer(function QuickMessage(props) {
  const snapPoints = useMemo(() => ['48%', '80%'], []);
  const bottomSheetModalRef = useRef();
  const insets = useSafeAreaInsets();
  useEffect(() => {
    var _bottomSheetModalRef$;
    quickMessageStore.getData({});
    (_bottomSheetModalRef$ = bottomSheetModalRef.current) === null || _bottomSheetModalRef$ === void 0 ? void 0 : _bottomSheetModalRef$.present();
    return () => {
      var _bottomSheetModalRef$2;
      (_bottomSheetModalRef$2 = bottomSheetModalRef.current) === null || _bottomSheetModalRef$2 === void 0 ? void 0 : _bottomSheetModalRef$2.dismiss();
    };
  }, []);
  const showUpdate = message => {
    quickMessageStore.currentMessage = message;
    quickMessageStore.showModal = true;
  };
  const sendMessage = msg => {
    InputStore.input = msg.text;
    chatStore.showAttachModal = false;
    chatStore.tab = 1;
    try {
      inputStore.inputRef();
    } catch (e) {
      Log(e);
    }
  };
  const renderItem = _ref => {
    let {
      item,
      index
    } = _ref;
    return /*#__PURE__*/React.createElement(TouchableOpacity, {
      onPress: () => sendMessage(item),
      style: {
        flexDirection: 'row',
        alignItems: 'center',
        paddingHorizontal: 16,
        paddingVertical: 8,
        borderBottomWidth: 1,
        borderColor: '#EEEEEE'
      }
    }, /*#__PURE__*/React.createElement(Text, {
      numberOfLines: 3,
      style: {
        flex: 1,
        flexWrap: 'wrap',
        fontWeight: '500',
        fontSize: 15,
        color: colors.neutralText
      }
    }, item.text), /*#__PURE__*/React.createElement(TouchableOpacity, {
      onPress: () => showUpdate(item),
      style: {
        width: 40,
        height: 40,
        alignItems: 'center',
        justifyContent: 'center'
      }
    }, /*#__PURE__*/React.createElement(Image, {
      source: require('../../assets/ic_edit_quick_message.png'),
      style: {
        width: 16,
        height: 16,
        resizeMode: 'contain'
      },
      resizeMode: 'contain'
    })));
  };
  return /*#__PURE__*/React.createElement(BottomSheetModal, {
    ref: bottomSheetModalRef,
    index: 0,
    bottomInset: 77 + insets.bottom,
    snapPoints: snapPoints,
    onDismiss: () => {
      if (chatStore.tab === 1) {
        chatStore.showAttachModal = false;
      }
    }
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      height: 56,
      flexDirection: 'row',
      alignItems: 'center',
      backgroundColor: '#F8F8FA',
      borderTopLeftRadius: 10,
      borderTopRightRadius: 10
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      position: 'absolute',
      width: '100%',
      textAlign: 'center',
      fontWeight: '600',
      fontSize: 17,
      color: '#44494D'
    }
  }, "Chat nhanh"), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => {
      chatStore.showAttachModal = false;
    },
    style: {
      width: 56,
      height: 56,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: require('../../assets/ic_close.png'),
    style: {
      width: 24,
      height: 24,
      resizeMode: 'contain'
    },
    resizeMode: 'contain'
  })), /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }), quickMessageStore.data.length > 0 ? /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => {
      quickMessageStore.currentMessage = {};
      quickMessageStore.showModal = true;
    },
    style: {
      paddingHorizontal: 16,
      height: 56,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      fontSize: 15,
      fontWeight: '600',
      color: '#3B7CEC'
    }
  }, "Th\xEAm m\u1EDBi")) : /*#__PURE__*/React.createElement(View, {
    style: {
      paddingHorizontal: 16,
      height: 56
    }
  })), quickMessageStore.data.length === 0 ? /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: require('../../assets/ic_quick_message_empty.png'),
    style: {
      width: 124,
      height: 99,
      alignSelf: 'center'
    }
  }), /*#__PURE__*/React.createElement(Text, {
    style: {
      color: colors.neutralText,
      fontSize: 15,
      fontWeight: '500',
      textAlign: 'center'
    }
  }, "B\u1EA1n ch\u01B0a c\xF3 tin nh\u1EAFn chat nhanh"), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => {
      quickMessageStore.showModal = true;
    },
    style: {
      marginHorizontal: 16,
      marginTop: 36,
      alignItems: 'center',
      justifyContent: 'center',
      marginBottom: 16,
      padding: 16,
      backgroundColor: colors.primary,
      borderRadius: 10
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      color: 'white',
      fontWeight: '600',
      fontSize: 15
    }
  }, "T\u1EA1o tin nh\u1EAFn nhanh"))) : /*#__PURE__*/React.createElement(BottomSheetFlatList, {
    data: quickMessageStore.data,
    renderItem: renderItem,
    ItemSeparatorComponent: () => /*#__PURE__*/React.createElement(View, {
      style: {
        height: 1,
        backgroundColor: ''
      }
    })
  }), /*#__PURE__*/React.createElement(QuickMessageModal, null));
});
const ImageMessage = observer(function ImageMessage(props) {
  const insets = useSafeAreaInsets();
  const snapPoints = useMemo(() => ['50%', '80%'], []);
  const bottomSheetModalRef = useRef();
  useEffect(() => {
    var _bottomSheetModalRef$3;
    (_bottomSheetModalRef$3 = bottomSheetModalRef.current) === null || _bottomSheetModalRef$3 === void 0 ? void 0 : _bottomSheetModalRef$3.present();
    return () => {
      var _bottomSheetModalRef$4;
      (_bottomSheetModalRef$4 = bottomSheetModalRef.current) === null || _bottomSheetModalRef$4 === void 0 ? void 0 : _bottomSheetModalRef$4.dismiss();
    };
  }, []);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BottomSheetModal, {
    ref: bottomSheetModalRef,
    index: 0,
    bottomInset: 77 + insets.bottom,
    snapPoints: snapPoints
    // onChange={handleSheetChanges}
    ,
    onDismiss: () => {
      chatStore.images = [];
      if (chatStore.tab === 0) {
        chatStore.showAttachModal = false;
        chatStore.tab = 1;
      }
    }
  }, /*#__PURE__*/React.createElement(CameraRollPicker, {
    assetType: 'All',
    groupTypes: "All",
    include: ['playableDuration', 'filename', 'fileExtension'],
    selected: chatStore.images,
    callback: images => {
      chatStore.images = images;
    }
  })));
});
const LocationMessage = observer(function LocationMessage(props) {
  const bottomSheetModalRef = useRef();
  const insets = useSafeAreaInsets();
  const mapRef = useRef();
  const [currentPosition, setCurrentPosition] = useState({
    latitude: 0,
    longitude: 0
  });
  const requestPermission = callback => {
    const permission = Platform.OS === 'android' ? PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION : PERMISSIONS.IOS.LOCATION_WHEN_IN_USE;
    request(permission).then(result => {
      switch (result) {
        case RESULTS.UNAVAILABLE:
          break;
        case RESULTS.DENIED:
          break;
        case RESULTS.LIMITED:
          break;
        case RESULTS.GRANTED:
          callback();
          break;
        case RESULTS.BLOCKED:
          break;
      }
    });
  };
  useEffect(() => {
    var _bottomSheetModalRef$5;
    (_bottomSheetModalRef$5 = bottomSheetModalRef.current) === null || _bottomSheetModalRef$5 === void 0 ? void 0 : _bottomSheetModalRef$5.present();
    requestPermission(() => {
      Geolocation.getCurrentPosition(position => {
        setCurrentPosition({
          longitude: position.coords.longitude,
          latitude: position.coords.latitude
        });
        chatStore.location = {
          longitude: position.coords.longitude,
          latitude: position.coords.latitude
        };
      }, error => {
        // See error code charts below.
      }, {
        enableHighAccuracy: true,
        timeout: 15000,
        maximumAge: 10000
      });
    });
    return () => {
      var _bottomSheetModalRef$6;
      (_bottomSheetModalRef$6 = bottomSheetModalRef.current) === null || _bottomSheetModalRef$6 === void 0 ? void 0 : _bottomSheetModalRef$6.dismiss();
    };
  }, []);
  const sendMap = async () => {
    try {
      chatStore.showAttachModal = false;
      chatStore.tab = 1;
      const message = {
        id: uuid.v4(),
        type: "LOCATION",
        location: {
          latitude: chatStore.location.latitude,
          longitude: chatStore.location.longitude
        },
        status: "sending",
        sender: appStore.user.type + '_' + appStore.user.user_id,
        conversation_id: chatStore.conversation_id
      };
      chatStore.data = [message, ...chatStore.data];
      chatStore.sendMessage(message);
    } catch (e) {
      console.log(e);
    }
  };
  return /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(BottomSheetModal, {
    ref: bottomSheetModalRef,
    index: 0,
    bottomInset: 77 + insets.bottom,
    snapPoints: ['80%'],
    onDismiss: () => {
      if (chatStore.tab === 3) {
        chatStore.showAttachModal = false;
        chatStore.tab = 1;
      }
    }
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      backgroundColor: 'white',
      height: '100%',
      width: '100%'
    }
  }, /*#__PURE__*/React.createElement(MapView, {
    ref: mapRef,
    zoomTapEnabled: false,
    scrollEnabled: false,
    provider: Platform.OS === 'android' || appStore.appId === 'VTPost' ? PROVIDER_GOOGLE : PROVIDER_DEFAULT,
    style: {
      height: '100%',
      width: '100%'
    },
    region: {
      latitude: currentPosition.latitude,
      longitude: currentPosition.longitude,
      latitudeDelta: 0.015,
      longitudeDelta: 0.0121
    },
    onRegionChangeComplete: (region, gesture) => {
      if (!(gesture !== null && gesture !== void 0 && gesture.isGesture) && appStore.appId === 'VTPost') {
        return;
      }
      chatStore.location = region;
    }
  }), /*#__PURE__*/React.createElement(TouchableOpacity, {
    style: {
      width: 56,
      height: 56,
      position: 'absolute',
      top: 8,
      right: 8
    },
    onPress: () => {
      var _mapRef$current;
      (_mapRef$current = mapRef.current) === null || _mapRef$current === void 0 ? void 0 : _mapRef$current.animateCamera({
        center: toJS(currentPosition)
      });
      // setCurrentPosition(currentPosition)
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: require('../../assets/ic_location.png'),
    style: {
      width: 56,
      height: 56,
      resizeMode: 'contain'
    },
    resizeMode: "contain"
  })), /*#__PURE__*/React.createElement(Image, {
    source: require('../../assets/ic_map_pin.png'),
    style: {
      width: 30,
      height: 30,
      resizeMode: 'contain',
      position: 'absolute',
      top: '50%',
      left: '50%',
      marginLeft: -15,
      marginTop: -30
    },
    resizeMode: "contain"
  })), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: sendMap,
    style: {
      position: 'absolute',
      zIndex: 99999,
      bottom: 16,
      left: 16,
      right: 16,
      alignItems: 'center',
      justifyContent: 'center',
      padding: 16,
      backgroundColor: colors.primary,
      borderRadius: 10
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      color: 'white',
      fontWeight: '600',
      fontSize: 15
    }
  }, "Chia s\u1EBB v\u1ECB tr\xED"))));
});
export const AttachScreen = observer(function AttachScreen(props) {
  const handleDocumentSelection = async () => {
    try {
      const response = await DocumentPicker.pick({
        presentationStyle: 'fullScreen',
        type: [types.pdf, types.xls, types.docx, types.xlsx, types.docx, types.doc, types.xls]
      });
      console.log(response);
      chatStore.showAttachModal = false;
      const message = {
        id: uuid.v4(),
        "type": "FILE",
        attachmentLocal: response,
        has_attachment: true,
        "text": '',
        "status": "sending",
        sender: appStore.user.type + '_' + appStore.user.user_id,
        conversation_id: props.data._id
      };
      chatStore.data = [message, ...chatStore.data];
      chatStore.sendMessage(message);
    } catch (err) {
      console.warn(err);
    }
  };
  const requestCameraPermission = async callback => {
    try {
      let permission = '';
      if (Platform.OS === 'android') {
        if (Platform.Version >= 33) {
          const res = PermissionsAndroid.requestMultiple(AppStore.appId === 'VTPost' ? ['android.permission.READ_MEDIA_IMAGES', 'android.permission.READ_MEDIA_VIDEO'] : ['android.permission.READ_MEDIA_IMAGES', 'android.permission.READ_MEDIA_VIDEO', 'android.permission.READ_EXTERNAL_STORAGE']).then(statuses => {
            console.log(statuses);
            return statuses['android.permission.READ_MEDIA_IMAGES'] === PermissionsAndroid.RESULTS.GRANTED && statuses['android.permission.READ_MEDIA_VIDEO'] === PermissionsAndroid.RESULTS.GRANTED && (AppStore.appId === 'VTPost' ? true : statuses['android.permission.READ_EXTERNAL_STORAGE'] === PermissionsAndroid.RESULTS.GRANTED);
          });
          res.then(res => {
            if (res) {
              callback();
            }
          });
          return;
        }
        permission = PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE;
      } else {
        permission = PERMISSIONS.IOS.PHOTO_LIBRARY;
      }
      const result = await request(permission);
      switch (result) {
        case RESULTS.UNAVAILABLE:
          break;
        case RESULTS.DENIED:
          break;
        case RESULTS.LIMITED:
          break;
        case RESULTS.GRANTED:
          //
          // bottomSheetRef.current?.present();
          callback();
          break;
        case RESULTS.BLOCKED:
          break;
      }
    } catch (err) {
      Log(err);
    }
  };
  const getImageMessage = () => {
    if (chatStore.tab === 0) {
      if (!chatStore.tabImage) {
        chatStore.tabImage = /*#__PURE__*/React.createElement(ImageMessage, props);
      }
      return chatStore.tabImage;
    } else {
      return /*#__PURE__*/React.createElement(View, null);
    }
  };
  const getQuickMessage = () => {
    if (chatStore.tab === 1) {
      if (!chatStore.tabQuickMessage) {
        chatStore.tabQuickMessage = /*#__PURE__*/React.createElement(QuickMessage, props);
      }
      return chatStore.tabQuickMessage;
    } else {
      return /*#__PURE__*/React.createElement(View, null);
    }
  };
  const getLocationMessage = () => {
    if (chatStore.tab === 3) {
      if (!chatStore.tabLocationMessage) {
        chatStore.tabLocationMessage = /*#__PURE__*/React.createElement(LocationMessage, props);
      }
      return chatStore.tabLocationMessage;
    } else {
      return /*#__PURE__*/React.createElement(View, null);
    }
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, chatStore.showAttachModal && /*#__PURE__*/React.createElement(SafeAreaView, null, getImageMessage(), getQuickMessage(), getLocationMessage(), /*#__PURE__*/React.createElement(View, {
    style: {
      bottom: 0,
      width: '100%',
      height: 77,
      position: 'absolute',
      backgroundColor: 'white',
      flexDirection: 'row',
      borderTopWidth: 1,
      borderColor: '#DCE6F0'
    }
  }, /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => {
      requestCameraPermission(() => {
        chatStore.tab = 0;
      });
    },
    style: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: chatStore.tab === 0 ? require('../../assets/nav_photo_video_active.png') : require('../../assets/nav_photo_video.png'),
    style: {
      width: 28,
      height: 28,
      resizeMode: 'contain'
    },
    resizeMode: 'contain'
  }), /*#__PURE__*/React.createElement(Text, {
    style: {
      color: chatStore.tab === 0 ? colors.primary : colors.neutralText,
      fontSize: 13,
      fontWeight: chatStore.tab === 0 ? '600' : '500',
      paddingTop: 6
    }
  }, "\u1EA2nh, video")), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => {
      chatStore.tab = 1;
    },
    style: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: chatStore.tab === 1 ? require('../../assets/nav_quick_message_active.png') : require('../../assets/nav_quick_message_active.png'),
    style: {
      width: 28,
      height: 28,
      resizeMode: 'contain',
      tintColor: chatStore.tab === 1 ? colors.primary : colors.sending
    },
    resizeMode: 'contain'
  }), /*#__PURE__*/React.createElement(Text, {
    style: {
      color: chatStore.tab === 1 ? colors.primary : colors.neutralText,
      fontSize: 13,
      fontWeight: chatStore.tab === 1 ? '600' : '500',
      paddingTop: 6
    }
  }, "Chat nhanh")), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: handleDocumentSelection,
    style: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: chatStore.tab === 2 ? require('../../assets/nav_document.png') : require('../../assets/nav_document.png'),
    style: {
      width: 28,
      height: 28,
      resizeMode: 'contain'
    },
    resizeMode: 'contain'
  }), /*#__PURE__*/React.createElement(Text, {
    style: {
      color: chatStore.tab === 2 ? colors.primary : colors.neutralText,
      fontSize: 13,
      fontWeight: chatStore.tab === 2 ? '600' : '500',
      paddingTop: 6
    }
  }, "T\xE0i li\u1EC7u")), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => {
      chatStore.tab = 3;
    },
    style: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Image, {
    source: chatStore.tab === 3 ? require('../../assets/nav_location_active.png') : require('../../assets/nav_location.png'),
    style: {
      width: 28,
      height: 28,
      resizeMode: 'contain'
    },
    resizeMode: 'contain'
  }), /*#__PURE__*/React.createElement(Text, {
    style: {
      color: chatStore.tab === 3 ? colors.primary : colors.neutralText,
      fontSize: 13,
      fontWeight: chatStore.tab === 3 ? '600' : '500',
      paddingTop: 6
    }
  }, "G\u1EEDi v\u1ECB tr\xED")))));
});
export const Input = observer(function Input() {
  const inputRef = useRef(null);
  useEffect(() => {
    inputStore.inputRef = () => {
      try {
        var _inputRef$current;
        (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
      } catch (e) {
        Log(e);
      }
    };
  }, []);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextInput, {
    editable: chatStore.canSend,
    ref: inputRef,
    placeholder: appStore.lang.chat.input_message,
    inputAccessoryViewID: "hideDoneButton",
    placeholderTextColor: '#B5B4B8',
    multiline: true,
    onChangeText: text => {
      inputStore.input = text;
    },
    value: inputStore.input,
    style: {
      fontSize: 15,
      color: colors.primaryText,
      flex: 1,
      minHeight: 56,
      paddingTop: 18,
      padding: 12,
      fontFamily: 'SVN-GilroyMedium',
      maxHeight: 250
    }
  }), Platform.OS === 'ios' && /*#__PURE__*/React.createElement(InputAccessoryView, {
    nativeID: "hideDoneButton"
  }, /*#__PURE__*/React.createElement(View, null)));
});
//# sourceMappingURL=Attach.js.map