/*
    * helpers.cpp
    * Shared helpers for the embedded desktop settings app
    * Copyright (c) 2026 Daniel Hammer
*/

#include "settings_internal.hpp"

namespace settings_app {

bool color_eq(Color a, Color b) {
    return a.r == b.r && a.g == b.g && a.b == b.b;
}

bool settings_status_visible(SettingsState* st) {
    return st->status_msg[0] &&
           (montauk::get_milliseconds() - st->status_time < 4000);
}

void settings_set_status(SettingsState* st, const char* msg) {
    montauk::strncpy(st->status_msg, msg ? msg : "", (int)sizeof(st->status_msg));
    st->status_time = montauk::get_milliseconds();
}

int find_swatch(const Color* palette, Color current) {
    for (int i = 0; i < SWATCH_COUNT; i++) {
        if (color_eq(palette[i], current)) return i;
    }
    return -1;
}

} // namespace settings_app
