// Pluggable transition registry. The diashow consults this list to populate its
// settings popover and to render the current transition.
//
// Adding a new animation:
//   1. Drop a Svelte file alongside crossfade.svelte / kenburns.svelte.
//   2. Add one entry to `transitions` below (reuse a component with different `props`
//      to expose variants — see the slide directions).
//   3. Rebuild — the popover updates automatically.
//
// This is the extensibility principle from docs/FEATURES.md §2.9 made concrete:
// no diashow code needs to change to add an animation.

import type { Component } from 'svelte';
import Crossfade from './crossfade.svelte';
import KenBurns from './kenburns.svelte';
import Slide from './slide.svelte';

export interface SlideTransition {
	id: string;
	label: string;
	defaultDurationMs: number;
	component: Component<TransitionProps>;
	/** Extra static props merged into the component — lets one component back several
	 *  registry entries (e.g. the slide directions). */
	props?: Partial<TransitionProps>;
}

/** Props every transition Svelte component receives. */
export interface TransitionProps {
	src: string;
	isVideo: boolean;
	durationMs: number;
	/** Fired when a video slide finishes so the parent can advance early. */
	onended?: () => void;
	/** Edge a slide transition enters from (ignored by non-slide components). */
	direction?: 'up' | 'down' | 'left' | 'right';
	/** Which half of a two-layer transition this instance plays: the incoming slide
	 *  ('enter') or the outgoing one being pushed off ('exit'). Ignored by transitions
	 *  that keep the previous frame static (crossfade, Ken Burns). */
	phase?: 'enter' | 'exit';
}

export const transitions: SlideTransition[] = [
	{
		id: 'crossfade',
		label: 'Überblendung',
		defaultDurationMs: 400,
		component: Crossfade as unknown as Component<TransitionProps>
	},
	{
		id: 'kenburns',
		label: 'Ken Burns',
		defaultDurationMs: 600,
		component: KenBurns as unknown as Component<TransitionProps>
	},
	{
		id: 'slide-up',
		label: 'Von unten',
		defaultDurationMs: 1000,
		component: Slide as unknown as Component<TransitionProps>,
		props: { direction: 'up' }
	},
	{
		id: 'slide-left',
		label: 'Von rechts',
		defaultDurationMs: 1000,
		component: Slide as unknown as Component<TransitionProps>,
		props: { direction: 'left' }
	},
	{
		id: 'slide-right',
		label: 'Von links',
		defaultDurationMs: 1000,
		component: Slide as unknown as Component<TransitionProps>,
		props: { direction: 'right' }
	}
];

export function findTransition(id: string): SlideTransition {
	return transitions.find((t) => t.id === id) ?? transitions[0];
}
