@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>
////

/// Badge Theme
///
/// PRIMARY TOKENS:
/// - `$background-color` — The badge background color.
///
/// Setting just `$background-color` will create a complete badge theme with proper text/icon contrast.
///
/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
/// @param {Color} $icon-color [null] - The icon color used. Auto-derived from background-color.
/// @param {Color} $text-color [null] - The text color used. Auto-derived from background-color.
/// @param {Color} $border-color [null] - The border color used.
/// @param {Color} $background-color [null] - The background color used. PRIMARY - derives icon-color and text-color.
/// @param {List} $shadow [null] - Sets a shadow to be used for the badge.
/// @param {Number} $border-radius [null] - The border radius used for badge component.
/// @param {Number} $size [null] - The size of the badge component.
/// @param {Number} $dot-size [null] - The size of the dot type badge.
/// @requires $light-material-schema
///
/// @example scss - Change the text and icon colors in a badge
///   $my-badge-theme: badge-theme($icon-color: black, $background-color: white);
///   // Pass the theme to the css-vars() mixin
///   @include css-vars($my-badge-theme);
@function badge-theme(
    $schema: $light-material-schema,

    $icon-color: null,
    $text-color: null,

    $border-color: null,
    $border-radius: null,

    $background-color: null,
    $shadow: null,
    $size: null,
    $dot-size: null
) {
    $selector: #{config.element-prefix() + '-' + 'badge'};
    $badge-schema: ();

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

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

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

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

    @if not($shadow) {
        $elevation: map.get($badge-schema, 'elevation');
        $shadow: elevation($elevation);
    }

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