@use 'sass:map';
@use '../../config';
@use '../../functions' as *;
@use '../../schemas/' as *;
@use '../../../utils/map' as *;
@use '../../../color/functions' as *;
@use '../../../elevations/' as *;

////
/// @package theming
/// @group themes
/// @access public
/// @author <a href="https://github.com/simeonoff" target="_blank">Simeon Simeonoff</a>
/// @author <a href="https://github.com/desig9stein" target="_blank">Marin Popov</a>
////

/// Avatar Theme
///
/// PRIMARY TOKENS:
/// - `$background` — The avatar background color.
///
/// Derived colors are auto-calculated for contrast.
///
/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
/// @param {Color} $background [null] - The background color used of the avatar. PRIMARY - derives color, icon-color.
/// @param {Color} $color [null] - The text color used of the avatar. Auto-derived from background.
/// @param {Color} $icon-color [null] - The icon color used of the avatar. Auto-derived from background.
/// @param {Number} $border-radius [null] - The border-radius used of the avatar.
/// @param {Number} $size [null] - The size of the avatar.
/// @requires {variable} $light-material-schema
///
/// @example scss - Change the background and icon colors in icon avatars
///   $my-avatar-theme: avatar-theme($icon-background: black, $icon-color: white);
///   // Pass the theme to the css-vars() mixin
///   @include css-vars($my-avatar-theme);
@function avatar-theme(
    $schema: $light-material-schema,
    $background: null,
    $color: null,
    $icon-color: null,
    $border-radius: null,
    $size: null
) {
    $selector: #{config.element-prefix() + '-' + 'avatar'};
    $avatar-schema: ();

    @if map.has-key($schema, 'avatar') {
        $avatar-schema: map.get($schema, 'avatar');
    } @else {
        $avatar-schema: $schema;
    }

    $theme: digest-schema($avatar-schema);

    @if not($color) and $background {
        $color: adaptive-contrast(var(--background));
    }

    @if not($icon-color) and $background {
        $icon-color: adaptive-contrast(var(--background));
    }

    @return extend(
        $theme,
        (
            selector: $selector,
            background: $background,
            color: $color,
            icon-color: $icon-color,
            border-radius: $border-radius,
            size: $size,
        )
    );
}
