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

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

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

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

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

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

    @if not($border-color) and $text-color {
        $border-color: hsl(from var(--text-color) h s l / 0.3);
    }

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

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