#include "app_core/canvas_tool_ui.h"
#include "test_harness.h"

namespace {

void selection_plans_canvas_modes(pp::tests::Harness& harness)
{
    const auto draw = pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::draw);
    PP_EXPECT(harness, draw.operation == pp::app::CanvasToolOperation::select_mode);
    PP_EXPECT(harness, draw.mode == pp::app::CanvasToolMode::draw);
    PP_EXPECT(harness, draw.transform_action == pp::app::CanvasToolTransformAction::none);
    PP_EXPECT(harness, draw.selects_toolbar_button);
    PP_EXPECT(harness, draw.updates_canvas_mode);
    PP_EXPECT(harness, !draw.no_op);

    const auto mask_line = pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::mask_line);
    PP_EXPECT(harness, mask_line.mode == pp::app::CanvasToolMode::mask_line);
    PP_EXPECT(harness, mask_line.updates_canvas_mode);
}

void transform_tools_plan_copy_and_cut_actions(pp::tests::Harness& harness)
{
    const auto copy = pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::copy);
    PP_EXPECT(harness, copy.mode == pp::app::CanvasToolMode::copy);
    PP_EXPECT(harness, copy.transform_action == pp::app::CanvasToolTransformAction::copy);
    PP_EXPECT(harness, copy.updates_canvas_mode);

    const auto cut = pp::app::plan_canvas_tool_select(pp::app::CanvasToolMode::cut);
    PP_EXPECT(harness, cut.mode == pp::app::CanvasToolMode::cut);
    PP_EXPECT(harness, cut.transform_action == pp::app::CanvasToolTransformAction::cut);
    PP_EXPECT(harness, cut.updates_canvas_mode);
}

void pick_and_touch_lock_toggle_state(pp::tests::Harness& harness)
{
    const auto pick_active = pp::app::plan_canvas_tool_pick_toggle(true);
    PP_EXPECT(harness, pick_active.operation == pp::app::CanvasToolOperation::toggle_picking);
    PP_EXPECT(harness, pick_active.requires_draw_mode);
    PP_EXPECT(harness, pick_active.toggles_picking);
    PP_EXPECT(harness, !pick_active.no_op);

    const auto pick_noop = pp::app::plan_canvas_tool_pick_toggle(false);
    PP_EXPECT(harness, pick_noop.requires_draw_mode);
    PP_EXPECT(harness, !pick_noop.toggles_picking);
    PP_EXPECT(harness, pick_noop.no_op);

    const auto touch_lock = pp::app::plan_canvas_tool_touch_lock_toggle();
    PP_EXPECT(harness, touch_lock.operation == pp::app::CanvasToolOperation::toggle_touch_lock);
    PP_EXPECT(harness, touch_lock.toggles_touch_lock);
    PP_EXPECT(harness, !touch_lock.no_op);
}

void button_state_tracks_active_mode_and_toggles(pp::tests::Harness& harness)
{
    const auto draw = pp::app::plan_canvas_tool_button_state(
        pp::app::CanvasToolMode::draw,
        true,
        true);
    PP_EXPECT(harness, draw.mode == pp::app::CanvasToolMode::draw);
    PP_EXPECT(harness, draw.pick_active);
    PP_EXPECT(harness, draw.touch_lock_active);
    PP_EXPECT(harness, draw.pen_active);
    PP_EXPECT(harness, !draw.erase_active);
    PP_EXPECT(harness, !draw.copy_active);
    PP_EXPECT(harness, !draw.flood_fill_active);

    const auto copy = pp::app::plan_canvas_tool_button_state(
        pp::app::CanvasToolMode::copy,
        true,
        false);
    PP_EXPECT(harness, copy.copy_active);
    PP_EXPECT(harness, !copy.pick_active);
    PP_EXPECT(harness, !copy.touch_lock_active);
    PP_EXPECT(harness, !copy.pen_active);

    const auto bucket = pp::app::plan_canvas_tool_button_state(
        pp::app::CanvasToolMode::flood_fill,
        false,
        false);
    PP_EXPECT(harness, bucket.flood_fill_active);
    PP_EXPECT(harness, !bucket.mask_line_active);
}

} // namespace

int main()
{
    pp::tests::Harness harness;
    harness.run("selection plans canvas modes", selection_plans_canvas_modes);
    harness.run("transform tools plan copy and cut actions", transform_tools_plan_copy_and_cut_actions);
    harness.run("pick and touch lock toggle state", pick_and_touch_lock_toggle_state);
    harness.run("button state tracks active mode and toggles", button_state_tracks_active_mode_and_toggles);
    return harness.finish();
}
