import QtQuick 2.10
import QtQuick.Controls 2.4

import de.itsblue.ScStw.Styling.Components 1.0

Item {
    id: control

    property var loadData
    property var listData: ({})
    property Component delegate
    property alias view: listView

    property int status: -1

    property alias contentY: listView.contentY
    property alias model: listView.model

    signal refresh()

    Component.onCompleted: {

    }

    ListView {
        id: listView

        model: control.listData === undefined ? 0:control.listData.length

        anchors.fill: parent

        boundsBehavior: Flickable.DragOverBounds
        boundsMovement: Flickable.StopAtBounds

        anchors.margins: 1
        anchors.rightMargin: 14
        clip: true

        //enabled: status === 200 || status === 902
        //opacity: enabled ? 1:0

        ScrollBar.vertical: ScrollBar {
            parent: listView.parent

            anchors {
                top: listView.top
                left: listView.right
                margins: 10
                leftMargin: 3
                bottom: listView.bottom
            }

            width: 8

            visible: listView.model > 0

            active: true
        }

        delegate: control.delegate

        onContentYChanged: {
/*
            if(contentY < -listView.height * 0.3 && control.status !== 905){
                contentY = 0
                control.refresh()
            }*/
        }

        Behavior on opacity {
            NumberAnimation {
                duration: 200
            }
        }

    }

    BusyIndicator {
        anchors.centerIn: parent

        width: app.landscape() ? parent.height * 0.1:parent.width * 0.1
        height: width

        opacity: !(status === 200 || status === 902) ? 1:0

        Behavior on opacity {
            NumberAnimation {
                duration: 200
            }
        }
    }
}
