"use client";

import { createContext, useContext } from "react";
import type { CSSObjectWithLabel } from "react-select";

/** Menus stay inside the dialog's accessible tree, outside its clipped panel. */
export const SelectMenuPortalContext = createContext<HTMLElement | null>(null);

export function useSelectMenuPortal() {
  const target = useContext(SelectMenuPortalContext);
  return {
    menuPortalTarget: target ?? (typeof document !== "undefined" ? document.body : undefined),
    menuPosition: "fixed" as const,
    menuPlacement: "auto" as const,
    menuShouldScrollIntoView: false,
    maxMenuHeight: 240,
  };
}

export const selectMenuPortalStyle = (base: CSSObjectWithLabel) => ({
  ...base,
  zIndex: 10000,
});
