import { loadStripe, type Stripe } from "@stripe/stripe-js";

const stripePublishableKey = import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY ?? "";

let stripePromise: Promise<Stripe | null> | null = null;

export function stripeConfigured() {
  return stripePublishableKey.trim() !== "";
}

export async function getStripe() {
  if (!stripeConfigured()) {
    return null;
  }
  if (!stripePromise) {
    stripePromise = loadStripe(stripePublishableKey);
  }
  return stripePromise;
}
