/** @maestro-core-managed — reset via `php artisan core:install --force` */
import { mountPublicHome } from "@maestro/core";
import PublicHome from "./maestro/publicHome.vue";

async function bootPublicHome() {
  let mode = "core_default";
  try {
    const response = await fetch("/api/app-settings", {
      credentials: "include",
      headers: {
        Accept: "application/json",
        "X-Requested-With": "XMLHttpRequest",
      },
    });
    if (response.ok) {
      const payload = await response.json();
      mode =
        payload?.publicPage?.mode === "customer_override"
          ? "customer_override"
          : "core_default";
    }
  } catch {
    // Keep a resilient fallback for public pages even when API settings are unavailable.
  }

  if (mode === "customer_override") {
    return mountPublicHome({ component: PublicHome });
  }

  return mountPublicHome();
}

void bootPublicHome().catch((error) => {
  console.error(error);
});
