/*
    blueROCK - for digital rock
    Copyright (C) 2019  Dorian Zedler

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.9
import QtQuick.Controls 2.4

ListView {
    id: control

    property int status: -1
    property bool loading: false
    property var listData
    property var emptyProperties: []
    property bool useBuiltInPullRefresher: true

    signal refresh()

    anchors {
        leftMargin: 10
        rightMargin: 14
    }

    clip: true

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

    ScrollBar.vertical: ScrollBar {
        parent: control.parent

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

        width: 8

        visible: control.model > 0

        active: true
    }

    Behavior on opacity {
        NumberAnimation {
            duration: 200
        }
    }

    PullRefresher {
        target: control

        visible: control.useBuiltInPullRefresher

        postRefreshDelay: 0

        busyIndicator: FancyBusyIndicator {}
        refreshPosition: height * 1.3

        onRefreshRequested: {
            if(control.useBuiltInPullRefresher) {
                control.refresh()
            }
        }
    }
}
