'use client';

import { forwardRef } from 'react';
import { PlayerProvider } from './context/PlayerProvider';
import { PlayerShell } from './PlayerShell';
import './styles/webview-safe.css';
import type { PlayerHandle, PlayerProps } from './types';

export const Player = forwardRef<PlayerHandle, PlayerProps>(function Player(props, ref) {
  const {
    src,
    peaks,
    title,
    artist,
    album,
    cover,
    autoplay,
    loop,
    initialVolume,
    muted,
    preload,
    exclusive,
    onPrev,
    onNext,
    onPlay,
    onPause,
    onEnded,
    onError,
    onTimeUpdate,
    variant,
    waveform,
    reactiveCover,
    className,
    ariaLabel,
    enableKeyboardShortcuts,
    seekStartsPlayback,
    autoFocus,
  } = props;

  // onTimeUpdate is intentionally not wired in the provider — we expose it via
  // ref or future hook. Keep the prop accepted so callers can adopt later.
  void onTimeUpdate;

  return (
    <PlayerProvider
      src={src}
      peaks={peaks}
      title={title}
      artist={artist}
      album={album}
      cover={cover}
      autoplay={autoplay}
      loop={loop}
      initialVolume={initialVolume}
      muted={muted}
      preload={preload}
      exclusive={exclusive}
      onPrev={onPrev}
      onNext={onNext}
      onPlay={onPlay}
      onPause={onPause}
      onEnded={onEnded}
      onError={onError}
    >
      <PlayerShell
        className={className}
        variant={variant}
        waveform={waveform}
        reactiveCover={reactiveCover}
        onPrev={onPrev}
        onNext={onNext}
        enableKeyboardShortcuts={enableKeyboardShortcuts}
        ariaLabel={ariaLabel}
        seekStartsPlayback={seekStartsPlayback}
        autoFocus={autoFocus}
        handleRef={ref}
      />
    </PlayerProvider>
  );
});

Player.displayName = 'AudioPlayer';
