import { POST_LOGIN } from "./api";
import instance from "@/util/request";
import apihandler from "@/util/apihandler";

export async function Login({ account, password }) {
  const res = await instance.post(POST_LOGIN, {
    account,
    password,
  });

  if (res.code === "0000") {
    console.log(res.data);
    document.cookie = `JWT-Authorization=${res.data.token}; Max-Age=${
      24 * 60 * 60 * 1000
    }`;
  }

  return apihandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
    isSuccess: false,
  });
}
