import { View, Text, Image } from "@tarojs/components";
import './fast_sleep_console.scss'
import { rpxToPx } from "@/utils/tools";
import NewButton, { NewButtonType } from "../base/new_button";
import { getThemeColor } from "@/features/health/hooks/health_hooks";
import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
import dayjs from "dayjs";
import { MainColorType } from "@/context/themes/color";
import showAlert from "@/components/basic/Alert";
import { IconCellArrow, IconNotification, IconNotificationOff } from "@/components/basic/Icons";
import { useSelector } from "react-redux";
import { delRecord } from "@/services/health";
export default function FastSleepConsole(props: { step: number, data: any, del: any }) {
const health = useSelector((state: any) => state.health);
function tapLogBtn(index: number) {
const { fast, sleep, status } = props.data
var single = 0;
var is_start = 0;
var window = 'FAST'
switch (index) {
case 0:
{
single = 1;
is_start = 1;
}
break;
case 1:
{
if (status == 'OG1') {
single = 1;
is_start = 1;
window = 'SLEEP'
}
else {
single = 0;
}
}
break;
case 2:
{
if (status == 'OG2') {
single = 1;
is_start = 0;
window = 'SLEEP'
}
else {
single = 0;
}
}
break;
case 3:
{
if (status == 'OG3') {
single = 1;
is_start = 0;
window = 'FAST'
}
else {
single = 0;
}
}
break;
}
jumpPage(`/_health/pages/log_time?is_fast_with_sleep=1&index=${index}&initCheck=${health.fast_with_sleep.status == 'OG2_MISALIGNED' ? 1 : 0}&single=${index == 0 ? 1 : 0}&is_start=${is_start}&window=${window}&data=${JSON.stringify(props.data)}`)
/*
const isSingle = router.params.single == '1'
const isFast = router.params.window == 'FAST'
const isStart = router.params.is_start == '1'
*/
}
function goDetail(index) {
if (index == 0 && props.data.fast.status == 'OG') {
const { event_id, schedule_id } = props.data.fast.timeline[0]
jumpPage(`/_health/pages/timeline_detail?event_id=${event_id}&schedule_id=${schedule_id}`)
}
else if (index == 1 && (props.data.sleep.status == 'OG' || props.data.status == 'OG3')) {
const { event_id, schedule_id } = props.data.sleep.timeline[0]
jumpPage(`/_health/pages/timeline_detail?event_id=${event_id}&schedule_id=${schedule_id}`)
}
}
function delConfirm() {
const { fast, sleep } = props.data
let array: any = []
if (fast.window_id) {
array.push(fast.window_id)
}
if (sleep.window_id) {
array.push(sleep.window_id)
}
showAlert({
title: 'del',
content: '确认删除此记录?',
showCancel: true,
confirm: () => {
delRecord(array[0], { ids: array.join(',') }).then(res => {
global.refreshWindow()
props.del()
})
}
})
}
function getIconColor(index: number, finish: boolean) {
var color = MainColorType.g03
if (index == 1 || index == 2) {
color = MainColorType.sleep
}
else {
color = MainColorType.fast
}
if (finish) {
color = MainColorType.g03
}
return color;
}
function processIcon(item, finish, isError) {
if (isError) {
return
}
if (finish) {
return
}
if (item.timeline.reminder) {
return
}
return
}
function timelineItem(item: any, index: number, count: number) {
const { fast, sleep, status } = props.data
var showBtn = true;
var time = ''
var hasDescription = item.moment && item.moment.description
var finish = false;
switch (index) {
case 0:
{
if (status == 'OG2_NO1' || status == 'WFS') {
showBtn = true
}
else {
showBtn = false;
finish = true;
}
time = dayjs(fast.target.start_timestamp).format('MM-DD HH:mm')
}
break;
case 1:
{
if (status == 'WFS' || status == 'OG1') {
showBtn = true
}
else {
showBtn = false
finish = true;
}
if (status == 'OG3') {
time = dayjs(sleep.real.start_timestamp).format('MM-DD HH:mm')
}
else {
time = dayjs(sleep.target.start_timestamp).format('MM-DD HH:mm')
}
}
break;
case 2:
{
if (status == 'OG3') {
showBtn = false
finish = true;
time = dayjs(sleep.real.end_timestamp).format('MM-DD HH:mm')
}
else {
showBtn = true
time = dayjs(sleep.target.end_timestamp).format('MM-DD HH:mm')
}
}
break;
case 3:
{
showBtn = true
time = dayjs(fast.target.end_timestamp).format('MM-DD HH:mm')
}
break;
}
var isError = false;
if (health.fast_with_sleep.status == 'OG2_MISALIGNED' && (index == 0 || index == 1)) {
isError = true;
}
return {
goDetail(index)
}}>
{
processIcon(item, finish, isError)
}
{time}
{ }}>{(item.moment && item.moment.title) ? item.moment.title : item.title}
{
hasDescription && {item.moment.description}
}
{
!isError && item.moment && item.moment.media && item.moment.media.length > 0 &&
}
{
!isError && showBtn && {
tapLogBtn(index)
}} />
}
{
isError &&
{
jumpPage(`/_health/pages/log_time?is_fast_with_sleep=1&index=${1}&single=0&initCheck=1`)
}}
/>
}
{
!isError && item.action == 'POST_MOMENT' && item.timeline.real &&
}
}
return
{
health.fast_with_sleep.status == 'OG2_MISALIGNED' &&
Logged times are not in their proper order
}
{
props.step != 2 && props.step != 3 && timelineItem({
title: 'Start Fast',
mode: 'FAST',
is_start: true,
action: props.data.fast.timeline[0].action,
moment: props.data.fast.timeline[0].moment,
timeline: props.data.fast.timeline[0]
}, 0, 4)
}
{
props.step != 3 && timelineItem({
title: 'Go to bed',
mode: 'SLEEP',
is_start: true,
action: props.data.fast.timeline[0].action,
moment: props.data.sleep.timeline[0].moment,
timeline: props.data.sleep.timeline[0]
}, 1, 4)
}
{
props.step != 1 && timelineItem({
title: 'Wake up',
mode: 'SLEEP',
is_start: false,
moment: props.data.sleep.timeline[1].moment,
timeline: props.data.sleep.timeline[1]
}, 2, 4)
}
{
props.step != 1 && props.step != 2 && timelineItem({
title: 'End Fast',
mode: 'FAST',
is_start: false,
moment: props.data.fast.timeline[1].moment,
timeline: props.data.fast.timeline[1]
}, 3, 4)
}
{
props.data.status != 'WFS' &&
}
}