import { createContext, useContext } from 'react' /** * Per-row composition context provided by `Legend.Row`. Actions placed inside * the row resolve their target layer from here instead of taking a `layerId` * prop, and the opacity compound (`Legend.Opacity.Item` / `.Inline`) shares * its open state through it. */ export interface LegendRowContextValue { layerId: string opacityOpen: boolean setOpacityOpen: (open: boolean) => void } export const LegendRowContext = createContext( null, ) /** Nearest `Legend.Row` composition context, or `null` outside a row. */ export function useLegendRow(): LegendRowContextValue | null { return useContext(LegendRowContext) } /** Per-group composition context provided by `Legend.Group` (the group id). */ export const LegendGroupContext = createContext(null) /** Nearest `Legend.Group` id, or `null` outside a group. */ export function useLegendGroupId(): string | null { return useContext(LegendGroupContext) } /** * Overflow-menu controller for `Legend.RowMenu` / `Legend.GroupMenu` / * `Legend.PanelMenu`. Async items (e.g. `Legend.ZoomTo`) use `setBusy` to keep * the menu open and show in-item loading feedback, then `close()` when the * handler settles. Prefer `runAsyncMenuAction` over calling these by hand. */ export interface LegendMenuController { /** Reactive busy flag for UI (spinner / disabled). */ busy: boolean /** * Synchronous busy check (ref-backed) — use this to gate clicks so a second * press before React re-renders cannot start another async action. */ isBusy: () => boolean setBusy: (busy: boolean) => void close: () => void } export const LegendMenuContext = createContext( null, ) /** Nearest overflow-menu controller, or `null` outside a row/group menu. */ export function useLegendMenu(): LegendMenuController | null { return useContext(LegendMenuContext) }