/**
 * Presentation Types
 *
 * Shared types for RuntimePresentation and constructor.tsx components.
 * These types facilitate code sharing between the two main presentation components.
 */

import type { RuntimePage, RuntimeProject } from './runtime';

/**
 * Transition preview state for video transitions
 */
export interface TransitionPreviewState {
  /** Resolved video URL for playback */
  videoUrl: string;
  /** Raw storage path for cache lookup */
  storageKey: string;
  /** Playback mode: none (forward), reverse (auto-reverse), separate (use reverseVideoUrl) */
  reverseMode: 'none' | 'reverse' | 'separate';
  /** Resolved URL for separate reverse video */
  reverseVideoUrl?: string;
  /** Raw storage path for reverse video cache lookup */
  reverseStorageKey?: string;
  /** Duration in seconds */
  durationSec?: number;
  /** Display title for the preview */
  title: string;
  /** Whether this is a back navigation (for history management) */
  isBack?: boolean;
}

/**
 * Background state for page display
 */
export interface BackgroundState {
  imageUrl: string;
  videoUrl: string;
  audioUrl: string;
}

/**
 * Navigation target resolved from element click
 */
export interface NavigationTarget {
  page: RuntimePage;
  pageId: string;
  transitionVideoUrl?: string;
  transitionReverseMode?: 'auto_reverse' | 'separate_video';
  reverseVideoUrl?: string;
  isBack: boolean;
}

/**
 * API configuration for runtime requests
 */
export interface RuntimeApiConfig {
  headers: {
    'X-Runtime-Project-Slug'?: string;
    'X-Runtime-Environment'?: string;
  };
}

/**
 * Page data loader result
 */
export interface PageDataLoaderResult {
  project: RuntimeProject | null;
  pages: RuntimePage[];
  isLoading: boolean;
  error: string;
  reload: (preservePageId?: string) => Promise<void>;
}

/**
 * Canvas element with navigation properties (for click handling)
 */
export interface NavigableElement {
  id: string;
  type: string;
  targetPageSlug?: string;
  targetPageId?: string;
  transitionVideoUrl?: string;
  transitionReverseMode?: 'auto_reverse' | 'separate_video';
  reverseVideoUrl?: string;
  navType?: 'forward' | 'back';
  navDisabled?: boolean;
  /** Back navigation mode: 'target_page' navigates to fixed slug, 'history' uses page history */
  navBackMode?: 'target_page' | 'history';
}

/**
 * Transition phase from useTransitionPlayback
 */
export type TransitionPhase =
  | 'idle'
  | 'preparing'
  | 'playing'
  | 'reversing'
  | 'completed';

/**
 * Background transition options
 */
export interface BackgroundTransitionOptions {
  pendingTransitionComplete: boolean;
  isBackgroundReady: boolean;
  transitionVideoRef: React.RefObject<HTMLVideoElement | null>;
  pageSwitch: {
    clearPreviousBackground: () => void;
    isSwitching: boolean;
    isNewBgReady: boolean;
    previousBgImageUrl: string;
  };
  onCleanup: () => void;
}
