@use 'sass:map';
@use '../../functions' as *;
@use '../../schemas/' as *;
@use '../../../utils/map' as *;
@use '../../../color/functions' as *;
@use '../../../elevations/' as *;

////
/// @group themes
/// @access public
/// @author <a href="https://github.com/desig9stein" target="_blank">Marin Popov</a>
////

/// Expansion panel Theme
/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
/// @param {Color} $header-background [null] - The panel header background color.
/// @param {Color} $header-focus-background [null] - The panel header focus background color.
/// @param {Color} $header-title-color [null] - The panel header title text color.
/// @param {Color} $header-description-color [null] - The panel header description text color.
/// @param {Color} $header-icon-color [null] - The panel header icon color.
/// @param {Color} $body-color [null] - The panel body text color.
/// @param {Color} $body-background [null] - The panel body background color.
/// @param {Color} $disabled-text-color [null] - The panel disabled text color.
/// @param {Color} $disabled-description-color [null] - The panel disabled header description text color.
/// @param {Number} $expanded-margin [null] - The expansion panel margin in expanded state when positioned inside accordion.
/// @param {List} $border-radius [null] - The border radius used for expansion-panel component.
/// @requires $light-material-schema
/// @example scss Change the header background color
///   $my-expansion-panel-theme: expansion-panel-theme($header-background: black);
///   // Pass the theme to the css-vars() mixin
///   @include css-vars($my-expansion-panel-theme);
@function expansion-panel-theme(
    $schema: $light-material-schema,

    $border-radius: null,
    $header-background: null,
    $header-focus-background: null,
    $header-title-color: null,
    $header-description-color: null,
    $header-icon-color: null,
    $body-color: null,
    $body-background: null,
    $disabled-text-color: null,
    $disabled-description-color: null,
    $expanded-margin: null
) {
    $name: 'igx-expansion-panel';
    $expansion-panel-schema: ();

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

    $theme: digest-schema($expansion-panel-schema);

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

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

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

    @if not($header-focus-background) and $header-background {
        $header-focus-background: hsl(from var(--header-background) h s calc(l * 1.1));
    }

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

    @if not($disabled-text-color) and $header-background {
        $disabled-text-color: hsla(from adaptive-contrast(var(--header-background)) h s l / 0.5);
    }

    @if not($disabled-description-color) and $header-background {
        $disabled-description-color: hsla(from adaptive-contrast(var(--header-background)) h s l / 0.5);
    }

    @return extend(
        $theme,
        (
            name: $name,
            header-background: $header-background,
            border-radius: $border-radius,
            header-focus-background: $header-focus-background,
            header-title-color: $header-title-color,
            header-description-color: $header-description-color,
            header-icon-color: $header-icon-color,
            body-color: $body-color,
            body-background: $body-background,
            disabled-text-color: $disabled-text-color,
            disabled-description-color: $disabled-description-color,
            expanded-margin: $expanded-margin,
        )
    );
}
