import { GUEST_CART_TOKEN, IS_GUEST } from "@/utils/constants";
import { decodeJWT } from "@/utils/jwt-cookie";
import { getCookie } from "@/utils/cookie-tools";
// 管理游客的token
export const getCartToken = (): string | null => {
  const raw = getCookie(GUEST_CART_TOKEN);
  if (!raw) return null;

  const isGuest = getCookie(IS_GUEST) !== "false";

  const decoded = decodeJWT<{ sessionToken: string }>(raw, isGuest);
  return decoded?.sessionToken ?? null;
};
