import Medusa from '@medusajs/js-sdk';

export const getAdminSdk = () => {
  const medusaBackendUrl = process.env.MEDUSA_BACKEND_PUBLIC_URL!;
  const medusaPublishableApiKey =
    process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY!;
  const key = process.env.MEDUSA_SECRET_API_KEY!;

  if (!medusaBackendUrl || !medusaPublishableApiKey) {
    throw new Error('Medusa environment variables not set');
  }
  return new Medusa({
    baseUrl: medusaBackendUrl,
    debug: process.env.NODE_ENV === 'development',
    apiKey: key,
  });
};
