"use client";

/**
 * Gets the access token from client-side cookies
 * @returns The access token or undefined if not found
 */
export function getClientAccessToken(): string | undefined {
  if (typeof document === "undefined") {
    return undefined;
  }

  const cookies = document.cookie.split(";");
  const accessTokenCookie = cookies.find(cookie =>
    cookie.trim().startsWith("accessToken=")
  );

  if (!accessTokenCookie) {
    return undefined;
  }

  return decodeURIComponent(
    accessTokenCookie.trim().substring("accessToken=".length)
  );
}
