#include <Display/WidgetDisplay/WorldTrashing/WorldTrashing.hpp>
#include <Display/WidgetDisplay/WorldSelection/WorldSelection.hpp>
#include <Display/WidgetDisplay/WorldCreation/WorldCreation.hpp>
#include <Widget/Label/Label.hpp>
#include <Widget/Layout/Center/Center.hpp>
#include <Widget/Layout/Row/Row.hpp>
#include <Widget/Button/Button.hpp>
#include <Log/Log.hpp>
#include <Display/WidgetDisplay/WorldDisplay/WorldDisplay.hpp>
#include <Widget/Panel/Panel.hpp>
#include <Display/WidgetDisplay/MainMenuDisplay/MainMenuDisplay.hpp>
#include <Widget/TextField/TextField.hpp>
#include <Utilities/Utilities.hpp>
#include <World/LocalWorld/SinglePlayerWorld/SinglePlayerWorld.hpp>
#include <Widget/Layout/Column/HorizontalSeparator/HorizontalSeparator.hpp>
#include <Widget/Layout/CompoundWidget/Form/Form.hpp>
#include <Display/WidgetDisplay/MessageDisplay/MessageDisplay.hpp>
#include <Widget/Button/BackButton/BackButton.hpp>

void WorldTrashing::doTrash()
{
    std::string worldDir = formatString("worlds/$+.voxelverse", worldName);
    std::optional<std::string> error = moveToTrash(worldDir);

    if (error.has_value())
    {
        Display::setCurrent<MessageDisplay>(Material::alert, "Error", formatString("Failed to move to trash: $+", *error));

        return;
    }

    Display::navPop();
}

WorldTrashing::WorldTrashing(std::string worldName) : worldName(worldName)
{
    setWidget(
        new Center(
            new Form(
                "Move to trash?",
                new Label(formatString("Do you want to move the world '$+' to the trash?", worldName)),

                Layout::WithProportion<1>(),
                (new Button("Move to trash", [this](){ doTrash(); }))
                    ->withIcon(Material::trash)
                    ->withFaceColor(Color::danger),

                Layout::WithProportion<1>(),
                new BackButton("Cancel")
            )
        )
    );
}