//
// Created by Lenn on 2025/10/17.
//

#include "heatmap.hh"
#include "heatmap.impl.hh"
#include "qcustomplot/qcustomplot.h"
#include <qcontainerfwd.h>
#include <qnamespace.h>
#include <qsize.h>

using namespace creeper::plot_widget::internal;

BasicPlot::BasicPlot() : pimpl{std::make_unique<Impl>(*this)} {
    // setStyleSheet("background-color: rgb(255, 0, 0);");
    // QColor lightBlue(230, 240, 250);
    setBackground(Qt::transparent);
}

BasicPlot::~BasicPlot() = default;

void BasicPlot::set_matrix_size(const QSize& size)const {
    pimpl->set_matrix_size(size);
}

void BasicPlot::set_matrix_size(const int& w, const int& h)const {
    QSize size(w, h);
    pimpl->set_matrix_size(size);
}

void BasicPlot::set_color_gradient_range(const double& min, const double& max)const {
    pimpl->set_color_gradient_range(min, max);
}

void BasicPlot::set_xlabel_text(const QString& text)const {
    pimpl->set_xlabel_text(text);
}

void BasicPlot::set_ylabel_text(const QString& text)const {
    pimpl->set_ylabel_text(text);
}

void BasicPlot::load_theme_manager(ThemeManager& mgr)const {
    pimpl->load_theme_manager(mgr);
}

QSize BasicPlot::get_matrix_size() const {
    return pimpl->get_matrix_size();
}

void BasicPlot::set_data(const QVector<PointData>& data)const {
    pimpl->set_data(data);
}

bool BasicPlot::is_initialized() const {
    return pimpl->is_plot_initialized();
}

void BasicPlot::init_plot()const {
    pimpl->initialize_plot();
}

void BasicPlot::paintEvent(QPaintEvent* event) {
    // 确保在绘制前初始化
    if (!is_initialized()) {
        init_plot();
    }
    QCustomPlot::paintEvent(event);
}

void BasicPlot::dataChanged(const QVector<PointData>& map)const {
    set_data(map);
    // emit dataChanged(map);
}

void BasicPlot::dataRangeChanged(const double& min, const double& max)const {
    set_color_gradient_range(min, max);
    // emit dataRangeChanged(min, max);
}

void BasicPlot::update_dynamic_heatmap(const QVector<PointData>& map)const {
    set_data(map);
}

using namespace creeper;

void creeper::HeatMapPlot::paintEvent(QPaintEvent* event) {
    BasicPlot::paintEvent(event);
}