/**
 * Launch params from URL (query or hash). Used for deep links and initial view.
 * Telegram may pass tgWebAppStartParam in search or hash; both are checked.
 */

/**
 * Parse start_param from URL (query or hash). Use when SDK is not yet available
 * (e.g. store init) or as fallback when SDK is delayed.
 */
export function getStartParamFromUrl(): string | undefined {
  if (typeof window === "undefined") return undefined;
  const fromSearch = new URLSearchParams(window.location.search).get(
    "tgWebAppStartParam"
  );
  if (fromSearch) return fromSearch;
  const fromHash = new URLSearchParams(window.location.hash.slice(1)).get(
    "tgWebAppStartParam"
  );
  return fromHash ?? undefined;
}
