/**
 * Host-owned public homepage bootstrap.
 * Never overwritten by `php artisan core:install --force`.
 *
 * Replace this file for custom public flows (booking, thank-you pages, etc.).
 * Managed entry `resources/js/public-home.js` always delegates here.
 */
import { mountPublicHome } from "@maestro/core";
import PublicHome from "./publicHome.vue";

async function bootHostPublicHome() {
  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 {
    // Resilient fallback when API settings are unavailable.
  }

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

  return mountPublicHome();
}

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