import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.WebView 1.0

WebViewPage {
    id: webViewPage
    allowedOrientations: Orientation.Portrait | Orientation.Landscape

    property string webPageAddress: ""
    property bool webViewLoading: false
    property int webViewLoadProgress: 0

    WebView {
        id: webView

        anchors.fill: parent

        active: true
        url: webPageAddress

        onLoadingChanged: {
            webViewPage.webViewLoading = loading
            webViewPage.webViewLoadProgress = 0
        }

        onLoadProgressChanged: {
            webViewPage.webViewLoadProgress = loadProgress
        }
    }

    Rectangle {
        id: panel
        color: Theme.highlightDimmerColor
        anchors {
            bottom: parent.bottom
            left: parent.left
            right: parent.right
            //margins: Theme.padding
        }
        width: parent.width
        height: opacity === 0.0 ? 0 : Theme.paddingLarge
        radius: 5

        opacity: (webViewPage.webViewLoading || loadStatusShowTimer.running) ? 0.75 : 0.0
        Behavior on opacity { FadeAnimator {} }

        Timer {
            id: loadStatusShowTimer
        }

        Rectangle {
            anchors.left: parent.left
            color: Theme.secondaryHighlightColor
            width: webViewPage.webViewLoading ? parent.width * (webViewPage.webViewLoadProgress / 100) : 0
            height: parent.height
        }
    }
}