package com.andryr.jvcclient.jvc;

import java.util.List;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.andryr.jvcclient.utils.UrlHelper;

public class FavoritesParser {
	public static void parseFavorites(Document doc, List<JvcForum> forumList,
			List<JvcTopic> topicList) {

		Elements elems = doc.select(".liste-with-chevron");
		if (elems.size() >= 2) {
			for (Element elem : elems.first().select(".a-with-chevron")) {
				String name = elem.text();
				String url = UrlHelper.getAbsoluteUrl(elem.attr("href"));
				forumList.add(new JvcForum(name, url));
			}
			for (Element elem : elems.get(1).select(".a-with-chevron")) {
				JvcTopic topic = new JvcTopic();
				topic.setUrl(elem.attr("href"));
				topic.setTitle(elem.text());
				topicList.add(topic);
			}
		}

	}
}
