import { Content, Header } from "antd/es/layout/layout";
import "./layout.less";
import { Menu } from "antd";
import { Footer } from "antd/lib/layout/layout";
import { Outlet, useLocation, useNavigate } from "react-router";
import { HomeTwoTone } from "@ant-design/icons";
import { inject, observer } from "mobx-react";
import { Store } from "antd/es/form/interface";
import { useEffect } from "react";
import { items } from "./layout_config";
const LayOut = (props: Store) => {
  const { usrStore } = props;
  const nav = useNavigate();
  const location = useLocation();

  useEffect(() => {
    if (usrStore.isNeedLogin) {
      nav("/login");
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [usrStore.isNeedLogin]);

  return (
    <div className="layout">
      <Header
        style={{
          position: "sticky",
          top: 0,
          zIndex: 9,
          width: "100%",
          display: "flex",
          alignItems: "center",
          padding: "0 10px",
          boxSizing: "border-box",
        }}
      >
        <HomeTwoTone
          onClick={() => nav("/")}
          style={{ fontSize: "36px", marginRight: "10px" }}
        />
        <Menu
          theme="dark"
          mode="horizontal"
          defaultSelectedKeys={[location.pathname]}
          items={items}
          onClick={(e) => {
            nav(e.key);
          }}
          style={{ flex: 1, minWidth: 0 }}
        />

        <span style={{ color: "#fff" }} onClick={() => usrStore.logOut()}>退出登录</span>
      </Header>
      <Content style={{ padding: "0 20px" }}>
        <Outlet />
      </Content>
      <Footer style={{ textAlign: "center" }}>
        <p>双流区黄水镇人民政府 ©{new Date().getFullYear()} Created</p>
        <p>备案号 蜀ICP备2024115456号</p>
      </Footer>
    </div>
  );
};

export default inject("usrStore")(observer(LayOut));
