import { createContext, useContext } from 'react';

// Routes under /channels/ render the same RoomTimeline / RoomInput as
// /direct/ and /:spaceId/, but with extra timeline filtering: thread
// replies, edits, reactions, RTC service events, and call events are
// hidden from the centre column so it shows only thread-rootable messages.
// The flag flows through context (not a prop) so the existing Room ->
// RoomView -> RoomTimeline tree doesn't need a new threaded prop.
const ChannelsModeContext = createContext<boolean>(false);

export const ChannelsModeProvider = ChannelsModeContext.Provider;

export function useChannelsMode(): boolean {
  return useContext(ChannelsModeContext);
}

// True while a `/channels/.../thread/:rootId/` URL is matched and the
// `<ThreadDrawer>` is mounted. RoomView reads this to suppress the
// channel composer (RoomInput) — Element-web pattern: only one composer
// surface mounts at a time so two `<Slate>` editors can't race against
// each other (slate#6016 + slate#4850 share-`initialValue` regression
// is otherwise possible at cold-load), and so the channel viewport
// doesn't visibly react to the user's own thread reply local-echo
// (the «message flashes in main timeline» blink). Provided by
// `Room.tsx` based on `useMatch(CHANNELS_THREAD_PATH)`.
const ThreadDrawerOpenContext = createContext<boolean>(false);

export const ThreadDrawerOpenProvider = ThreadDrawerOpenContext.Provider;

export function useThreadDrawerOpen(): boolean {
  return useContext(ThreadDrawerOpenContext);
}
