import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

import "../style"

AbstractButton {
    id: control

    property string densityMode: "normal"

    ApplicationStyle {
        id: applicationStyle
        densityMode: control.densityMode
    }

    Layout.preferredWidth: applicationStyle.smallControlHeight
    Layout.preferredHeight: applicationStyle.smallControlHeight
    implicitWidth: applicationStyle.smallControlHeight
    implicitHeight: applicationStyle.smallControlHeight
    padding: 1
    hoverEnabled: enabled
    focusPolicy: Qt.NoFocus

    contentItem: Item {
        Rectangle {
            anchors.right: parent.right
            anchors.verticalCenter: parent.verticalCenter
            width: applicationStyle.smallControlHeight - 8
            height: applicationStyle.smallControlHeight - 8
            radius: 3
            color: control.down
                   ? applicationStyle.dangerPressedColor
                   : control.hovered
                     ? applicationStyle.dangerHoverColor
                     : applicationStyle.panelColor
            border.width: applicationStyle.borderWidth
            border.color: applicationStyle.controlBorderColor

            Canvas {
                anchors.fill: parent

                onPaint: {
                    var context = getContext("2d")
                    context.clearRect(0, 0, width, height)
                    context.strokeStyle = control.enabled
                            ? applicationStyle.dangerBorderColor
                            : applicationStyle.controlBorderColor
                    context.lineWidth = 3
                    context.lineCap = "round"
                    context.beginPath()
                    context.moveTo(5, 5)
                    context.lineTo(17, 17)
                    context.moveTo(17, 5)
                    context.lineTo(5, 17)
                    context.stroke()
                }
            }
        }
    }

    background: Item {}
}
