import QtQuick 2.0
import Sailfish.Silica 1.0
import Nemo.Configuration 1.0 /////////
import Nemo.Notifications 1.0 ///////////
import Amber.Mpris 1.0
import "pages"
import "items"
//import "radio-player"
//import "video-player"
import "helpers"
//import "jupii"

// Check out Amber Mpris Qml !!!

ApplicationWindow
{
    id: allRadio
    property string _version: "2.0.15"
    property string _language: Qt.locale().name.slice(0,2)
    property string _country: Qt.locale().name.slice(-2)
    property int sleepTime: 0
    property alias settings: allradioSettings
    property alias mediaPlayerPanel: mediaPlayerPanel
    property RadioPlayer radioPlayer : RadioPlayer {id:radioPlayer}
    property RadioBrowser radioBrowser : RadioBrowser {id:radioBrowser;parent: allRadio}
    property SleepTimer sleepTimer : SleepTimer {id:sleepTimer}

    RadioMprisPlayer {id: radioMprisPlayer}
    MediaPlayerPanel {id: mediaPlayerPanel}
    ConfigurationGroup {id:settingsGroup;path: "/apps/harbour-allradio";ConfigurationGroup {id: allradioSettings;path: "/settings"}}
    Notification {id: notification;onClicked: console.log("Clicked")}
    //MprisPlayer {}

    function handleArguments() {
         for(var i = 1; i < Qt.application.arguments.length; i++) {
             switch (Qt.application.arguments[i]) {
                 case "--help": help();break; // no argument
                 //case "--codec": console.info("*** CODEC *** "+Qt.application.arguments[i+1]);break; // argument can be: mp3, aac, aac+, hls
                 //case "--favorite": console.info("*** FAVORITE *** "+Qt.application.arguments[i+1]);break; // argument can be: top, latest, random
                 //case "--pause": console.info("*** HISTORY *** "+Qt.application.arguments[i+1]);break; // argument can be: top, latest, random
                 case "--sleep": console.info("*** SLEEP *** : "+Qt.application.arguments[i+1]);break; // play for 1-120 minutes (sleeptimer)
                 case "--latest": console.info("*** PLAY *** : "+Qt.application.arguments[i+1]);latest();break; // latest, saved, random, world
                 case "--random": console.info("*** PLAY *** : "+Qt.application.arguments[i+1]);random();break; // latest, saved, random, world
             }
         }
    }
    function help(){
        console.info("help")

    }
    function latest(){
        radioPlayer.loadRecentPlay()
        radioPlayer.playStream()

    }
    function random(){
        radioPlayer.loadRandomPlay()
        radioPlayer.playStream()

    }
        initialPage: Component { AllRadio { } }
    cover: Qt.resolvedUrl("cover/CoverPage.qml")
    allowedOrientations: defaultAllowedOrientations
    Component.onCompleted: {mediaPlayerPanel.parent.z = 99;handleArguments()}
}
