import { ROUTES } from "@/router/routes";

export const CHAT_IMAGE_QUERY_PARAM = "image";

export function getChatImageOverlayMessageId(input: {
  get: (key: string) => string | null;
}): string | null {
  const value = input.get(CHAT_IMAGE_QUERY_PARAM)?.trim();
  return value && value.length > 0 ? value : null;
}

export function buildChatImageOverlayUrl(
  messageId: string,
  basePath: string = ROUTES.chat,
): string {
  const params = new URLSearchParams({
    [CHAT_IMAGE_QUERY_PARAM]: messageId,
  });
  return `${basePath}?${params.toString()}`;
}

export function buildChatWithoutImageOverlayUrl(
  input: { toString: () => string },
  basePath: string = ROUTES.chat,
): string {
  const params = new URLSearchParams(input.toString());
  params.delete(CHAT_IMAGE_QUERY_PARAM);
  const query = params.toString();
  return query ? `${basePath}?${query}` : basePath;
}
