import { View, Image, Text } from "@tarojs/components"; import './fast_sleep_popup.scss' import Card from "./card"; import NewButton, { NewButtonType } from "../base/new_button"; import { rpxToPx } from "@/utils/tools"; import { useTranslation } from "react-i18next"; import { useSelector } from "react-redux"; import { MainColorType } from "@/context/themes/color"; import { TimeFormatter } from "@/utils/time_format"; import StatusIndicator, { StatusType } from "../base/status_indicator"; import { IconCheck } from "@/components/basic/Icons"; import FastSleepPopupContent from "./fast_sleep_popup_content"; export default function FastSleepPopup(props: { close: any, data: any,top?:number }) { const health = useSelector((state: any) => state.health); const { t } = useTranslation() function total() { const { fast } = props.data return diffentTime(fast.period.start_time, fast.period.end_time) } function total1() { const { fast, sleep, status } = props.data if (status == 'WFS') return '' var str = ' / ' + diffentTime(fast.period.start_time, sleep.period.start_time) if (status == 'OG2_NO1') { return {str} } return {str} } function total2() { const { sleep, status } = props.data if (status == 'WFS') return '' var str = ' / ' + diffentTime(sleep.period.start_time, sleep.period.end_time) if (status == 'OG2' || status == 'OG2_NO1' || status == 'OG3') { return {str} } return {str} } function total3() { const { fast, sleep, status } = props.data if (status == 'WFS') return '' var str = ' / ' + diffentTime(sleep.period.end_time, fast.period.end_time) if (status == 'OG3') { return {str} } return {str} } function step1() { const { fast, sleep, status } = props.data if (status == 'OG2_NO1') { return 00:00:00 } if (status == 'WFS') { return {TimeFormatter.calculateTimeDifference(fast.target.start_timestamp, sleep.target.start_timestamp,false,true)} } else if (status == 'OG1') { return {TimeFormatter.countdown(fast.real.start_timestamp)} } else if (status == 'OG2_NO1') { return ('') } return {TimeFormatter.calculateTimeDifference(fast.real.start_timestamp, sleep.real.start_timestamp,false,true)} } function step2() { const { fast, sleep, status } = props.data if (status == 'WFS' ) { return {TimeFormatter.calculateTimeDifference(sleep.target.start_timestamp, sleep.target.end_timestamp,false,true)} } if (status == 'OG1') { return 00:00:00 } if (status == 'OG2_NO1' || status == 'OG2') { return {TimeFormatter.countdown(sleep.real.start_timestamp)} } else if (status == 'OG3') { return {TimeFormatter.calculateTimeDifference(sleep.real.start_timestamp, sleep.real.end_timestamp,false,true)} } return {TimeFormatter.calculateTimeDifference(sleep.target.start_timestamp, sleep.target.end_timestamp,false,true)} } function step3() { const { fast, sleep, status } = props.data if (status == 'WFS') { return {TimeFormatter.calculateTimeDifference(sleep.target.end_timestamp, fast.target.end_timestamp,false,true)} } if (status == 'OG1' || status == 'OG2_NO1' || status == 'OG2') { return 00:00:00 } if (status == 'OG3') { return {TimeFormatter.countdown(sleep.real.end_timestamp)} } return TimeFormatter.calculateTimeDifference(sleep.target.end_timestamp, fast.target.end_timestamp,false,true) } function diffentTime(time2, time1) { var duration = 0 var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1]) var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1]) duration = t1 - t2 >= 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000 var now = new Date().getTime() return TimeFormatter.calculateTimeDifference(now, now + duration,false,true) } function beforeStatus() { const { status } = props.data var type = StatusType.normal if (status == 'WFS' || status == 'OG1' || status == 'OG2_NO1') { type = StatusType.normal } else { type = StatusType.img } return type } function ingStatus() { const { status } = props.data var type = StatusType.normal if (status == 'WFS' || status == 'OG1' || status == 'OG2_NO1') { type = StatusType.normal } else if (status == 'OG2') { type = StatusType.normal } else { type = StatusType.img } return type; } function afterStatus() { const { status } = props.data var type = StatusType.normal if (status == 'WFS' || status == 'OG1' || status == 'OG2' || status == 'OG2_NO1') { type = StatusType.normal } else if (status == 'OG3') { type = StatusType.normal } else { type = StatusType.img } return type; } return }