/*
 * SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

@import (reference) "./tools.less";
@import (reference) "./colortheme-all.less";
@import (reference) "./variables.less";
@import (reference) "./badges.less";
.avatar_vars(
    @width: 30px
) {
    @avatar-width: @width;
    @avatar-font-size: @width / 1.8;
    // scale animal avatar to be somewhat larger, because:
    // 1. emojis are wider than most latin characters
    // 2. they should occupy the width of two average characters
    @avatar-font-size-animal: @avatar-font-size * (6/5);
}
.avatar_main(@width: 30px) {
    --LessLoader_require: LessLoader_currentFile();
    .avatar_vars(@width);
    --avatar-width: @avatar-width;
    --avatar-font-size: @avatar-font-size;
    @badge-width: min(0.4*@width, 100px);
    --badges-width: @badge-width;
    --badges-offset: ceil(-1*@badge-width/5);
    --badges-font: ceil(@badge-width*2/3);
}
& {
    .avatar_vars();
    &.cp-avatar {
        overflow: visible;
        text-overflow: ellipsis;
        font-size: 16px;
        display: flex;
        align-items: center;
        border-radius: @variables_radius;
        position: relative;
        .cp-avatar-default, media-tag {
            display: inline-flex;

            width: @avatar-width;
            width: var(--avatar-width);

            height: @avatar-width;
            height: var(--avatar-width);
            border-radius: @variables_radius;


            justify-content: center;
            align-items: center;
            overflow: hidden;
            box-sizing: content-box;
        }
        .cp-avatar-default {
            .tools_unselectable();
            background: @cp_avatar-bg;
            color: @cp_avatar-fg;
            font-size: @avatar-font-size;
            font-size: var(--avatar-font-size);
            .animal {
                font-size: @avatar-font-size-animal;
            }
        }
        media-tag {
            min-height: @avatar-width;
            min-height: var(--avatar-width);

            min-width: @avatar-width;
            min-width: var(--avatar-width);

            max-height: @avatar-width;
            max-height: var(--avatar-width);

            max-width: @avatar-width;
            max-width: var(--avatar-width);
            img {
                min-width: 100%;
                min-height: 100%;
                max-width: none;
                max-height: none; // To override 'media-tag img' in slide.less
            }
        }
        .badges_include();
        & > i.cp-badge {
            position: absolute;
            z-index: 10;
            bottom: var(--badges-offset);
            right: var(--badges-offset);
            border: 1px solid @cp_badges-color;
        }
    }
}

