// Memoised helpers that read state shape without triggering re-renders.

import type { SubtitleCue } from '@/types';
import type { EditorActions, StateSlice } from './types';

export type EditorState = StateSlice & EditorActions;

export const selectTimelineDuration = (s: EditorState): number => {
  let max = 0;
  for (const c of s.clips) max = Math.max(max, c.start + c.duration);
  return max;
};

export const selectActiveSubtitle = (s: EditorState): SubtitleCue | undefined =>
  s.subtitles.find((cue) => s.currentTime >= cue.start && s.currentTime <= cue.end);