import type { BlogPostAudioEmbed } from "@/data/blog-post-detail";

const buildSoundCloudEmbedUrl = (url: string) => {
  if (url.includes("w.soundcloud.com/player")) {
    return url;
  }

  const cleanUrl = url.split("?")[0];
  return `https://w.soundcloud.com/player/?url=${encodeURIComponent(cleanUrl)}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true`;
};

export default function BlogPostAudio({ audio }: { audio: BlogPostAudioEmbed }) {
  const embedUrl = buildSoundCloudEmbedUrl(audio.src);

  return (
    <div className="video-wrapper">
      <iframe
        title={audio.title}
        width={audio.width}
        height={audio.height}
        scrolling="no"
        frameBorder="no"
        allow={audio.allow}
        src={embedUrl}
        loading={audio.loading}
      />
    </div>
  );
}
