import QtQuick 2.0
import Sailfish.Silica 1.0
import QtQuick.LocalStorage 2.0
import "../helpers/db.js" as Favorites
import "../delegates"

Page {
    property bool sfocus: false
    property bool pageAcitve

    z:1

    SilicaListView {
        id: view
        anchors.fill: parent
        clip: mediaPlayerPanel.expanded
        anchors.bottomMargin: mediaPlayerPanel.visibleSize
        VerticalScrollDecorator {}

        header: Column {
            width: parent.width

            PageHeader {title: "Community Radio Browser";description: qsTr("Found")+" "+view.count + " " +qsTr("countries")}

            SearchField {
                id: sfield
                width: parent.width
                placeholderText: qsTr("Search")
                text: ""
                inputMethodHints: Qt.ImhNoAutoUppercase
                EnterKey.iconSource: "image://theme/icon-m-enter-close"
                EnterKey.onClicked: {focus = false}
                focus: sfocus
                onTextChanged: radioBrowser.countriesModel.filter = text
                onClicked: {view.currentIndex = -1}
            }
        }

        model: radioBrowser.countriesModel.countryModel

        delegate: CountryListDelegate {
            id: countryListDelegate;

            onClicked: {
                sfocus=false;
                Favorites.setSetting("lastCountry",alpha_2)
                pageStack.push("CountryStationsPage.qml",{stationCount: stationcount,_countrycode: alpha_2,searchby:"name"})
            }
        }
    }
}