#pragma once

#include "widget.h"
#include "pushbutton.h"
#include "cascademenubutton.h"
#include "menuseparator.h"
#include "core/rectangle.h"

class MenuDrop : public Widget
{
public:
    explicit MenuDrop(const std::shared_ptr<kku::CoreFactory>& factory);

    virtual void input(const kku::SystemEvent& event) override;
    virtual void update(const kku::microsec& dt) override;
    virtual void display() const override;
    virtual void move(const kku::Vector2<float>& delta) override;
    virtual bool isUnderMouse(const kku::Point& position) const override;
    virtual void setVisibility(bool is_visible = true) override;

    virtual void setRect(const kku::Area<float>& rect) override;
    virtual kku::Area<float> getRect() const override;

    virtual void setPosition(const kku::Point& position) override;
    virtual kku::Point getPosition() const override;

    void addPushButton(const std::shared_ptr<PushButton>& button);
    void addCascadeButton(const std::shared_ptr<CascadeMenuButton>& button);
    void addSeparator(const std::shared_ptr<MenuSeparator>& separator);

    void lock();
    void unlock();
    bool isLocked() const;

private:
    std::shared_ptr<kku::Rectangle> _content_rect;
    bool _is_locked;

    std::size_t _button_height;
    std::size_t _button_index;

    std::vector<std::shared_ptr<MenuDrop>> _submenus;

    void add(const std::shared_ptr<Widget>& widget);
    bool hasActiveSubmenus() const;
};
