export type DisplaySurface = "top" | "bottom";

const DISPLAY_SURFACE_EVENT = "thor:display-surface";

export function requestDisplaySurface(surface: DisplaySurface) {
  window.dispatchEvent(new CustomEvent<DisplaySurface>(DISPLAY_SURFACE_EVENT, { detail: surface }));
}

export function subscribeDisplaySurface(listener: (surface: DisplaySurface) => void) {
  const onSurface = (event: Event) => listener((event as CustomEvent<DisplaySurface>).detail);
  window.addEventListener(DISPLAY_SURFACE_EVENT, onSurface);
  return () => window.removeEventListener(DISPLAY_SURFACE_EVENT, onSurface);
}
