export function convertToEmbedUrl(url: string): string {
    const match = url.match(/(?:shorts\/|watch\?v=|youtu\.be\/)([^?&]+)/);
    if (!match) return url;

    const videoId = match[1];
    return `https://www.youtube.com/embed/${videoId}?autoplay=1&vq=highres&rel=0&modestbranding=1`;
}

export function getYoutubeId(url: string): string | null {
    const regex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|shorts)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/;
    const match = url.match(regex);
    return match ? match[1] : null;
}

export function getYoutubeThumbnail(url: string): string {
    const id = getYoutubeId(url);
    return id ? `https://img.youtube.com/vi/${id}/maxresdefault.jpg` : '';
}