// =========================================================
// FILE: firebase-config.js
// =========================================================

import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";

import {
  getAnalytics,
  isSupported
} from "https://www.gstatic.com/firebasejs/10.12.2/firebase-analytics.js";

import {
  getAuth,
  setPersistence,
  browserLocalPersistence
} from "https://www.gstatic.com/firebasejs/10.12.2/firebase-auth.js";

import {
  initializeFirestore,
  persistentLocalCache,
  persistentSingleTabManager
} from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";

const firebaseConfig = {
  apiKey: "AIzaSyCYu4Xw5iFl59LsHPQmiKAph7dGU1HUesU",
  authDomain: "trytrack-web.firebaseapp.com",
  projectId: "trytrack-web",
  storageBucket: "trytrack-web.firebasestorage.app",
  messagingSenderId: "502742725884",
  appId: "1:502742725884:web:c9773097486ca046e85379",
  measurementId: "G-YR5G8JCFJG"
};

const app = initializeApp(firebaseConfig);

isSupported().then((supported) => {
  if (supported) {
    getAnalytics(app);
  }
});

export const auth = getAuth(app);

setPersistence(auth, browserLocalPersistence)
  .then(() => {})
  .catch((error) => {
    console.error("Persistence error:", error);
  });

export const db = initializeFirestore(app, {
  ignoreUndefinedProperties: true
});
