import { View, Image, Text, Switch } from "@tarojs/components";
import Taro, { useRouter } from "@tarojs/taro";
import './post_result.scss'
import { getThemeColor } from "@/features/health/hooks/health_hooks";
import { rpxToPx } from "@/utils/tools";
import NewButton, { NewButtonType } from "../base/new_button";
import { IconActive, IconCheck, IconNotification, IconNotificationOff, IconSit } from "@/components/basic/Icons";
import { MainColorType } from "@/context/themes/color";
import { useState } from "react";
import dayjs from "dayjs";
import { useDispatch, useSelector } from "react-redux";
import { setMode, setShowActionTip } from "@/store/health";
import NewModal from "../base/new_modal";
import Card from "../components/card";
import { updateReminder } from "@/services/health";
import StatusIndicator, { StatusType } from "../base/status_indicator";
import { useTranslation } from "react-i18next";
let useRoute;
let useNavigation;
if (process.env.TARO_ENV == 'rn') {
useRoute = require("@react-navigation/native").useRoute
useNavigation = require("@react-navigation/native").useNavigation
}
export default function PostResult() {
const user = useSelector((state: any) => state.user);
let router
let navigation;
if (useNavigation) {
navigation = useNavigation()
}
if (process.env.TARO_ENV == 'rn') {
router = useRoute()
}
else {
router = useRouter()
}
const [data, setData] = useState(JSON.parse(router.params.data))
const [showSetting, setShowSetting] = useState(false)
const dispatch = useDispatch()
const { t } = useTranslation()
function getMainColor() {
if (data.scenario == 'MOVE' && data.extra.move_status == 'SEDENTARY') {
return MainColorType.g02
}
return getThemeColor(data.window ? data.window : 'FAST')
}
function nextTitle() {
return data.next.content
}
function showSwitchBtn() {
if (data.extra && data.extra.fast_type == 'LF') return false;
return data.schedule_completed
}
function changeReminder(e) {
updateReminder({ reminder: e.detail.value }, data.next.schedule_id).then((res) => {
var detail = JSON.parse(JSON.stringify(data))
detail.next.reminder = e.detail.value
setData(detail)
})
}
function swithBtnText() {
switch (data.window) {
case 'FAST':
return 'Switch to Eat'
case 'EAT':
return 'Switch to Fast'
case 'ACTIVE':
return 'Switch to Sleep'
case 'SLEEP':
return 'Swtich to Active'
}
return ''
}
function tapSwitch() {
switch (data.window) {
case 'FAST':
dispatch(setMode('EAT'))
break
case 'EAT':
dispatch(setMode('FAST'))
break
case 'ACTIVE':
dispatch(setMode('SLEEP'))
break
case 'SLEEP':
dispatch(setMode('ACTIVE'))
break
}
Taro.navigateBack()
}
function headerIcon() {
if (data.current_window) {
return
}
if (data.images && data.images.length > 0) {
return
}
if (data.scenario == 'MOVE') {
return data.extra.move_status == 'ACTIVE' ?:
}
return
}
function headerDesc() {
if (data.scenario == 'MOVE') {
if (data.extra.move_status == 'SEDENTARY') {
return 'Sedentary Hour'
}
else {
return 'Active Hour'
}
}
return data.description
}
function statusText() {
switch (data.current_window) {
case 'FAST':
return t('health.guide_current_scenario', { scenario: t('health.fast') })
case 'EAT':
return t('health.guide_current_scenario', { scenario: t('health.eat') })
case 'SLEEP':
return t('health.guide_current_scenario', { scenario: t('health.sleep') })
case 'ACTIVE':
return t('health.guide_current_scenario', { scenario: t('health.active') })
}
return ''
}
return
{
headerIcon()
}
{data.title}
{headerDesc()}
{
data.next &&
{
setShowSetting(true)
}}
>
{
data.next.reminder ? :
}
}
{
data.current_window &&
}
{
if (data.current_window) {
Taro.navigateBack({
delta: 10
})
}
else {
Taro.navigateBack()
}
if (data.status_change){
if (data.status_change.previous != data.status_change.current) {
//灵动岛弹窗
dispatch(setShowActionTip({
isShow: true,
isCompleted: false
}))
}
}
}}
/>
{
showSwitchBtn() &&
}
{
showSetting && setShowSetting(false)}
confirm={() => setShowSetting(false)}
>
{data.next.time}
{data.next.title}
}
}