import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12

import Controls 1.0 as Controls
import Utils 1.0

Rectangle {
    color: Qt.darker(Palette.hoveredBackgroundColor, 1.05)
    height: 50
    radius: 6

    property Dialog dialog: undefined

    RowLayout {
        anchors.fill: parent

        Controls.SubtitleLabel {
            text: root.title
            leftPadding: 20
            topPadding: 0
            bottomPadding: 0
            verticalAlignment: Text.AlignVCenter
            Layout.fillWidth: true
            Layout.preferredHeight: parent.height

            MouseArea {
                anchors.fill: parent

                property int lastX: 0
                property int lastY: 0

                onPressed: {
                    lastX = mouse.x
                    lastY = mouse.y
                }

                onPositionChanged:{
                    var deltaX = mouse.x - lastX
                    dialog.x += deltaX
                    lastX = mouse.x - deltaX

                    var deltaY = mouse.y - lastY
                    dialog.y += deltaY
                    lastY = mouse.y - deltaY
                }
            }
        }

        Image {
            id: closeImage
            source: "qrc:/Icons/close.svg"
            sourceSize.width: 36
            sourceSize.height: 36
            Layout.rightMargin: 10

            MouseArea {
                anchors.fill: parent
                propagateComposedEvents: true

                onPressed: {
                    closeImage.sourceSize.width = 32
                    closeImage.sourceSize.height = 32
                }
                onReleased: {
                    closeImage.sourceSize.width = 36
                    closeImage.sourceSize.height = 36
                }
                onClicked: {
                    root.close()
                }
            }
        }
    }
}
