'use client';

/**
 * `@djangocfg/ui-tools/audio-player` subpath entrypoint.
 *
 * We deliberately keep this surface narrow:
 *
 *   - `Player` / `LazyPlayer` — the only React component you should
 *     import. Already wraps `<PlayerProvider>` + `<PlayerShell>`.
 *   - types
 *   - `PlayerProvider` + selector hooks — for the rare consumer that
 *     wants to render a fully custom layout. They must own the
 *     provider themselves.
 *   - cross-instance store helpers (active player, preferences).
 *
 * Slot components (Cover/Title/Waveform/Controls/Layout) and internal
 * peak-cache helpers are NOT re-exported from this entrypoint. Earlier
 * versions did re-export them, which produced a second module-graph
 * entry into the `context/*` files under Vite's `optimizeDeps`
 * pre-bundling — the slot files import the same selectors as
 * `PlayerShell`, but via a different URL key, so `<PlayerProvider>`
 * (one context instance) and `usePlayerAudio` inside a slot read
 * (another context instance) ended up on different `createContext()`
 * objects → "usePlayerAudio must be used inside <PlayerProvider>".
 *
 * If you need raw slots, import from a deeper path (e.g.
 * `@djangocfg/ui-tools/src/tools/media/AudioPlayer/parts/Cover`) and
 * accept that you must own a single `<PlayerProvider>` boundary.
 */

// ============================================================================
// Player component (synchronous; previously lazy)
// ============================================================================

export { Player, Player as LazyPlayer } from './Player';

// ============================================================================
// Types
// ============================================================================

export type {
  PlayerProps,
  PlayerState,
  PlayerStateKind,
  PlayerControls,
  PlayerHandle,
  WaveformConfig,
  WaveformMode,
  ReactiveCoverMode,
  PlayerVariant,
  PlayerErrorReason,
} from './types';

// ============================================================================
// Context provider + selector hooks (no UI)
// ============================================================================

export {
  PlayerProvider,
  usePlayerAudio,
  usePlayerControls,
  usePlayerDuration,
  usePlayerLevels,
  usePlayerMeta,
  usePlayerPaused,
  usePlayerState,
} from './context';

// ============================================================================
// Cross-instance store (active player, preferences)
// ============================================================================

export {
  setActivePlayer,
  getActivePlayer,
  getLastActivePlayer,
  subscribeActivePlayer,
  getPreferences,
  setStoredVolume,
  setStoredMuted,
  subscribePreferences,
  type PlayerPreferences,
} from './store';

export {
  useActivePlayer,
  useLastActivePlayer,
  useIsActivePlayer,
} from './hooks/useActivePlayer';
export { usePlayerPreferences } from './hooks/usePlayerPreferences';
