#pragma once

#include "critter.hpp"
#include <RmlUi/Config/Config.h>
#include <RmlUi/Core/Context.h>
#include <RmlUi/Core/DataModelHandle.h>
#include <functional>
#include <map>
#include <vector>

struct NewCritterForm {
    Rml::String name;
    Rml::String gender = "F";
    int mother_id = 0;
    int father_id = 0;
    Rml::String notes;
    Rml::String species;

    void Clear() {
        name.clear();
        gender = "F";
        mother_id = 0;
        father_id = 0;
        notes.clear();
        species.clear();
    }
};

struct AppData {
    Rml::String page_title = "Main";
    bool is_add_critter_dialog_open = false;
    bool is_confirmation_dialog_open = false;
    Rml::String confirmation_dialog_text = "Are you sure?";
    bool confimation_dialog_result = false;
    Rml::String error_message;
    NewCritterForm new_critter_form;

    std::function<void()> on_confirm_action = nullptr;
};

void sync_map_to_list(const std::map<int, Critter> &critters, std::vector<CritterEntry> &critter_list);
bool setup_data_binding(Rml::Context *context, Rml::DataModelHandle &model_handle, AppData &app_data, std::vector<CritterEntry> &critter_list, std::map<int, Critter> &critters);