'use client';

/**
 * `@djangocfg/ui-tools/audio-player` subpath entrypoint.
 *
 * `LazyPlayer` is exported as a direct (synchronous) alias of `Player`. We
 * intentionally avoid `React.lazy` + `import('./Player')` here: under bundlers
 * that pre-bundle subpath entries (Vite optimizeDeps in Next.js/Vite/SB), the
 * dynamic import creates a second chunk that re-instantiates the React
 * Contexts (AudioRefCtx/ControlsCtx/MetaCtx/StateCtx/LevelsCtx). The slot
 * components and selector hooks re-exported below would then read from a
 * different context instance than `<PlayerProvider>` writes to, which made
 * `usePlayerAudio` throw "must be used inside <PlayerProvider>".
 *
 * Heavy audio-decoding work (peaks, AudioContext) already happens lazily at
 * runtime via effects inside `PlayerProvider`/`PlayerShell` — there is no
 * benefit to splitting the React shell behind a second chunk.
 */

// ============================================================================
// Player component (synchronous; previously lazy — see note above)
// ============================================================================

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

// ============================================================================
// Light surface — types, store, context, slot components, hooks
// ============================================================================

// 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';

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

// Peak cache helpers
export { clearPeaksCache, setPeaks } from './audio';

// Slot components — presentational, read from PlayerContext. Safe to
// re-export synchronously: they don't import the heavy Player tree
// (audio decoding, layouts, shell) — only context selectors and types.
export { Cover, CoverPlaceholder, ReactivePulse } from './parts/Cover';
export { Title, Artist, TimeDisplay } from './parts/Meta';
export {
  PlayButton,
  SkipButton,
  VolumeControl,
  LoopButton,
  ControlsRow,
  IconButton,
} from './parts/Controls';
export {
  Waveform,
  PeaksWaveform,
  LiveWaveform,
  BarsWaveform,
  ProgressBar,
  WaveformSkeleton,
} from './parts/Waveform';
export { ErrorState } from './parts/ErrorState';
export { DefaultLayout, CompactLayout } from './parts/Layout';
