import QtQuick
import "../config" as Cfg

Rectangle {
    id: card

    required property bool popupOpen
    required property bool isTop
    property bool animEnabled: true
    property bool showShadow: false

    width: parent.width

    anchors.top: isTop ? parent.top : undefined
    anchors.bottom: isTop ? undefined : parent.bottom

    transform: [
        Scale {
            yScale: Cfg.Config.popupAnimType === "bubbleslide"
                        ? (popupOpen ? 1 : 0)
                        : 1
            origin.y: isTop ? 0 : card.height
            Behavior on yScale {
                NumberAnimation {
                    duration: Cfg.Config.popupAnimDuration
                    easing.type: Easing.OutBack
                }
                enabled: animEnabled
            }
        },
        Translate {
            y: Cfg.Config.popupAnimType === "slide"
                   ? (popupOpen ? 0 : (isTop ? -card.height : card.height))
                   : 0
            Behavior on y {
                NumberAnimation {
                    duration: Cfg.Config.popupAnimDuration
                    easing.type: Easing.OutCubic
                }
                enabled: animEnabled
            }
        }
    ]

    opacity: popupOpen ? 1.0 : 0.0
    Behavior on opacity { NumberAnimation { duration: 200 } }

    Rectangle {
        visible:        card.showShadow && card.popupOpen
        anchors.fill:   parent
        anchors.margins: -3
        radius:         card.radius + 3
        color:          "transparent"
        border.color:   Qt.rgba(0, 0, 0, 0.35)
        border.width:   6
        opacity:        card.showShadow && card.popupOpen ? 0.6 : 0
        Behavior on opacity { NumberAnimation { duration: 200 } }
    }

    default property alias _popupCardContent: _content.data

    Item {
        id: _content
        anchors.fill: parent
        z: 2
    }

    MouseArea {
        anchors.fill: parent
        propagateComposedEvents: false
        z: 1
    }
}
