#define private public
#include "../../../../src/windows/window-blur-helper.h"
#undef private

using namespace Sidebar;

WindowBlurHelper::WindowBlurHelper(QObject *parent) : QObject(parent)
{
}

void WindowBlurHelper::setWindowProxy(UkuiQuick::WindowProxy *windowProxy)
{
    m_windowProxy = windowProxy;
}

bool WindowBlurHelper::enable()
{
    return m_enable;
}

void WindowBlurHelper::setEnable(bool enable)
{
    if (m_enable == enable) {
        return;
    }
    m_enable = enable;
    updateBlurArea();
}

double WindowBlurHelper::radius()
{
    return m_radius;
}

void WindowBlurHelper::setRadius(double radius)
{
    if (qFuzzyCompare(m_radius, radius)) {
        return;
    }
    m_radius = radius > 1 ? 1 : radius;
    updateBlurArea();
    Q_EMIT radiusChanged();
}

void WindowBlurHelper::setRegion(qreal x, qreal y, qreal w, qreal h, qreal radius)
{
    Q_UNUSED(radius)
    m_region = QRegion(QRect(qRound(x), qRound(y), qRound(w), qRound(h)));
    updateBlurArea();
}

bool WindowBlurHelper::updateBlurArea()
{
    if (!m_windowProxy) {
        return false;
    }

    const bool enabled = m_enable && !m_region.isEmpty();
    m_windowProxy->setBlurOpacity(enabled ? m_radius : 0);
    m_windowProxy->setBlurRegion(enabled, m_region);
    return enabled;
}

void WindowBlurHelper::enableBlurBehind(WId window, bool enable, const QRegion &region, uint32_t radius)
{
    Q_UNUSED(window)
    Q_UNUSED(enable)
    Q_UNUSED(region)
    Q_UNUSED(radius)
}
