import QtQuick 2.0
import QtQuick.XmlListModel 2.0

Item {
    // radio-browser advanced:
    ////property int bitrateMin: 0
    ////property int bitrateMax: 1000000
    ////property string state: ""
    ////property bool stateExact: false
    ////property string language: ""
    ////property bool languageExact: false
    ////property string tagList: "" // commaseparated string
    property string name: ""
    property bool nameExact: false
    property string countrycode: ""
    property string tag: ""
    property bool tagExcact: false
    property string codec: ""
    property string order: "" // name, url, homepage, favicon, tags, country, state, language, votes, codec, bitrate, lastcheckok, lastchecktime, clicktimestamp, clickcount, clicktrend, random
    property bool reverse: false//order === name ? false : true // true if name
    property int offset: 0
    property int limit: 150
    property string source: ""

    // Allradio specific:
    property string country: countrycode ? radioBrowser.getCountryName(countrycode) : "World"
    property alias finished: searchModel.finished
    property string filterString
    property alias stationsModel: searchModel.stationsModel
    property bool clear: false
    property AdvancedSearchModel searchModel : AdvancedSearchModel {id:searchModel}

    onSourceChanged: {searchModel.source = source}
    onClearChanged: if (clear) {searchModel.clear;searchModel.stationsModel.clear();offset=0;clear=false}

    function getStations() {
        searchModel.xml=""
        filterString = ""
        if (name !== "") {filterString = "&name="+name+"&nameExact="+nameExact}
        if (countrycode !== "") filterString = filterString + "&countrycode="+countrycode
        if (tag !== "") filterString = filterString + "&tag="+tag+"&tagExact="+tagExcact
        if (codec !== "") filterString = filterString + "&codec="+codec
        if (order !== "") filterString = filterString + "&order="+order
        if (order === "name") reverse = false; else reverse = true
        filterString = filterString + "&reverse="+reverse + "&offset="+offset+"&limit="+limit
     //   console.log(radioBrowser.serverUrl + "/xml/stations/search?hidebroken=true"+filterString)
        source = radioBrowser.serverUrl + "/xml/stations/search?hidebroken=true"+filterString
    }
}

