export function normalizeYouTubeVideoId(input:string):string{
  const value=String(input||'').trim();if(/^[A-Za-z0-9_-]{11}$/u.test(value))return value;
  try{const url=new URL(value);const host=url.hostname.toLowerCase().replace(/^www\./u,'');if(host==='youtu.be')return url.pathname.split('/').filter(Boolean)[0]?.slice(0,11)||'';if(host.endsWith('youtube.com')){const query=url.searchParams.get('v');if(query&&/^[A-Za-z0-9_-]{11}$/u.test(query))return query;const parts=url.pathname.split('/').filter(Boolean);const marker=parts.findIndex(part=>['embed','shorts','live'].includes(part));if(marker>=0&&/^[A-Za-z0-9_-]{11}$/u.test(parts[marker+1]||''))return parts[marker+1];}}catch{/* Accept IDs only after URL parse fails. */}return'';
}
export function normalizeWistiaMediaId(input:string):string{
  const value=String(input||'').trim();if(/^[A-Za-z0-9]{8,32}$/u.test(value))return value;
  try{const url=new URL(value);const parts=url.pathname.split('/').filter(Boolean);for(const marker of ['medias','iframe','embed']){const index=parts.lastIndexOf(marker);if(index>=0&&/^[A-Za-z0-9]{8,32}$/u.test(parts[index+1]||''))return parts[index+1];}for(let index=parts.length-1;index>=0;index--)if(/^[A-Za-z0-9]{8,32}$/u.test(parts[index]))return parts[index];}catch{/* Invalid URL. */}return'';
}
export function normalizeDirectVideoUrl(input:string):string{try{const url=new URL(String(input||'').trim());return url.protocol==='https:'?url.toString():'';}catch{return'';}}
