import {useSelector} from "react-redux";
import {getUserInfo, isLogined} from "@features/mainSlice";
import styles from "./styles.module.scss";
import SvgIcon from "@components/SvgIcon";
import React, {useState} from "react";
import WRetainPop from "@widgets/WCashWheel/WRetainPop/WRetainPop";
import WShare from "@widgets/WCashWheel/WShare/WShare";
import {getTurnplate} from "@features/turnplateSlice";
import {localStorageGet, localStorageSet} from "@utils/helpers";
import {LOCAL_WHEEL_RETAIN} from "@constants/localkey";
import {ROUTE_PATH} from "@constants/routes";
import {useNavigate} from "react-router";
const i18n=global.i18n;
const WCashWheelHeader=({...props})=>{
    const route=props.route;
    const close=props.close;
    const user=useSelector(getUserInfo);
    const isLogin=useSelector(isLogined);
    const turnplate=useSelector(getTurnplate);
    const [openRetain,setOpenRetain]=useState(false);
    const [openShare,setOpenShare]=useState(false);
    const navigate=useNavigate();
    const onCheckClose=()=>{
        let isclose=true;
        if (isLogin){
            if (turnplate!=null){
                let collect_amount=turnplate.collect_amount;
                let total_amount=turnplate.total_amount;
                if (collect_amount>0&&collect_amount<total_amount){
                    let lsttime=localStorageGet(LOCAL_WHEEL_RETAIN,"0");
                    lsttime=Number(lsttime);
                    let now=Date.now();
                    let dis=now-lsttime;
                    if (dis>86400000){
                        setOpenRetain(true);
                        isclose=false;
                    }
                }
            }
        }
        if (isclose){
            close();
            // navigate("",{replace:true});
        }
    }
    const renderHeader=()=>{
        let title=route?route.title:"";
        return (
            <div className={styles.header}>
                <div className={styles.hcontent}>
                    {i18n.t(title)}
                </div>
                <div className={styles.top}>
                    <div className={styles.left}>
                        <button className={styles.close} onClick={()=>{
                            close();
                            // onCheckClose();
                        }}>
                            <SvgIcon className={styles.arrow} herf={"icon_Arrow"}/>
                        </button>
                    </div>
                    <div className={styles.right}>

                    </div>
                </div>
            </div>
        )
    }
    const renderShare=()=>{
        return (
            <WShare open={openShare} onClose={()=>{
                setOpenShare(false);
            }}></WShare>
        )
    }
    const renderRetainPop=()=>{
        return (
            <WRetainPop open={openRetain} onClose={()=>{
                setOpenRetain(false);
            }} openShare={openShareBox} closeP={()=>{
                localStorageSet(LOCAL_WHEEL_RETAIN,Date.now())
                close();
            }}></WRetainPop>
        )
    }
    const openShareBox=()=>{
        setOpenShare(true)
    }
    return (
        <div id={props.id} className={props.className}>
            {renderHeader()}
            {renderShare()}
            {renderRetainPop()}
        </div>
    )
}
export default WCashWheelHeader;
