-- Function to update the search results based on the search text

local function updateSearchResults(searchText)
	-- Clear existing search results
	for _, child in ipairs(searchScrollingFrame:GetChildren()) do
		if not child:IsA("UIListLayout") then
			child:Destroy()
		end
	end

	local repositories = config.clippify.Repositories
	local tracks = {} -- This will store the combined tracks from all repositories

	-- Loop through each repository and load the tracks
	for _, repository in ipairs(repositories) do
		local repoTracks = require(repository)
		for _, trackInfo in ipairs(repoTracks) do
			table.insert(tracks, trackInfo)
		end
	end

	-- Filter and copy appropriate track frames based on the search text
	for _, trackInfo in ipairs(tracks) do
		local trackName = trackInfo.name
		if searchText == "" or string.find(string.lower(trackName), string.lower(searchText)) then
			-- Create a copy of the TrackFrame
			local trackFrame = game.ReplicatedStorage.ClipPhone.TrackFrame:Clone()
			trackFrame.Name = trackName
			trackFrame.ArtCover.Image = trackInfo.imageId
			trackFrame.Title.Text = trackName
			trackFrame.Parent = searchScrollingFrame
			trackFrame.Visible = true
		end
	end
end
