import QtQuick
import QtQuick.Controls

Button {
    id: control
    width: 300
    height: 400
    visible: true

    enum LoginType {
        None = 0,
        Face,
        Card,
        Password,
        Finger
    }

    property int loginType: Login.None
    property bool isShowInput: false
    property int centerX: 711 - control.x - 300 - 40
    property int centerY: 371 - control.y - 400 + 60

    property Component faceInputDelegate: Rectangle {
        id: __faceInput
        x: -control.x + width * 1.25
        y: -control.y
        width: 350
        height: 350
        color: "#980e57ea"
        radius: 20

        Column {
            x: 0
            y: 0
            width: 350
            height: 350
            visible: true
            spacing: 30
            padding: 0
            topPadding: 46

            Image {
                width: 200
                height: 200
                opacity: 0.5
                anchors.horizontalCenter: parent.horizontalCenter
                source: "qrc:/resources/png/faceNotice.png"
            }

            Label {
                id: cardNotice
                anchors.horizontalCenter: parent.horizontalCenter
                color: "#9affffff"
                text: qsTr("请刷人脸")
                font.pixelSize: 30
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.bold: true
            }
        }
    }
    property Component cardInputDelegae: Rectangle {
        id: cardInput
        x: -control.x + width * 0.5
        y: -control.y
        width: 350
        height: 350
        color: "#980e57ea"
        radius: 20

        Column {
            x: 0
            y: 0
            width: 350
            height: 350
            spacing: 30
            padding: 0
            topPadding: 46

            Image {
                width: 200
                height: 200
                opacity: 0.5
                anchors.horizontalCenter: parent.horizontalCenter
                source: "qrc:/resources/png/cardNotice.png"
            }

            Label {
                id: faceNotice
                anchors.horizontalCenter: parent.horizontalCenter
                color: "#9affffff"
                text: qsTr("请刷工卡")
                font.pixelSize: 30
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.bold: true
            }
        }
    }
    property Component passwordInputDelegate: Rectangle {
        id: __passwordInput
        x: -control.x - width * 0.5
        y: -control.y
        width: 497
        height: 438
        color: "#980e57ea"
        radius: 20

        Column {
            id: __passwordColumn
            x: 0
            y: 0
            width: 497
            height: 438
            spacing: 30
            padding: 0
            topPadding: 46

            Rectangle {
                x: 72
                width: 353
                height: 68
                color: "#00ffffff"
                border.color: "#a3ffffff"
                border.width: 3
                radius: 10

                TextField {
                    id: usernameText
                    anchors.fill: parent
                    anchors.margins: 2
                    font.pointSize: 15
                    focus: false
                    color: "#a3ffffff"
                    background: Rectangle {
                        color: "transparent" // 使TextField背景透明
                    }
                    placeholderText: qsTr("请输入用户名")
                    font.pixelSize: 30
                    horizontalAlignment: Text.AlignLeft
                    verticalAlignment: Text.AlignVCenter
                    wrapMode: Text.NoWrap
                    selectionColor: "#a300aaff"
                    placeholderTextColor: "#60ffffff"
                    bottomPadding: 5
                    topPadding: 5
                    rightPadding: 20
                    leftPadding: 20
                    renderType: Text.QtRendering
                    font.styleName: "Regular"
                }
            }

            Rectangle {
                x: 72
                width: 353
                height: 68
                color: "#00ffffff"
                border.color: "#a3ffffff"
                border.width: 3
                radius: 10

                TextField {
                    id: passwordText
                    anchors.fill: parent
                    anchors.margins: 2
                    font.pointSize: 15
                    focus: false
                    color: "#a3ffffff"
                    background: Rectangle {
                        color: "transparent" // 使TextField背景透明
                    }
                    placeholderText: qsTr("请输入密码")
                    echoMode: TextInput.Password // 设置echoMode为Password
                    font.pixelSize: 30
                    selectionColor: "#a300aaff"
                    horizontalAlignment: Text.AlignLeft
                    verticalAlignment: Text.AlignVCenter
                    wrapMode: Text.NoWrap
                    placeholderTextColor: "#60ffffff"
                    bottomPadding: 5
                    topPadding: 5
                    rightPadding: 20
                    leftPadding: 20
                    renderType: Text.QtRendering
                    font.styleName: "Regular"
                }
            }

            Button {
                id: __buttonEnter
                x: 72
                width: 353
                height: 68
                text: qsTr("登录")
                contentItem: Label {
                    id: label3
                    text: parent.text
                    font.pixelSize: 30
                    color: "#a3ffffff" // 设置字体颜色
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
                background: Rectangle {
                    color: "#a300aaff"
                    radius: 10 // 设置圆角半径
                }

                Connections {
                    target: __buttonEnter
                    function onClicked() {
                        username_login();
                    }
                }
            }

            Button {
                id: __buttonCancel
                x: 72
                width: 353
                height: 68
                text: qsTr("取消")
                contentItem: Label {
                    text: parent.text
                    font.pixelSize: 30
                    color: "#a3ffffff" // 设置字体颜色
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
                background: Rectangle {
                    color: "#00ffffff"
                    border.color: "#a3ffffff"
                    border.width: 3
                    radius: 10 // 设置圆角半径
                }

                Connections {
                    target: __buttonCancel
                    function onClicked() {
                        isShowInput = false;
                    }
                }
            }
        }
    }
    property Component fingerInputDelegate: Rectangle {
        id: fingerInput
        x: -control.x - width * 1.25
        y: -control.y
        width: 350
        height: 350
        color: "#980e57ea"
        radius: 20

        Column {
            x: 0
            y: 0
            width: 350
            height: 350
            visible: true
            spacing: 30
            padding: 0
            topPadding: 46

            Image {
                width: 200
                height: 200
                opacity: 0.5
                anchors.horizontalCenter: parent.horizontalCenter
                source: "qrc:/resources/png/fingerNotice.png"
            }

            Label {
                id: fingerNotice
                anchors.horizontalCenter: parent.horizontalCenter
                color: "#9affffff"
                text: qsTr("请刷指纹")
                font.pixelSize: 30
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.bold: true
            }
        }
    }

    background: Rectangle {
        id: __background
        color: "#982b7ae9"
        border.color: "#4c2b7ae9"
        border.width: 2                         // 边框宽度
        radius: 20                              // 可选，设置圆角
    }
    icon.height: 150
    icon.width: 120
    display: AbstractButton.TextUnderIcon
    icon.source: ""
    icon.color: "#00ffffff"
    text: ""
    font.pixelSize: 40
    spacing: 20
    palette.buttonText: "#7fffffff"             // 设置字体颜色为绿
    activeFocusOnTab: false

    Loader {
        id: __loginInput
    }

    onIsShowInputChanged: {
        if (!isShowInput)
            console.log(__loginInput.sourceComponent)
            __loginInput.sourceComponent = null;
            console.log(__loginInput.sourceComponent)
        if (isShowInput)
            if (loginType === Login.Face) {
                // TODO: 人脸检测任务
                console.log("人脸检测");
                __loginInput.sourceComponent = faceInputDelegate;
            } else if (loginType === Login.Card) {
                __loginInput.sourceComponent = cardInputDelegae;
            } else if (loginType === Login.Password) {
                __loginInput.sourceComponent = passwordInputDelegate;
            } else if (loginType === Login.Finger) {
                __loginInput.sourceComponent = fingerInputDelegate;
            }
    }

    function username_login() {

    }
}
