import { initializeApp, getApps, getApp } from 'firebase/app';
import { getMessaging, Messaging  , isSupported} from 'firebase/messaging';

const firebaseConfig = {
  apiKey: "AIzaSyAEd26bH52GI6Mc5OhImgVFCGSHxROqr7M",
  authDomain: "jazzagain1.firebaseapp.com",
  projectId: "jazzagain1",
  storageBucket: "jazzagain1.appspot.com",
  messagingSenderId: "927463586136",
  appId: "1:927463586136:web:41358cf68645cbe762cd2d"
};

const app = !getApps().length ? initializeApp(firebaseConfig) : getApp();

const getFirebaseMessaging = async (): Promise<Messaging | undefined> => {
  if (typeof window !== 'undefined') {
    const supported = await isSupported();
    if (supported) {
      return getMessaging(app);
    }
  }
  return undefined;
};

export { getFirebaseMessaging };
