import QtQuick 2.15

Rectangle {
    id: control

    signal clicked()

    property alias text: label.text
    property alias font: label.font
    property bool lightTheme: false

    implicitWidth: Math.max(150, label.implicitWidth + 34)
    implicitHeight: 42
    radius: 7
    color: !enabled
           ? (lightTheme ? "#EDF1F5" : "#1E293B")
           : buttonMouse.pressed
             ? (lightTheme ? "#D5DEE8" : "#004A99")
             : buttonMouse.containsMouse
               ? (lightTheme ? "#E2E8F0" : "#0054B5")
               : (lightTheme ? "#F8FAFC" : "#005FCC")
    border.width: 1
    border.color: !enabled
                  ? (lightTheme ? "#CBD5E1" : "#475569")
                  : lightTheme
                    ? (buttonMouse.containsMouse ? "#005FCC" : "#B7C4D3")
                    : "#60A5FA"
    opacity: enabled ? 1 : 0.65

    Text {
        renderType: Text.NativeRendering
        id: label

        anchors.fill: parent
        anchors.leftMargin: 17
        anchors.rightMargin: 17
        color: !control.enabled
               ? (control.lightTheme ? "#8793A1" : "#64748B")
               : control.lightTheme ? "#1F2D3D" : "#F8FAFC"
        font.pixelSize: 14
        font.bold: true
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        elide: Text.ElideRight
    }

    MouseArea {
        id: buttonMouse

        anchors.fill: parent
        enabled: control.enabled
        hoverEnabled: true
        acceptedButtons: Qt.LeftButton
        cursorShape: control.enabled
                     ? Qt.PointingHandCursor : Qt.ArrowCursor
        onClicked: control.clicked()
    }
}
