import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

GridLayout
{
    id: newObject

    columns: 4
    Layout.fillWidth: true
    Layout.fillHeight: true
    rowSpacing: 9


    //// New grid row

    Label
    {
        text: qsTr("Straße*")
        Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
    }

    TextField
    {
        property string name: "street"
        id: street
        Layout.fillWidth: true
        Layout.alignment: Qt.AlignVCenter
        onTextChanged: checkFields()
    }

    Label
    {
        text: qsTr("Nr.*")
        Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
    }

    TextField
    {
        property string name: "houseno"
        id: houseno
        Layout.fillWidth: true
        Layout.alignment: Qt.AlignVCenter
        onTextChanged: checkFields()
    }

    // New grid row
    Label
    {
        text: qsTr("PLZ")
        Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
    }

    ComboBox
    {
        property string name: "postcode"
        id: postcode
        Layout.fillWidth: true
        editable: true
        onCurrentTextChanged: checkFields()
        onEditTextChanged: checkFields()
        onActivated: currentValue
        model: address_model
        textRole: "display"
        popup.height: 300
        currentIndex: -1
        onCurrentIndexChanged: city.currentIndex = postcode.currentIndex

        validator: RegularExpressionValidator
        {
            regularExpression: /([0-9]{1,5})/
        }
    }

    Label
    {
        text: qsTr("Ort")
        Layout.alignment: Qt.AlignRight

    }

    ComboBox
    {
        property string name: "city"
        id: city
        Layout.fillWidth: true
        editable: true
        onEditTextChanged: checkFields()
        onCurrentTextChanged: checkFields()
        model: address_model
        textRole: "city"
        popup.height: 300
        currentIndex: -1
    }

    // New grid row
    Label
    {
        text: qsTr("Parteien")
        Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
    }

    SpinBox
    {
        property string name: "units"
        id: partitions
        Layout.fillWidth: true
        from: 1
        to: 100
        value: 1
        editable: true
    }

    Label
    {
        text: qsTr("Stockwerke")
        Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
    }

    SpinBox
    {
        property string name: "floors"
        id: floors
        Layout.fillWidth: true
        from: 1
        to: 100
        value: 1
        editable: true
    }

    // New grid row
    Label
    {
        text: qsTr("Zwischenetage")
        Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
    }

    ComboBox
    {
        property string name: "mezzanin"
        id: mezzanin
        Layout.fillWidth: true
        editable: false
        model: [qsTr("Ja"), qsTr("Nein")]
    }

    Label
    {
        text: qsTr("Aufzug")
        Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
    }

    ComboBox
    {
        property string name: "lift"
        id: lift
        Layout.fillWidth: true
        editable: false
        model: [qsTr("Ja"), qsTr("Nein")]
    }

    //New grid row
    Label
    {
        text: qsTr("Objekt-Nr.")
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "objectno"
        id: objectno
        Layout.fillWidth: true
        Layout.alignment: Qt.AlignVCenter
        placeholderText: qsTr("0 oder leer um eine Nummer automatisch zu generieren")
        placeholderTextColor: "pink"
    }


    Label
    {
        text: qsTr("Besonderheiten")
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "remarks"
        id: remarks
        Layout.fillWidth: true
    }

    //// New grid row


    Label
    {
        text: qsTr("Reinigungsmittel wo?*")
        Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
    }

    TextField
    {
        property string name: "cleaningproducts"
        id: cleaningproducts
        Layout.fillWidth: true
        onTextChanged: checkFields()
    }
    Item
    {
        Layout.fillHeight: true
    }

    function checkObjectField()
    {

        return  street.text.trim() && houseno.text.trim() &&

                (postcode.editText.trim() || postcode.currentText.trim()) &&
                (city.editText.trim() || city.currentText.trim()) &&
                cleaningproducts.text.trim()
    }
}









