import QtQuick 2.0
import Sailfish.Silica 1.0
import "../delegates"
//import "../delegates_"
import "../items"

DockedPanel {
 //   property real showP: 0.0
//    property int tab: 0
    id: dock

  //  property alias videoSource: videoPlayer.videoSource

    dock: Dock.Bottom
    z: 99
    width: parent.width
    height: Theme.itemSizeExtraLarge //play.height + (Theme.paddingMedium * 2)
    animationDuration: 250
    open: !radioBrowser.loading ? true : false

  //  onOpenChanged: if (open) {
  //                     mediaPlayerPanel.videoSource = radioPlayer
  //                     if (radioPlayer.isPlaying || radioPlayer.isPaused && radioPlayer.radioVideo) radioPlayer.resumeStream()
  //                 }

 //   onVisibleChanged: if (visible) {
 //                         mediaPlayerPanel.videoSource = radioPlayer
 //                        if (radioPlayer.isPlaying || radioPlayer.isPaused && radioPlayer.radioVideo) radioPlayer.resumeStream()
 //                     }

   // onOpenChanged: open ? videoOn() : videoOff()


    SilicaItem {
        anchors.top: parent.top
        width: parent.width
        height: Theme.itemSizeExtraLarge
  /*      VideoPlayer {
            id: videoPlayer
            z:98
            //anchors.top: orientation === Orientation.Portrait ? stationimage.top : allRadio.top
            //anchors.bottom: orientation === Orientation.Portrait ? stationimage.bottom : allRadio.bottom
            //anchors.left: orientation === Orientation.Portrait ? stationimage.left : allRadio.left
            //anchors.right: orientation === Orientation.Portrait ? stationimage.right : allRadio.right
            //anchors.margins: orientation === Orientation.Portrait ? stationimage.border.width : 0
            anchors.fill: stationimage
            visible: radioPlayer.isVideo && !radioPlayer.isPaused ? true : false
            onVisibleChanged: visible ? enabled=true : enabled = false
        //    videoSource: radioPlayer//dock.open ? radioPlayer : null
            //color: orientation === Orientation.Portrait ? "transparent" : "black"
            //videoSource: radioPlayer.videoP ? null : radioPlayer
            //videoSource: radioPlayer.playerPageOpen ? null : radioPlayer
        } */
    RadioImage {
        id: stationimage
      //  visible: !videoPlayer.visible
        height: parent.height * 0.8 //- (Theme.paddingMedium * 2)
        width: height
        anchors.verticalCenter: parent.verticalCenter
        anchors.left: parent.left
        anchors.leftMargin: Theme.paddingMedium
        stationImage: radioPlayer._favicon
        stationLabel: radioPlayer._name
    }

    Item {
        id: songInfo
        anchors.verticalCenter: stationimage.verticalCenter
        height: play.height //- (Theme.paddingMedium * 2)
        anchors.leftMargin: Theme.paddingLarge
        anchors.rightMargin: Theme.paddingLarge
        anchors.left: stationimage.right
        anchors.right: play.left
        Column {
            anchors.verticalCenter: parent.verticalCenter
            width: parent.width
            Label {
                id: rname
                font.pixelSize: Theme.fontSizeSmall
                elide: Text.ElideRight
                width: parent.width
                font.bold: true
                text: radioPlayer._name
            }
       //     Row {
       //         spacing: Theme.paddingMedium
       /*         Image {
                    id: headerLogo
                    anchors.bottom: rcountry.bottom
                    height: rcountry.height * 0.8
                    fillMode: Image.PreserveAspectFit
                    smooth: true
//                    source: radioPlayer._cc === "" ? radioPlayer._cc ? "../images/bycountry_t.png" : "" : "../flags/"+radioPlayer._cc.toLowerCase()+".png"
                    source: "../flags/"+radioPlayer._cc.toLowerCase()+".png"
                } */
            Label {
                id: rcountry
                color: Theme.secondaryColor
                font.pixelSize: Theme.fontSizeSmall
                width: parent.width
                elide: Text.ElideRight
                text: radioPlayer.radioCountryName
     //       }
            }
        }
    }

    MouseArea {
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.right: songInfo.right
        onClicked: {
           // if (radioPlayer.isPlaying && radioPlayer.radioVideo)
            //if (radioPlayer.radioVideo) radioPlayer.videoPause()
            pageStack.push("../pages/RadioPlayerPage.qml")
        }
    }

    IconButton {
        id: play
        anchors.right: parent.right
        anchors.rightMargin: Theme.paddingMedium
        anchors.verticalCenter: parent.verticalCenter
        icon.source: radioPlayer.isPlaying ? "image://theme/icon-l-pause" : "image://theme/icon-l-play"
        onClicked: if (radioPlayer.isPlaying) radioPlayer.pauseStream(); else {radioPlayer.resumeStream(); }//if (radioPlayer.radioVideo) pageStack.push("RadioPlayerPage.qml")}//icon.source == "image://theme/icon-l-play" ? icon.source = "image://theme/icon-l-pause" : icon.source = "image://theme/icon-l-play"
    }
    BusyIndicator {
        id: busy
        visible: running
        anchors.centerIn: play
        size: BusyIndicatorSize.Medium
        running: radioPlayer.radioStatus===2
    }

    }






}
