// SPDX-FileCopyrightText: 2026 Marco Allegretti
// SPDX-License-Identifier: EUPL-1.2

import QtQuick

import org.kde.kirigami as Kirigami

Item {
    id: root

    property bool hovered: false
    property bool pressed: false
    property bool active: false
    property bool stateLayerEnabled: true
    property color color: Kirigami.Theme.textColor
    property color activeColor: Kirigami.Theme.highlightColor
    property real hoverOpacity: 0.08
    property real pressedOpacity: 0.14
    property real activeOpacity: 0.12
    property real activeHoverOpacity: 0.18
    property real radius: Kirigami.Units.cornerRadius

    readonly property real layerOpacity: {
        if (!stateLayerEnabled) {
            return 0;
        }
        if (pressed) {
            return pressedOpacity;
        }
        if (active) {
            return hovered ? activeHoverOpacity : activeOpacity;
        }
        return hovered ? hoverOpacity : 0;
    }

    Rectangle {
        anchors.fill: parent
        radius: root.radius
        color: root.active ? root.activeColor : root.color
        opacity: root.layerOpacity

        Behavior on color {
            MotionColorAnimation { type: Motion.EffectsFast }
        }

        Behavior on opacity {
            MotionNumberAnimation { type: Motion.EffectsFast }
        }
    }
}