/**
 * Single-call wrapper for Telegram Mini App ready().
 * Called once when the first visible screen has finished loading so Telegram
 * hides its native loading animation only after our content is ready.
 */

import { miniAppReady } from "@telegram-apps/sdk-react";

let readyCalled = false;

/**
 * Calls Telegram miniAppReady() at most once per session.
 * Safe when SDK is unavailable (e.g. non-Telegram environment).
 */
export function callMiniAppReadyOnce(): void {
  if (readyCalled) return;
  try {
    if (miniAppReady.isAvailable()) {
      miniAppReady();
      readyCalled = true;
    }
  } catch {
    // SDK not available or not in Mini App context; no-op.
  }
}
