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

/// Dialog Theme
///
/// PRIMARY TOKENS:
/// - `$background` — The dialog background color.
///
/// Setting just `$background` will create a complete dialog theme with proper text contrast.
///
/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
/// @param {Color} $background [null] - The dialog background color. PRIMARY - derives title-color, message-color, border-color.
/// @param {Color} $title-color [null] - The dialog title text color. Auto-derived from background.
/// @param {Color} $message-color [null] - The dialog message text color. Auto-derived from background (slightly transparent).
/// @param {List} $shadow [null] - The shadow used for the dialog.
/// @param {List} $border-radius [null] - The border radius used for dialog component.
/// @param {Color} $border-color [null] - The border color used for dialog component. Auto-derived from background.
/// @requires $light-material-schema
/// @example scss - Change the background color
///   $my-dialog-theme: dialog-theme($background: black);
///   // Pass the theme to the css-vars() mixin
///   @include css-vars($my-dialog-theme);
@function dialog-theme(
    $schema: $light-material-schema,

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

    $background: null,
    $title-color: null,
    $message-color: null,
    $shadow: null
) {
    $selector: (#{config.element-prefix() + '-' + 'dialog'}, '.igx-dialog');
    $dialog-schema: ();

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

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

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

    @if not($message-color) and $background {
        $message-color: hsl(from adaptive-contrast(var(--background)) h s l / 0.8);
    }

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

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

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