import React, { use } from "react";
import { Outlet } from "react-router";
import { useEffect, useState } from "react";
import { 
    SearchOutlined, 
    FontSizeOutlined, 
    MessageOutlined, 
    SunOutlined, 
    MoonOutlined
 } from "@ant-design/icons";
import style from "./frame.module.css";
import logo from "&/assets/logo.png";
import { useAppDispatch } from "@/hooks/store";
import { useSelector } from "react-redux";

import { checkAndRefreshToken } from "@/utils/jwt";
const Frame:React.FC = () => {

    useEffect(() => {
        checkAndRefreshToken();
    }, []);
    const dispatch = useAppDispatch();

    const showSearch = useSelector((state: any) => state.setting.showSearch); 
    const theme= useSelector((state: any) => state.setting.theme);
    const toggleSearch = () => {
        dispatch({ type: "setting/toggleSearch" });
    }

    const toggleFontSize = () => {
        dispatch({ type: "setting/toggleFontSize" });
    };

    const toggleTheme = () => {
        dispatch({ type: "setting/toggleTheme" });
    };


    return (
        <div style={{ display: 'block', height: '100vh' }}>
            <header className={style.header}>
                <img className={style.logo} src={logo} alt="website logo"></img>
                {showSearch && (<input className={style.searchInput} placeholder="输入关键词进行搜索"/>)}
                <div className={style.toollist}>
                    <SearchOutlined onClick={toggleSearch}/>
                    <FontSizeOutlined onClick={toggleFontSize}/>
                    <MessageOutlined />
                    {theme === 'dark' ? <MoonOutlined onClick={toggleTheme}/> : <SunOutlined onClick={toggleTheme}/>}
                </div>
            </header>
            <div className={style.container}>
                <Outlet/>
            </div>
            
            
        </div>
    );
}

export default Frame;