const SPOTIFY_EXTRACTOR =
	/^\/(?<item_type>(?:album|artist|episode|playlist|tracks?))\/?(?<item_id>[a-zA-Z0-9]{22})/gi;

function embed_spotify(link_info) {
	const is_spotify_link = ["spotify.com"].includes(link_info.domain?.toLowerCase());

	if (!is_spotify_link) {
		return;
	}

	SPOTIFY_EXTRACTOR.lastIndex = 0;

	const {
		groups: { item_type, item_id },
	} = SPOTIFY_EXTRACTOR.exec(link_info.path ?? "") ?? { groups: {} };

	if (!item_id) {
		return;
	}

	return `
	<div class="embed-container iframe ${!item_type || item_type.toLowerCase().indexOf("track") === 0 ? "short" : "square"} spotify rounded">
		<div class="embed-actions-container">
			<button class="icon plus" onclick="console.log(\"close\");"/>
			<button class="icon pause" onclick="console.log(\"stop\");"/>
		</div>
		<iframe
		src="https://open.spotify.com/embed/${item_type ?? "track"}/${item_id}"
		allowfullscreen
		allow="clipboard-write; encrypted-media; fullscreen; picture-in-picture"
		loading="lazy"></iframe>
	</div>`;
}
