export type DisplayLayout = "single" | "thor-preview" | "dedicated";

export interface DisplayLayoutRequest {
  display?: string | null;
  layout?: string | null;
}

/**
 * Physical Thor surfaces are selected explicitly by the Android host. Every
 * ordinary browser viewport is a single-screen game unless a developer asks
 * for the dual-screen hardware preview.
 */
export function resolveDisplayLayout({ display, layout }: DisplayLayoutRequest): DisplayLayout {
  if (display === "top" || display === "bottom") return "dedicated";
  if (layout === "thor-preview" || layout === "dual") return "thor-preview";
  return "single";
}

export function currentDisplayLayout(search = window.location.search): DisplayLayout {
  const params = new URLSearchParams(search);
  return resolveDisplayLayout({
    display: params.get("display"),
    layout: params.get("layout"),
  });
}

export function isSingleScreenLayout(search = window.location.search) {
  return currentDisplayLayout(search) === "single";
}
