#ifndef DECK_HPP_
#define DECK_HPP_

#include <Widget/Layout/CompoundWidget/CompoundWidget.hpp>

template<typename TLayout, typename... Wrappers>
class Deck final : public CompoundWidget
{
private:
    template<typename...>
    struct WrapHelper {};

    template<>
    struct WrapHelper<>
    {
        template<typename TAny>
        static TAny wrap(TAny widget)
        {
            return widget;
        }
    };

    template<typename NextWrapper, typename... RestWrappers>
    struct WrapHelper<NextWrapper, RestWrappers...>
    {
        template<int proportion>
        static Layout::WithProportion<proportion> wrap(Layout::WithProportion<proportion> prop)
        {
            return prop;
        }

        static Widget* wrap(Widget *widget)
        {
            return new NextWrapper(WrapHelper<RestWrappers...>::wrap(widget));
        }

        static std::vector<Widget*> wrap(std::vector<Widget*> widgets)
        {
            std::vector<Widget*> wrapped;
            for (Widget *widget : widgets)
            {
                wrapped.push_back(new NextWrapper(WrapHelper<RestWrappers...>::wrap(widget)));
            }

            return wrapped;
        }
    };

public:
    template<typename... TChildren>
    Deck(TChildren... children) : CompoundWidget(
        new TLayout(WrapHelper<Wrappers...>::wrap(children)...)
    ) {}
};

#endif