import QtQuick 2.4
import Ubuntu.Components 1.3
import Ubuntu.Components.ListItems 1.0 as ListItem
import Ubuntu.Components.Popups 1.1
import Dekko.Theme 0.2
import Dekko.Settings 0.2
import "../Utils/Utils.js" as Utils
import "../Contact/imports"
import "../Components"


Item {
    id: avatar
    property string name
    property string initials
    property string email
    property string radius: "small"
    property bool validContact: false
    property string fontSize: "large"
    property int fontWeight: Style.common.fontWeight

    height: units.gu(6)
    width: height
    Component {
        id: component_inner_av
        UbuntuShape {
            id: avatarCircle
            anchors.fill: parent
            anchors.centerIn: parent
            aspect: UbuntuShape.Flat
            radius: avatar.radius
            backgroundColor: Utils.getIconColor(name, Style.avatar.avatarColorList)
            visible: validContact
            //name: "avatar-circle"
            Label {
                id: initialsLabel
                color: "#FFFFFF"
                text: validContact ? initials : ""
                anchors.centerIn: parent
                fontSize: avatar.fontSize
                font.weight: avatar.fontWeight
            }

            Icon {
                id: contactIcon
                name: "contact"
                anchors.centerIn: parent
                height: parent.height - units.gu(2)
                width: height
                color: "white"
                visible: !initialsLabel.text
            }
        }
    }
    Loader {
        id: loader_inner_av
        anchors.fill: parent
        active: !inner_name.visible
        sourceComponent: component_inner_av
    }
    UbuntuShapeGravatar {
        id: inner_name
        radius: avatar.radius
        emailAddress: validContact && GlobalSettings.preferences.gravatarAllowed ? email : ""
        clip: true
        anchors.fill: parent
        visible: status === Image.Ready
    }
}
