import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Dialogs
import "../js/qmldict.js" as JsLib

ColumnLayout
{
    property var new_object: null
    //property alias checkAddContact: checkAddContact
    Layout.fillWidth: true
    Layout.fillHeight: true
    spacing: 15
    Label
    {
        text: qsTr("Angebot anlegen")
        horizontalAlignment: Text.AlignHCenter
        Layout.fillWidth: true
        font.pixelSize: 35
    }


    RowLayout
    {
        id: addObject
        Layout.fillWidth: true
        Layout.fillHeight: true
        spacing: 45

        Frame
        {
            Layout.alignment: Qt.AlignTop
            Layout.fillWidth: true
            AddNewOffer
            {
                id: newOffer
                width: parent.width
            }
        }


    }
    RowLayout
    {
        Layout.fillHeight: true
        Layout.alignment: Qt.AlignRight
        Button
        {
            text: qsTr("Abbrechen")
            onClicked: contentStack.pop()
        }
        Button
        {
            property var new_object: null
            id: saveBtn
            text: qsTr("Speichern")
            enabled: false
            onClicked:
            {
                // new_object = JsLib.parseForm(newObject)
                // new_object['lift'] = new_object['lift'] === 'Ja' ? 1 : 0
                // new_object['mezzanin'] = new_object['mezzanin'] === 'Ja' ? 1 : 0
                // object_model.addObject(new_object)
            }
        }
    }
    Item
    {
        id: spacer3
        Layout.fillHeight: true
    }

    Component.onCompleted:
    {
        //object_model.objectAdded.connect(onObjectAdded)
        //contact_model.objectContactAdded.connect(onObjectContact)
    }


    // Connections
    // {
    //     target: object_model

    //     function onObjectIdReady()
    //     {
    //         var obj_id = arguments[0]
    //         if (checkAddObjectContact.checked && obj_id)
    //         {
    //             var new_objecto = addObjectLayout.getForm()
    //             contact_model.addObjectContact(new_objecto, obj_id)
    //             object_model.viewCriterion("Alle")
    //         }

    //         appLoader.source = "ObjectTable.qml"
    //     }
    // }

    // function checkFields()
    // {
    //     if(checkAddObjectContact.checked)
    //     {
    //         if(!newObject.checkObjectField() || !addObjectLayout.contactPerson.contacts || !addObjectLayout.contactPerson.contacts.length)
    //             saveBtn.enabled = false
    //         else
    //             saveBtn.enabled = true
    //     }
    //     else if (!newObject.checkObjectField())
    //         saveBtn.enabled = false
    //     else
    //         saveBtn.enabled = true
    // }
}
