import { useSound } from "use-sound";
import z from "zod";
import soundSpriteButtons from "../assets/sounds/762132__ienba__ui-buttons.wav";
import soundSprite from "../assets/sounds/842498__newlocknew__uimvmt_game-user-interface-sound-set.mp3";

const UiSoundSetSprites = z.enum([
	"smooth1",
	"smooth2",
	"lobbyCreated",
	"gameStart",
]);

const UiButtonSprites = z.enum(["click1", "click2", "click3", "click4"]);

export default function useInterfaceSound() {
	const [playSprite1] = useSound(soundSprite, {
		sprite: {
			smooth1: [0, 1200],
			smooth2: [7800, 1400],
			lobbyCreated: [53800, 3500],
			gameStart: [62000, 4000],
		},
	});

	const [playSprite2] = useSound(soundSpriteButtons, {
		sprite: {
			click1: [0, 1000],
			click2: [2750, 1000],
			click3: [5200, 1000],
			click4: [7700, 1000],
		},
	});

	const play = ({ id }: { id: string }) => {
		if (UiSoundSetSprites.safeParse(id).success) {
			playSprite1({ id });
		} else if (UiButtonSprites.safeParse(id).success) {
			playSprite2({ id });
		}
	};

	return { play };
}
