import { createElement } from 'react';
/**
 * Renders a GradialVideo as a <video> element.
 *
 * - Uses poster.fallback.src for the poster attribute (single URL — browser limitation).
 * - Includes <source> elements for format variants when available.
 * - Falls back to src attribute on <video> when no source variants exist.
 */
export function GradialVideoPlayer({ video, ...attrs }) {
    const posterSrc = video.poster?.fallback.src;
    const hasSources = video.sources && video.sources.length > 0;
    const videoAttrs = {
        poster: posterSrc,
        width: video.width > 0 ? video.width : undefined,
        height: video.height > 0 ? video.height : undefined,
        ...attrs,
    };
    // If no format variants, put src directly on <video>
    if (!hasSources) {
        videoAttrs.src = video.src;
    }
    const children = (video.sources ?? []).map((source, index) => createElement('source', {
        key: index,
        src: source.src,
        type: source.type,
    }));
    return createElement('video', videoAttrs, ...children);
}
