import { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux'
import { MenuUnfoldOutlined,MenuFoldOutlined } from '@ant-design/icons';
import { Layout, Button } from 'antd';
import AHeader from '../AHeader'
import AMenu from '../AMenu'
import ATabs from '../ATabs'
import apiObj from '@api/index';
import { setStatusList, setHisTypeList, setTitleList, setDataList, setMsgTypeList, setMsgStatusList } from '@reducers/staticInfo';

const { Content, Sider } = Layout;
const { post, api, xPost } = apiObj;
const propTypes = {

}
const defaultProps = {};

function PageLayout() {
    const [collapsed, setCollapsed] = useState(false);
    const dispatch = useDispatch();
    /*const staticInfo =useSelector(state => {
        return state.staticInfo;
    });*/
    function getStaticInfos() {
        //const { hisTypeList, statusList, titleList, dataList } = staticInfo;
        // if ([...hisTypeList, ...statusList, ...titleList, ...dataList].length > 0) {
        //     return;
        // }
        post(api.getManagerBoxInfo).then((res) => {
            if (res.data.code === 200) {
                const data = res.data.data;
                dispatch(setHisTypeList(data[43] || data[45]));       //非单家医院为医院类型43，单家医院为病区45
                dispatch(setStatusList(data[47]));
                dispatch(setTitleList(data[40]));
                dispatch(setDataList(data[48]));
                dispatch(setMsgTypeList(data[50]));   //通知状态列表
                dispatch(setMsgStatusList(data[51]));    //通知类型列表
            }
        })
    }
    function toggleCollapsed() {
        setCollapsed(!collapsed)
    }
    useEffect(() => {
        getStaticInfos()
    }, []);
    return (
        <Layout>
            <AHeader></AHeader>
            <Layout>
                <Sider className='page-sider' collapsed={collapsed} >
                    <AMenu></AMenu>
                    <span onClick={toggleCollapsed} style={{ marginBottom: 16 }} className='toogle'>
                        {collapsed ? <MenuUnfoldOutlined className='icon'/> : <MenuFoldOutlined className='icon'/>}
                    </span>
                    <span className='logoT'>©杭州朗通信息技术有限公司</span>
                </Sider>
                <Content className='page-content'>
                    <ATabs></ATabs>
                </Content>
            </Layout>
        </Layout>
    )
}

PageLayout.propTypes = propTypes;
PageLayout.defaultProps = defaultProps;
export default PageLayout;