package ctbrec.ui.sites.myfreecams;

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

import ctbrec.recorder.Recorder;
import ctbrec.sites.mfc.MyFreeCams;
import ctbrec.ui.tabs.PaginatedScheduledService;
import ctbrec.ui.tabs.TabProvider;
import ctbrec.ui.tabs.ThumbOverviewTab;
import javafx.scene.Scene;
import javafx.scene.control.Tab;

public class MyFreeCamsTabProvider extends TabProvider {
    private Recorder recorder;
    private MyFreeCams myFreeCams;
    private MyFreeCamsFriendsTab friends;

    public MyFreeCamsTabProvider(MyFreeCams myFreeCams) {
        this.myFreeCams = myFreeCams;
        this.recorder = myFreeCams.getRecorder();
    }

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

        PaginatedScheduledService updateService = new OnlineCamsUpdateService();
        ThumbOverviewTab online = new ThumbOverviewTab("Online", updateService, myFreeCams);
        online.setRecorder(recorder);
        tabs.add(online);

        friends = new MyFreeCamsFriendsTab(myFreeCams);
        friends.setRecorder(recorder);
        tabs.add(friends);

        updateService = new HDCamsUpdateService();
        ThumbOverviewTab hd = createTab("HD", updateService);
        hd.setImageAspectRatio(9.0 / 16.0);
        hd.preserveAspectRatioProperty().set(false);
        tabs.add(hd);

        updateService = new PopularModelService();
        tabs.add(createTab("Most Popular", updateService));

        updateService = new NewModelService();
        tabs.add(createTab("New", updateService));

        MyFreeCamsTableTab table = new MyFreeCamsTableTab(myFreeCams);
        tabs.add(table);

        return tabs;
    }

    private ThumbOverviewTab createTab(String title, PaginatedScheduledService updateService) {
        ThumbOverviewTab tab = new ThumbOverviewTab(title, updateService, myFreeCams);
        tab.setRecorder(recorder);
        return tab;
    }

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