import QtQuick
import QtQuick.Controls
import QtQuick.Layouts


GridLayout
{
    property alias dbHost: dbHost
    property alias dbPort: dbPort
    property alias dbName: dbName
    property alias dbUserName: dbUserName
    property alias dbPassword: dbPassword
    id: dbGrid
    columns: 2
    columnSpacing: 5
    rowSpacing: 9

    property string name: "database"

    Label
    {
        text: qsTr("Datenbank Einstellungen")
        font.pixelSize: 40
        Layout.columnSpan: 2
        Layout.alignment: Qt.AlignHCenter
        padding: 15
    }


    Label
    {
        text: qsTr("DB-Host:")
        Layout.alignment: Qt.AlignRight

    }

    TextField
    {
        id: dbHost
        placeholderText: qsTr("Hier Host eingeben")
        Layout.fillWidth: true
        property string name: "DB_HOST"
    }

    Label
    {
        text: qsTr("DB-Port:")
        Layout.alignment: Qt.AlignRight
    }

    TextField
    {
        id: dbPort
        placeholderText: qsTr("Hier DB-Port eingeben")
        Layout.fillWidth: true
        validator: IntValidator{bottom: 1025; top: 65535;}
        property string name: "DB_PORT"
    }

    Label
    {
        text: qsTr("DB-Name:")
        Layout.alignment: Qt.AlignRight
    }

    TextField
    {
        id: dbName
        placeholderText: qsTr("Hier DB-Name eingeben")
        Layout.fillWidth: true
        property string name: "DB_NAME"
    }

    Label
    {
        text: qsTr("DB-Benutzername:")
        Layout.alignment: Qt.AlignRight
    }

    TextField
    {
        id: dbUserName
        placeholderText: qsTr("Hier DB-Benutzername eingeben")
        Layout.fillWidth: true
        property string name: "DB_USER"

    }

    Label
    {
        text: qsTr("DB-Passwort:")
        Layout.alignment: Qt.AlignRight
    }

    TextField
    {
        id: dbPassword
        echoMode: TextInput.Password
        placeholderText: qsTr("Hier DB-Passwort eingeben")
        Layout.fillWidth: true
        property string name: "DB_PASS"
    }


    Item
    {
        Layout.fillHeight: true
    }

    Component.onCompleted:
    {
        var db = config.getDbConf()
        if (Object.keys(db).length)
        {
          dbHost.text = db['DB_HOST']
          dbPort.text = db['DB_PORT']
          dbName.text = db['DB_NAME']
          dbUserName.text = db['DB_USER']
          dbPassword.text = db['DB_PASS']
        }
    }
}
