import React from "react";
// import { useNavigate } from "react-router-dom";
import { LogoutOutlined } from "@ant-design/icons";
import { Button, Modal } from "antd";
import useUserModel from "@/store/user";
import { logout } from "@/service/login";
const { confirm } = Modal;

export default (props) => {
  // const navigate = useNavigate();
  const [_, { setUser }] = useUserModel();

  const onExit = () => {
    confirm({
      title: "确认退出系统?",
      onOk: () => {
        // 调用接口
        // localStorage.removeItem("token");
        // setUser();
        // window.location.href =
        //   authUrl +
        //   `?redirect=${encodeURIComponent(window.location.href)}&mode=ticket`;
        logout().then((res) => {
          localStorage.removeItem("token");
          setUser();
          window.location.href = getLoginPage();
        }).catch((err) => {
          console.error(err);
          localStorage.removeItem("token");
          setUser();
          window.location.href = getLoginPage();
        });
      },
    });
  };

  return (
    <Button
      className="font"
      type="text"
      icon={<LogoutOutlined />}
      onClick={onExit}
    >
      退出
    </Button>
  );
};
