#include <gmock/gmock.h>

#include "mocks/SessionMock.hpp"
#include "mocks/widgets/AuthPageMock.hpp"
#include "mocks/widgets/MainPageMock.hpp"
#include "utils/UniquePtrMockWrapper.hpp"

#include <Wt/Test/WTestEnvironment>
#include <Wt/WApplication>
#include <Wt/WMenuItem>
#include <Wt/WPopupMenu>

#include <eedb/EEDB.hpp>
#include <eedb/Session.hpp>
#include <eedb/auth/Services.hpp>
#include <eedb/db/connection.hpp>
#include <eedb/widgets/HomePage.hpp>
#include <eedb/widgets/Theme.hpp>

using namespace testing;

class DefaultAuthPageTest : public Test {
  public:
    DefaultAuthPageTest() : app(env) {
        createApp();
    }

    void createApp() {
        auto services = eedb::auth::Services();
        auto session  = std::make_unique< eedb::SessionMock >();

        //		const eedb::auth::Services & baseAuth,
        //			  std::unique_ptr< Wt::Auth::AbstractUserDatabase > userDatabase,
        //			  Wt::Auth::Login & session

        //        EXPECT_CALL(*session, login()).WillOnce(ReturnRef(login));

        //        homePage = std::make_unique< eedb::Home >(*session);
        //        sut      = dynamic_cast< eedb::Home * >(homePage.get());

        //        EXPECT_CALL(*session, enviroment()).WillOnce(ReturnRef(env));
//        sut = new eedb::AuthPageImpl(services, session.login());
    }

  protected:
    Wt::Test::WTestEnvironment env;
    Wt::Auth::Login login;

    std::function< void() > strongLoginCallback;
    Wt::WApplication app;
//    eedb::DefaultAuthPage * sut;
};

TEST_F(DefaultAuthPageTest, createApp) {
    //    auto menu     = dynamic_cast< Wt::WPopupMenu * >(eedb->findWidget("home.navigation.session_menu_popup"));
    //    auto menuItem = dynamic_cast< Wt::WMenuItem * >(eedb->findWidget("home.navigation.session_menu.logout"));
    //    menu->triggered().emit(menuItem);
}

// TEST(a, b) {
//    auto session = std::make_unique< eedb::SessionMock >();
//    EXPECT_CALL(*session, enviroment()).WillOnce(ReturnRef(env));

//    sut = new eedb::EEDB(std::move(session), [this]() { return authPageFactory(); }, [this]() { return homePageFactory(); });

//    //    Wt::WPushButton * b = dynamic_cast< Wt::WPushButton * >(app.findWidget("startbutton"));

//    //    Wt::WProgressBar * bar = dynamic_cast< Wt::WProgressBar * >(app.findWidget("progress"));

//    //    b->clicked().emit(Wt::WMouseEvent());

//    //    environment.endRequest();

//    //    for(;;) {
//    //        boost::this_thread::sleep(boost::posix_time::milliseconds(50));
//    //        std::cerr << "Progress: " << bar->value() << std::endl;
//    //        if(b->isEnabled())
//    //            break;
//    //    }

//    //    environment.startRequest();
//}
