import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
ApplicationWindow
{
    id: addMitarbeiter
    title: qsTr("Objekt - Neuer Mitarbeiter")

    ColumnLayout
    {
        anchors.fill: parent
        anchors.margins: 10
        Label
        {
            text: qsTr("Mitarbeiter zuweisen")
            Layout.alignment: Qt.AlignHCenter
            font.pixelSize: 35
        }

        GridLayout
        {
           Layout.fillWidth: true
           columns: 2
           rowSpacing: 4
           columnSpacing: 6

           Label
           {
               text: qsTr("Eingesetzter Mitarbeiter")
               Layout.alignment: Qt.AlignRight
           }
           ComboBox
           {
               id: assignee
               Layout.fillWidth: true
           }
           Label
           {
               text: qsTr("Lohn Mitarbeiter pro Stunde")
               Layout.alignment: Qt.AlignRight
           }
           TextField
           {
               id: wage
               Layout.fillWidth: true
           }
           Label
           {
               text: qsTr("Einsatzdauer")
               Layout.alignment: Qt.AlignRight
           }
           TextField
           {
               id: duration
               Layout.fillWidth: true
           }
           Label
           {
               text: qsTr("Reinigungstage")
               Layout.alignment: Qt.AlignRight
           }
           TextField
           {
               id: cleanDays
               Layout.fillWidth: true
           }
           Label
           {
               text: qsTr("Tätigkeiten")
               Layout.alignment: Qt.AlignRight
           }
           TextField
           {
               id: tasks
               Layout.fillWidth: true
           }
           Label
           {
               text: qsTr("Ertrag")
               Layout.alignment: Qt.AlignRight
           }
           TextField
           {
               id: output
               Layout.fillWidth: true
           }
           Item
           {
               Layout.fillHeight: true
               Layout.columnSpan: 2
           }
        }
        RowLayout
        {
            Layout.fillWidth: true
            spacing: 5
            Item
            {
                Layout.fillWidth: true
            }
            Button
            {
                text: qsTr("Abbrechen")
                onClicked: addMitarbeiter.close()
            }
            Button
            {
                text: qsTr("Hinzufügen")
                onClicked:
                {
                    if (duration.text.trim() !== "" && wage.text.trim() !== "" && cleanDays.text.trim() !== "" && tasks.text.trim() !== "" && output.text.trim() !== "")
                    {
                        var ne = {
                                    "assignee": assignee.currentText,
                                    "duration": duration.text.trim(),
                                    "wage": wage.text.trim(),
                                    "cleandays": cleanDays.text.trim(),
                                    "tasks": tasks.text.trim(),
                                    "output": output.text.trim(),
                                };
                        addMitarbeiter.addNewEmployee(ne)
                        addMitarbeiter.close()
                    }
                }
            }
        }
    }

    signal addNewEmployee(var new_employee)
}
