#include <Milestone/Milestone.hpp>
#include <MilestoneRegistry/MilestoneRegistry.hpp>
#include <Widget/Layout/Column/Column.hpp>
#include <Widget/Layout/CompoundWidget/MilestoneListView/MilestoneListView.hpp>
#include <Widget/Layout/CompoundWidget/MilestoneView/MilestoneView.hpp>

MilestoneListView::MilestoneListView(
    Player &player,
    std::function<void(std::string, int)> onAchievementSelected,
    AchievementFilter &filter
)
{
    std::vector<Milestone*> milestones;
    milestoneRegistry.getSortedMilestoneList(milestones);

    std::vector<Widget*> milestoneViews;
    for (Milestone *milestone : milestones)
    {
        if (!player.isMilestoneReachable(milestone->id))
        {
            continue;
        }

        milestoneViews.push_back(new MilestoneView(player, *milestone, onAchievementSelected, filter));
    }

    addChildren(
        new Column(milestoneViews)
    );
}