#include "states.h"
#include "wgt_listitem.h"

//-blue app states

unsigned int States::desktopWidth{};
unsigned int States::desktopHeight{};

unsigned int States::DesktopWidth() { return desktopWidth; }
unsigned int States::DesktopHeight() { return desktopHeight; }


//-blue SelectedItemWidgetGroup
namespace {
std::vector<SelectedItemWidgetGroup *> ar_ExistItemGroup{};
}
SelectedItemWidgetGroup *SelectedItemWidgetGroup::GetGroup(const char *groupName) {
    std::string name{groupName};
    auto it = std::ranges::find_if(ar_ExistItemGroup, [&name](auto *item) {
        return item->m_GroupName == name;
    });
    if (it != ar_ExistItemGroup.end()) return *it;
    auto *grp = new SelectedItemWidgetGroup{groupName};
    ar_ExistItemGroup.push_back(grp);
    return grp;
}
//=public
ListItemWidget *SelectedItemWidgetGroup::GetCurSelected() const { return cur_Selected; }
void SelectedItemWidgetGroup::Select(ListItemWidget *item) {
    for (auto member: m_MemberItems) {
        member->SetSelectedFromGroup_(member == item);
    }
    cur_Selected = item;
}
void SelectedItemWidgetGroup::UnSelectAll() {
    for (auto member: m_MemberItems) {
        member->SetSelectedFromGroup_(false);
    }
    cur_Selected = nullptr;
}

//=private
SelectedItemWidgetGroup::SelectedItemWidgetGroup(const char *name) : m_GroupName(name) {}
void SelectedItemWidgetGroup::Add(ListItemWidget *item) {
    m_MemberItems.push_back(item);
}
void SelectedItemWidgetGroup::Remove(ListItemWidget *item) {
    m_MemberItems.remove(item);
}
void SelectedItemWidgetGroup::UnSelectFromItem(ListItemWidget *item) {
    if (cur_Selected == item) {
        item->SetSelectedFromGroup_(false);
        cur_Selected = nullptr;
    }
}













//
