import React, { FC, useEffect, useState } from 'react' import { Image, Pressable, Text, View } from 'react-native' import R from '../../res' import s from './styles' import { ICartTimerProps } from './types' const CartTimer: FC = ({ shouldNotMinimize, texts, styles, secondsLeft, }) => { const [isOnlyTimeVisible, setIsOnlyTimeVisible] = useState(false) const hideOtherData = () => { if (!shouldNotMinimize) { setIsOnlyTimeVisible(!isOnlyTimeVisible) } } const [timeRemaining, setTimeRemaining] = useState('') const message = texts?.message ? texts.message : 'Please complete your purchase before the timer reaches zero:' useEffect(() => { const clockify = () => { //let hours = Math.floor(secondsLeft / 60 / 60) const mins = Math.floor((secondsLeft / 60) % 60) const seconds = Math.floor(secondsLeft % 60) //let displayHours = hours < 10 ? `0${hours}` : hours const displayMins = mins < 10 ? `0${mins}` : mins const displaySecs = seconds < 10 ? `0${seconds}` : seconds setTimeRemaining(`${displayMins}:${displaySecs}`) } clockify() }, [secondsLeft]) return ( {!isOnlyTimeVisible && ( )} {!isOnlyTimeVisible && ( {message} )} {timeRemaining} ) } export default CartTimer