package ctbrec.ui.sites.jasmin;

import java.util.ArrayList;
import java.util.List;

import ctbrec.sites.jasmin.LiveJasmin;
import ctbrec.ui.tabs.TabProvider;
import ctbrec.ui.tabs.ThumbOverviewTab;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.util.Duration;

public class LiveJasminTabProvider extends TabProvider {

    private LiveJasmin liveJasmin;
    private LiveJasminFollowedTab followedTab;

    public LiveJasminTabProvider(LiveJasmin liveJasmin) {
        this.liveJasmin = liveJasmin;
    }

    @Override
    public List<Tab> getTabs(Scene scene) {
        List<Tab> tabs = new ArrayList<>();

        tabs.add(createTab("Girls", liveJasmin.getBaseUrl() + "/en/girl/?listPageOrderType=most_popular"));
        tabs.add(createTab("Girls HD", liveJasmin.getBaseUrl() + "/en/girl/hd/?listPageOrderType=most_popular"));
        tabs.add(createTab("New Girls", liveJasmin.getBaseUrl() + "/en/girls/newbie/?listPageOrderType=most_popular"));
        tabs.add(createTab("Boys", liveJasmin.getBaseUrl() + "/en/boy/?listPageOrderType=most_popular"));
        tabs.add(createTab("Boys HD", liveJasmin.getBaseUrl() + "/en/boy/hd/?listPageOrderType=most_popular"));

        followedTab = new LiveJasminFollowedTab(liveJasmin);
        followedTab.setRecorder(liveJasmin.getRecorder());
        followedTab.setImageAspectRatio(9.0 / 16.0);
        tabs.add(followedTab);

        return tabs;
    }

    @Override
    public Tab getFollowedTab() {
        return followedTab;
    }

    private ThumbOverviewTab createTab(String title, String url) {
        LiveJasminUpdateService s = new LiveJasminUpdateService(liveJasmin, url);
        s.setPeriod(Duration.seconds(60));
        ThumbOverviewTab tab = new LiveJasminTab(title, s, liveJasmin);
        tab.setRecorder(liveJasmin.getRecorder());
        tab.setImageAspectRatio(9.0 / 16.0);
        return tab;
    }
}
