#include "pch.h"
#include "log.h"
#include "node_popup_menu.h"

Node* NodePopupMenu::clone_instantiate() const
{
    return new NodePopupMenu();
}

void NodePopupMenu::init()
{
    m_flood_events = true;
    SetPosition(0, 0);
    SetWidth(100);
    SetHeight(500);
    SetPositioning(YGPositionTypeAbsolute);
    m_mouse_ignore = false;
    m_capture_children = false;
}

kEventResult NodePopupMenu::handle_event(Event* e)
{
    switch (e->m_type)
    {
    case kEventType::MouseDownL:
        break;
    case kEventType::MouseUpL:
        if (!m_mouse_inside)
        {
            mouse_release();
        }
        else
        {
            for (int i = 0; i < m_children.size(); i++)
            {
                if (m_children[i]->m_mouse_inside)
                {
                    if (on_select)
                        on_select(this, i);
                    break;
                }
            }
            mouse_release();
        }
        destroy();
        break;
    default:
        return kEventResult::Available;
        break;
    }
    return kEventResult::Consumed;
}
