import QtQuick 2.12

import "qrc:/globals"
import "qrc:/components"

Rectangle { id: _root

    property alias menuHidden               : _headerMenu.hidden
    property alias headerMenuIndex          : _headerMenu.index

    width   : Variables.applicationWidth
    height  : Variables.headerHeight
    clip    : true

    gradient: Gradient {
        GradientStop { position: 0.2; color: Qt.lighter(Colors.backgroundMain, 1.2) }
        GradientStop { position: 0.8; color: Qt.darker (Colors.backgroundMain, 1.2) }
    }

    Item { id: _dateTimeItem
        width   : Variables.headerBarDateTimeWidth
        anchors {
            top     : parent.top
            left    : parent.left
            bottom  : parent.bottom
            margins : 10
        }
        Column { id: _dateTimeColumn
            anchors.fill: parent
            Text { id: _timeText
                color   : Colors.textMain
                width   : parent.width
                height  : parent.height * 3/5
                horizontalAlignment : Text.AlignHCenter
                verticalAlignment   : Text.AlignVCenter
                text    : vDateTime.time
                font.pixelSize: 40
            }
            Text { id: _dateText
                color   : Colors.textMain
                width   : parent.width
                height  : parent.height * 2/5
                horizontalAlignment : Text.AlignHCenter
                verticalAlignment   : Text.AlignVCenter
                text    : vDateTime.date
                font.pixelSize: 25
            }
        }
    }

    Text { id: _version     // TEST : Application version should be moved into the information screen later.
        color   : Colors.textMain
        anchors {
            top         : parent.top
            left        : parent.left
        }
        horizontalAlignment : Text.AlignHCenter
        verticalAlignment   : Text.AlignBottom

        height  : 15
        width   : _root.width / 4
        text    : Qt.application.version //DEBUG: + "[" + _GuiView.platform + "]"
        font.pixelSize: 14
    }

    Text { id: _ipAddress   // TEST : Wireless IP
        color   : Colors.textMain
        anchors {
            top         : parent.top
            left        : _version.right
        }
        horizontalAlignment : Text.Alignleft
        verticalAlignment   : Text.AlignBottom

        height  : 15
        width   : _root.width / 5

        text    : "W: " + vDevice.ipAddress
        font.pixelSize: 15
    }

    Text { id: _timeZone    // TEST : Current timezone
        color   : Colors.textMain
        anchors {
            top         : parent.top
            left        : _ipAddress.right
        }
        horizontalAlignment : Text.Alignleft
        verticalAlignment   : Text.AlignBottom

        height  : 15
        width   : _root.width / 5
        text    : vDateTime.timezone
        font.pixelSize: 14
    }

    MainMenu { id: _headerMenu
        anchors {
            left        : _dateTimeItem.right
            bottom      : parent.bottom
            bottomMargin: hidden || disable ? height * -1 : 0
        }
        height  : parent.height
        width   : parent.width / 3
        hidden          : true
        titlePixelSize  : 32
        backgroundColor : Colors.transparent
        highlightHeight : 15
        isMainTreatment : true

        onHiddenChanged: {
            if (hidden) {
                index = 0
            }
        }
    }

    Row { id: _headerButtonRow
        height      : parent.height
        spacing     : Variables.defaultMargin * 2
        anchors {
            verticalCenter: parent.verticalCenter
            right       : parent.right
            rightMargin :  _headerButtonRow.spacing
        }

        IconButton { id  : _prescriptionButton
            iconSize        : Variables.headerIconDiameter
            iconImageSource : "qrc:/images/iPrescription"
            extraSpace      : _headerButtonRow.spacing

            onPressed: print("Prescription button pressed!")
        }

        IconButton { id  : _wifiButton
            iconSize        : Variables.headerIconDiameter
            iconImageSource : "qrc:/images/iWifi"
            extraSpace      : _headerButtonRow.spacing

            onPressed: print("Wifi button pressed!")
        }

        IconButton { id  : _bluetoothButton
            iconSize        : Variables.headerIconDiameter
            iconImageSource : "qrc:/images/iBluetooth"
            extraSpace      : _headerButtonRow.spacing

            onPressed: print("Bluetooth button pressed!")
        }

        IconButton { id  : _cloudSyncButton
            iconSize        : Variables.headerIconDiameter
            iconImageSource : "qrc:/images/iCloudSync"
            extraSpace      : _headerButtonRow.spacing

            onPressed: print("CloudSync button pressed!")
        }

        IconButton { id  : _storageButton
            iconSize        : Variables.headerIconDiameter
            iconImageSource : "qrc:/images/iStorage"
            extraSpace      : _headerButtonRow.spacing

            onPressed: print("Storage button pressed!")
        }

        IconButton { id  : _settingsButton
            iconSize        : Variables.headerIconDiameter
            iconImageSource : "qrc:/images/iSettings"
            extraSpace      : _headerButtonRow.spacing

            onPressed: print("Settings button pressed!")
        }

        IconButton { id  : _informationButton
            iconSize        : Variables.headerIconDiameter
            iconImageSource : "qrc:/images/iInformation"
            extraSpace      : _headerButtonRow.spacing

            onPressed: print("Information button pressed!")
        }
    }
}
