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

/// Tooltip Theme
///
/// PRIMARY TOKENS:
/// - `$background` — The 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 of the tooltip. PRIMARY - derives text-color.
/// @param {Color} $text-color [null] - The text color of the tooltip. Auto-derived from background.
/// @param {List} $border-radius [null] - The border radius used for the tooltip component.
/// @param {List} $shadow [null] - Sets a shadow to be used for the tooltip component.
/// @requires $light-material-schema
/// @example scss - Change the tooltip background
///   $my-tooltip-theme: tooltip-theme($background: magenta);
///   // Pass the theme to the css-vars() mixin
///   @include css-vars($my-tooltip-theme);
@function tooltip-theme(
    $schema: $light-material-schema,

    $border-radius: null,
    $shadow: null,
    $background: null,
    $text-color: null
) {
    $selector: (#{config.element-prefix() + '-' + 'tooltip'}, #{'.' + config.element-prefix() + '-' + 'tooltip'});
    $tooltip-schema: ();

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

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

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

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

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