// Qt
import QtQuick 2.15
import QtQuick.Controls 2.15
// Project

//  Qml imports
import "qrc:/globals"
import "qrc:/components"
import "qrc:/compounds"
import "qrc:/pages/treatment/adjustments"

TreatmentAdjustmentBase { id : _root
    property bool editingEnabled    : false

    height          : Variables.smallDialogHeight
    width           : Variables.smallDialogWidth
    titleText       : qsTr("Enter Patient ID")

    x               : Math.round((parent.width - width) / 2)
    y               : Math.round((parent.height - height) / 2)
    onCloseClicked  : _root.close()

    // Mouse area used to lower keybaord when clicking outside any TextEntry
    MouseArea { id: _mouseArea
        anchors.fill: parent
        onPressed: {
            focus = true
        }
    }

    Column { id : _column
        spacing: Variables.defaultMargin

        anchors {
            top             : _root.contentItem.top
            topMargin       : Variables.defaultMargin * 2
            horizontalCenter: _root.contentItem.horizontalCenter
        }

        LabelUnitContainer { id: _patientID
            text                            : qsTr("Patient ID")
            contentArea.anchors.leftMargin  : 120

            contentItem : TextEntry { id: _pretreatmentPatientIDEntry
                clip                        : true
                textInput.width             : parent.width - Variables.defaultMargin * 4
                text                        : vTreatmentCreate.patientID
                anchors.centerIn            : parent
                textInput.maximumLength     : 20  // LEAHI-PRS-236
                textInput.rightPadding      : Variables.defaultMargin
                textInput.leftPadding       : Variables.defaultMargin * 14
                textInput.inputMethodHints  : Qt.ImhPreferLowercase
                textInput.echoMode          : TextInput.Normal
                textInput.validator         : RegExpValidator { regExp: Variables.regExp_PatientID }
                line.visible                : false
                enabled                     : _root.editingEnabled

                Text { id: _patientIDPlaceHolderText
                    text                : Variables.emptyEntry
                    anchors.fill        : parent
                    rightPadding        : 125
                    horizontalAlignment : Text.AlignRight
                    font.pixelSize      : Fonts.fontPixelValueControl
                    color               : Colors.offWhite
                    visible             :   _pretreatmentPatientIDEntry.textInput.text.length === 0 &&
                                          ! _pretreatmentPatientIDEntry.textInput.activeFocus
                }
            }
        }

        LabelUnitContainer { id: _secondaryPatientID
            text                            : qsTr("Secondary Patient ID")
            contentArea.anchors.leftMargin  : 120

            contentItem : TextEntry { id: _pretreatmentSecondaryPatientIDEntry
                clip                        : true
                textInput.width             : parent.width - Variables.defaultMargin * 4
                text                        : vTreatmentCreate.patientID
                anchors.centerIn            : parent
                textInput.maximumLength     : 20  // LEAHI-PRS-236
                textInput.rightPadding      : Variables.defaultMargin
                textInput.leftPadding       : Variables.defaultMargin * 14
                textInput.inputMethodHints  : Qt.ImhPreferLowercase
                textInput.echoMode          : TextInput.Normal
                textInput.validator         : RegExpValidator { regExp: Variables.regExp_PatientID }
                line.visible                : false
                enabled                     : _root.editingEnabled

                Text { id: _psecondaryPatientIDPlaceHolderText
                    text                : Variables.emptyEntry
                    anchors.fill        : parent
                    rightPadding        : 125
                    horizontalAlignment : Text.AlignRight
                    font.pixelSize      : Fonts.fontPixelValueControl
                    color               : Colors.offWhite
                    visible             :   _pretreatmentSecondaryPatientIDEntry.textInput.text.length === 0 &&
                                          ! _pretreatmentSecondaryPatientIDEntry.textInput.activeFocus
                }
            }
        }
    }

    ConfirmButton { id : _confirmButton
        anchors {
            bottom          : _root.contentItem.bottom
            bottomMargin    : Variables.defaultMargin * 3
            horizontalCenter: _root.contentItem.horizontalCenter
        }

        width       : Variables.defaultButtonWidth
        height      : Variables.defaultButtonHeight
        visible     : ! vTreatmentCreate.parametersValidated

        anchors {
            top     : undefined
            right   : undefined
            margins : 0
        }

        onClicked   : {
            vTreatmentCreate.patientID          = _pretreatmentPatientIDEntry.text
            vTreatmentCreate.secondaryPatientID = _pretreatmentSecondaryPatientIDEntry.text

            _root.close()
        }
    }
}
