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();
        tabs.add(createTab("Online", updateService));

        friends = new MyFreeCamsFriendsTab(myFreeCams);
        friends.setRecorder(recorder);
        friends.setImageAspectRatio(9.0 / 16.0);
        friends.preserveAspectRatioProperty().set(false);
        tabs.add(friends);

        updateService = new HDCamsUpdateService();
        tabs.add(createTab("HD", updateService));

        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.setImageAspectRatio(9.0 / 16.0);
        tab.preserveAspectRatioProperty().set(false);
        tab.setRecorder(recorder);
        return tab;
    }

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