// Copyright: (c) 2026 TWWIM UG. All rights reserved. (www.twwim.com) import { useMemo } from 'react'; import type { AuthOrigin, Channel } from '@archer/domain'; import { useAuthenticatedUser } from '@/features/auth/hooks/useAuthenticatedUser'; import { resolveChannel } from '@/lib/channel'; /** * Reactive channel resolver. Reruns when authOrigin patches into the store * (login, refresh). Pure derivation — no setter, no side effects. * * Use this for UI shape decisions (which sidebar items, which cards, link * targets, etc). Do NOT use it for "can I call the WP REST bridge" checks — * that's `isWordpressEmbed()` and answers a different question (runtime * presence of the wp-json nonce + window.archerAi). */ export function useChannel(): Channel { const user = useAuthenticatedUser(); const isWpEmbedBuild = import.meta.env.VITE_WP_EMBED === 'true'; return useMemo( () => resolveChannel({ isWpEmbedBuild, authOrigin: user?.authOrigin as AuthOrigin | undefined, }), [isWpEmbedBuild, user?.authOrigin], ); }