import { customColor } from '@/constants/Colors'; import { Ionicons } from '@expo/vector-icons'; import { LinearGradient } from 'expo-linear-gradient'; import { Image, StyleSheet, Text, TouchableOpacity, View, ScrollView } from 'react-native'; import ChoicesGroup from '../Selection/ChoicesGroup'; import dayjs from 'dayjs'; import { memo, useEffect, useState } from 'react'; import UserResults from '../modal/UserResults'; import { useLoading, useSnackbar } from '@/contexts'; import CustomButton from '../UI/Button'; export const allVoteStatus = [ { status: 'Không chọn', colors: [customColor.status.notVote.start, customColor.status.notVote.middle, customColor.status.notVote.end], borderColor: customColor.status.notVote.border, }, { status: 'Chưa chọn', colors: [customColor.card.backgroundStart, customColor.card.backgroundMiddle, customColor.card.backgroundEnd], borderColor: customColor.card.border, }, { status: 'Đúng', colors: [customColor.status.correct.start, customColor.status.correct.middle, customColor.status.correct.end], borderColor: customColor.status.correct.border, }, { status: 'Sai', colors: [customColor.status.incorrect.start, customColor.status.incorrect.middle, customColor.status.incorrect.end], borderColor: customColor.status.incorrect.border, }, { status: 'Chờ kết quả', colors: [customColor.status.waiting.start, customColor.status.waiting.middle, customColor.status.waiting.end], borderColor: customColor.status.waiting.border, }, ]; function MatchItem({ match, isNewMatch, onIsFocus, isLoadingTab }: { onIsFocus: any; match: any; isNewMatch: boolean; isLoadingTab: boolean }) { const start_date = dayjs(match.match_start).format('DD/MM/YYYY HH:mm'); const end_date = dayjs(match.match_end).format('DD/MM/YYYY HH:mm'); const result = match.match_result ? match.match_result : ''; const isChoose = match.options.some((option: any) => option.selected === true); const options = [ 'Tất cả', ...match.options .sort((a: any, b: any) => a.option_name.trim().localeCompare(b.option_name.trim())) .map((i: any) => { return i.option_name; }), ]; const [userVoteStatus, setUserVoteStatus] = useState(); const { showSnackbar } = useSnackbar(); const fetchResult = async () => { try { let vote_status = allVoteStatus.find((val) => val.status === match.vote_status); // if (!isNewMatch) { // // keo cu // vote_status = allVoteStatus.find((val) => val.status === match.vote_status); // } else { // const isChoose = match.options.some((option: any) => option.selected === true); // if (match.match_status == 'Không chọn') { // vote_status = allVoteStatus.find((val) => val.status === 'Không chọn'); // } else if (match.match_status == 'Đang vote') { // if (isChoose) { // console.log('isChoose', isChoose); // vote_status = allVoteStatus.find((val) => val.status === 'Chờ kết quả'); // } else { // vote_status = allVoteStatus.find((val) => val.status === 'Chưa chọn'); // } // } else { // if (isChoose) { // vote_status = allVoteStatus.find((val) => val.status === 'Chờ kết quả'); // } else { // vote_status = allVoteStatus.find((val) => val.status === 'Không chọn'); // } // } // } setUserVoteStatus({ status: vote_status?.status, colors: vote_status?.colors, borderColor: vote_status?.borderColor }); } catch (err: any) { console.log('Result error', err.response.data.detail); showSnackbar(err.response.data.detail, 'error'); } }; const fetchColor = () => { const vote_status = allVoteStatus.find((val) => val.status === 'Chờ kết quả'); setUserVoteStatus({ status: vote_status?.status, colors: vote_status?.colors, borderColor: vote_status?.borderColor }); }; const handleOnChoose = () => { fetchColor(); }; useEffect(() => { fetchResult(); }, [isLoadingTab]); return ( { onIsFocus(false); }} > {!isLoadingTab && ( { } {start_date.toString()} {'-'} {end_date.toString()} {match.match_name} {isNewMatch && ( )} {result != '' ? ( {'Kết quả: ' + result} ) : ( <> )} )} ); } const MatchDetail = memo( ({ isChoose, isNewMatch, match, onChoose, options }: { isChoose: boolean; isNewMatch: boolean; match: any; onChoose?: any; options: Array }) => { const [showVotes, setShowVotes] = useState(false); return ( {`Mô tả: ${match.match_description}`} {`Tiền cược: ${match.match_money.toLocaleString() + 'đ'}`} setShowVotes(true)}> {showVotes && ( setShowVotes(false)} /> )} ); }, ); const styles = StyleSheet.create({ brightText: { color: customColor.card.brightText, }, darkText: { color: customColor.card.darkText, }, title: { fontSize: 16, fontWeight: '800', color: customColor.card.title, textAlign: 'center', }, container: { flex: 1, borderRadius: 20, borderWidth: 1.5, paddingHorizontal: 10, paddingBottom: 6, marginVertical: 10, justifyContent: 'center', }, rowContainer: { flex: 1, flexDirection: 'row', justifyContent: 'space-around', }, verticalDevider: { marginVertical: 8, }, horizontailDevider: { marginHorizontal: 8, }, }); export default memo(MatchItem);