import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

GridLayout
{
    id: nationalInsurance
    columns: 2


    Label
    {
        Layout.preferredWidth: bankAccount.longest.width
        text: qsTr("Herkunftsland")
        horizontalAlignment: Text.AlignRight
    }

    ComboBox
    {
        property string name: "country"
        id: nation
        Layout.fillWidth: true
        editable: true
        model: [qsTr("Deutschland"), qsTr("Syrien")]
    }

    Label
    {
        text: qsTr("Sozialversicherungs-Nr")
        Layout.alignment: Qt.AlignRight
    }

    TextField
    {
        property string name: "socialno"
        id: socialno
        Layout.fillWidth: true
    }

    Label
    {
        text: qsTr("Steuer-ID")
        Layout.alignment: Qt.AlignRight
    }

    TextField
    {
        property string name: "taxno"
        id: taxnumber
        Layout.fillWidth: true
    }

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

    TextField
    {
        property string name: "medicalinsurance"
        id: medicalinsurance
        Layout.fillWidth: true
    }
    Label
    {
        text: qsTr("Knappschaft")
        Layout.alignment: Qt.AlignRight
        visible: bankAccount.jobstatus.currentText === "Minijob" ? 1:0
    }

    TextField
    {
        property string name: "knappschaft"
        id: knappschaft
        Layout.fillWidth: true
        visible: bankAccount.jobstatus.currentText === "Minijob" ? 1:0
    }


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

    ComboBox
    {
        property string name: "idtype"
        id: idtype
        Layout.fillWidth: true
        editable: true
        model: [qsTr("Personalausweis"), qsTr("Reisepass")]
    }
    Label
    {
        text: qsTr("Ausweis Nr.")
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "idnumber"
        id: idnumber
        Layout.fillWidth: true
    }

    Label
    {
        text: qsTr("Ausweis gültig bis")
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "idexpiry"
        id: idexpiry
        Layout.fillWidth: true
        validator: RegularExpressionValidator
        {
            regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/
        }
        Keys.onPressed: (event)=>
        {
            if (event.key !== Qt.Key_Backspace)
            {
                var len = idexpiry.length
                var bd = idexpiry.text
                if (len === 2 || len === 5) idexpiry.text = bd + "."
            }
        }
    }
    Label
    {
        text: qsTr("Ausstellungsort")
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "idauthority"
        id: idauthority
        Layout.fillWidth: true
    }
    Label
    {
        id: test
        text: qsTr("Ausgestellt am")
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "idissued"
        id: idissued
        Layout.fillWidth: true
        validator: RegularExpressionValidator
        {
            regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/
        }
        Keys.onPressed: (event)=>
        {
            if (event.key !== Qt.Key_Backspace)
            {
                var len = idissued.length
                var bd = idissued.text
                if (len === 2 || len === 5) idissued.text = bd + "."
            }
        }
    }
    CheckBox
    {
        Layout.preferredWidth: bankAccount.longest.width
        property string name: "worklicense"
        id: worklicense
        text: qsTr("Arbeitserlaubnis <font color='red'><b>?</b></font>")
        visible: nation.currentText === "Deutschland"? false:true
    }
    CheckBox
    {
        property string name: "residencetype"
        id: residencetype
        text: qsTr("Aufenthaltstitel")
        visible: nation.currentText === "Deutschland"? false:true
    }
    Label
    {
        text: qsTr("Aufenthaltstitel Nr.")
        visible: residencetype.checked
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "residenceno"
        id: residenceno
        visible: residencetype.checked
        Layout.fillWidth: true
    }
    Label
    {
        text: qsTr("Ausgestellt von")
        visible: residencetype.checked
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "residenceauthority"
        id: residenceauthority
        visible: residencetype.checked
        Layout.fillWidth: true
    }
    Label
    {
        text: qsTr("Ausgestellt am")
        visible: residencetype.checked
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "residenceissued"
        id: residenceissued
        visible: residencetype.checked
        Layout.fillWidth: true
        validator: RegularExpressionValidator
        {
            regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/
        }
        Keys.onPressed: (event)=>
        {
            if (event.key !== Qt.Key_Backspace)
            {
                var len = residenceissued.length
                var bd = residenceissued.text
                if (len === 2 || len === 5) residenceissued.text = bd + "."
            }
        }
    }
    Label
    {
        text: qsTr("Gültig bis")
        visible: residencetype.checked
        Layout.alignment: Qt.AlignRight
    }
    TextField
    {
        property string name: "residenceexpiry"
        id: residenceexpiry
        visible: residencetype.checked
        Layout.fillWidth: true
        validator: RegularExpressionValidator
        {
            regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/
        }
        Keys.onPressed: (event)=>
        {
            if (event.key !== Qt.Key_Backspace)
            {
                var len = residenceexpiry.length
                var bd = residenceexpiry.text
                if (len === 2 || len === 5) residenceexpiry.text = bd + "."
            }
        }
    }

}


