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

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

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

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

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

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

    @return extend(
        $theme,
        (
            selector: $selector,
            resting-background: $resting-background,
            resting-color: $resting-color,
            active-background: $active-background,
            active-color: $active-color,
        )
    );
}
