import { createContext, useContext } from 'react';

export type MobilePagerTab = 'direct' | 'channels' | 'bots';

// Set by MobileTabsPager around each of its three listing panes. Lets
// the StreamHeader inside the pane discover (a) that it's mounted in
// pager mode at all, (b) whether it's the currently active pane, and
// (c) how to request a tab switch with no animation (used by the
// invisible per-pane Segment buttons that capture taps in the safe-
// top + tabsRow band — see `StreamHeader.tsx` for why the row is
// `opacity:0` instead of `visibility:hidden`).
//
// "Mounted in pager mode" controls whether the per-pane tabs row
// renders visibly — when we're in pager mode the tabs row is painted
// invisible (the shared static header at pager root paints the visible
// tabs + icons), but the row still occupies its TABS_ROW_PX height so
// the curtain's snap geometry is unchanged.
//
// "isActive" controls which pane's curtain is wired to the shared
// static header's action icons via `mobilePagerCurtainAtom`.
//
// `selectTabInstant` is the tap commit path. It snaps the strip to
// the target tab without the swipe-finish CSS transition — taps feel
// snappy where swipes still animate. Swipes still go through the
// pager's gesture hook which uses a separate animated commit.
export type MobilePagerPaneInfo = {
  isActive: boolean;
  selectTabInstant: (target: MobilePagerTab) => void;
};

const MobilePagerPaneContext = createContext<MobilePagerPaneInfo | null>(null);

export const MobilePagerPaneProvider = MobilePagerPaneContext.Provider;

export function useMobilePagerPane(): MobilePagerPaneInfo | null {
  return useContext(MobilePagerPaneContext);
}
