import { View, Text } from "@tarojs/components";
import { useSelector } from "react-redux";
import './schedules_edit.scss'
import './edit.scss'
import { useState } from "react";
import { useRouter } from "@tarojs/taro";
import MoveOrderList from '@/features/trackSomething/components/MoveOrderList'
import { MainColorType } from "@/context/themes/color";
import MoveList from "../components/move_list";
import NewButton, { NewButtonType } from "../base/new_button";
import { rpxToPx } from "@/utils/tools";
import NewHeader, { NewHeaderType } from "../components/new_header";
import StatusIndicator, { StatusType } from "../base/status_indicator";
import Card from "../components/card";
import { orderSchedules } from "@/services/health";
import Taro from "@tarojs/taro";
import ScheduleMoveList from "../components/schedule_move_list";

let useRoute;
let useNavigation;
let scenario = '';
if (process.env.TARO_ENV == 'rn') {
    useRoute = require("@react-navigation/native").useRoute
    useNavigation = require("@react-navigation/native").useNavigation
}
export default function SchedulesOrder() {
    let navigation, showActionSheetWithOptions;

    let router
    if (useNavigation) {
        navigation = useNavigation()
    }

    if (process.env.TARO_ENV == 'rn') {
        router = useRoute()
    }
    else {
        router = useRouter()
    }

    const health = useSelector((state: any) => state.health);
    const [list, setList] = useState(JSON.parse(router.params.list))

    function items() {
        var array: any = []
        for (var i = 0; i < list.length; i++) {
            var obj = list[i]
            array.push(
                <View className='schedule_item' style={{ width: rpxToPx(700), height: rpxToPx(128), boxSizing: 'border-box' }}>
                    <View style={{ display: 'flex', flexDirection: 'column', justifyContent: 'flex-start', flex: 1 }}>
                        <View className='item_left2'>
                            <StatusIndicator type={StatusType.normal} color={MainColorType.active} text={obj.title} fontSize={rpxToPx(34)} />
                        </View>
                        <View className="h22" style={{ color: MainColorType.g02, marginLeft: rpxToPx(26),marginTop:rpxToPx(10) }}>{obj.time_label}</View>
                    </View>
                    {/* {
                        router.params.type == 'reminder' ? reminder(obj) : editName(item, obj, index, i)
                    } */}

                    {/* {router.params.type == 'reminder' && (obj.specific_time || health.mode == 'DAY' || health.mode == 'NIGHT') && <Switch checked={obj.reminder}
                                                color={getThemeColor(obj.window)}
                                                onChange={e => {
                                                    if (process.env.TARO_ENV == 'weapp') {
                                                        e.stopPropagation()
                                                    }

                                                    obj.reminder = e.detail.value;
                                                    setList([...list])
                                                }} />} */}
                    <View className='border_footer_line' style={{ left: rpxToPx(66), flexShrink: 0 }} />

                </View>
            )
        }
        return array
    }

    function tapDone() {
        var array:any = []
        list.map((item)=>{
            array.push(item.id)
        })
        orderSchedules({ids:array}).then(res=>{
            global.refreshWindow()
            if (global.tempRefresh){
                global.tempRefresh()
            }
            Taro.navigateBack()
        })
    }

    return <View >
        <NewHeader title="日程设置" type={NewHeaderType.left} />
        <Card>
            {/* <MoveList itemHeight={rpxToPx(128)} components={items()} array={list} color="#fff" update={array => {
                setList(array)
            }} /> */}
            <ScheduleMoveList itemHeight={rpxToPx(128)} array={list} color="red" update={array => {
                setList(array)
            }}/>
        </Card>
        <View className="main_footer">
            <NewButton
                type={NewButtonType.fill}
                title="完成"
                color={MainColorType.active}
                width={rpxToPx(670)}
                height={rpxToPx(96)}
                onClick={tapDone}
            />
        </View>
        {/* <View>hell owl</View> */}
        {/* <MoveOrderList itemHeight={40} array={list} color={MainColorType.active} update={(temps: any)=>{setList(temps)}}/> */}
    </View>
}