import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import org.qgis 1.0
import org.qfield 1.0

import Theme 1.0


Popup{
    id: popup
    parent: ApplicationWindow.overlay

    property VectorLayer currentLayer
    property var index

    x: 24
    y: 24
    padding: 0
    width: parent.width - 48
    height: parent.height - 48
    modal: true
    closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside

    Page{
        focus: true
        anchors.fill: parent

        header: PageHeader {
            title: qsTr("Attribute Tracker Settings")

            showApplyButton: false
            showCancelButton: false
            showBackButton: true

            onBack: {
                popup.close()
            }
        }

        ScrollView {
            padding: 20
            ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
            ScrollBar.vertical.policy: ScrollBar.AsNeeded
            contentWidth: trackerSettingsGrid.width
            contentHeight: trackerSettingsGrid.height
            anchors.fill: parent
            clip: true

            GridLayout {
                id: trackerSettingsGrid
                width: parent.parent.width
                Layout.fillWidth: true

                columns: 2
                columnSpacing: 0
                rowSpacing: 5

                Label{
                    text: qsTr("Choose attribute:")
                }

                ComboBox{
                    id: attributeSelector

                    textRole: "name"
                    valueRole: "name"
                    model: attributeTrackingModel.getLayerFields(currentLayer)
                }

                QfButton {
                  id: saveButton
                  Layout.topMargin: 8
                  Layout.fillWidth: true
                  Layout.columnSpan: 2
                  font: Theme.defaultFont
                  text: qsTr( "Start tracking")
                  //icon.source: Theme.getThemeVectorIcon( 'directions_walk_24dp' )

                  onClicked: {                      
                    attributeTrackingModel.startTracker(currentLayer, attributeSelector.currentValue, index);
                    dashBoard.visible = false;
                    close();
                  }
                }
            }
        }
    }
}





