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

/// Bottom Navigation Theme
///
/// PRIMARY TOKENS:
/// - `$background` — The bar background color.
/// - `$label-color` or `$icon-color` - Idle state colors. Either one derives the other, plus disabled colors.
/// - `$label-selected-color` or `$icon-selected-color` - Selected state colors. Either one derives the other.
///
/// 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 bar. PRIMARY - derives label-color, icon-color.
/// @param {Color} $label-color [null] - The label color used in idle state. Auto-derived from background. Derives icon-color if not set.
/// @param {Color} $icon-color [null] - The icon color used in idle state. Auto-derived from label-color if not set.
/// @param {Color} $label-selected-color [null] - The label color used in selected state. Derives icon-selected-color if not set.
/// @param {Color} $icon-selected-color [null] - The icon color used in selected state. Auto-derived from label-selected-color if not set.
/// @param {Color} $icon-disabled-color [null] - The disabled color of the icon. Auto-derived from label-disabled-color if not set.
/// @param {Color} $label-disabled-color [null] - The disabled color of the label. Auto-derived from label-color.
/// @param {Color} $border-color [null] - The border color of the bottom navigation.
/// @param {List | Number} $shadow [null] - Sets a shadow to be used for the bar.
/// @requires $light-material-schema
/// @example scss - Set a custom background color
///   $my-bottom-nav-theme: bottom-nav-theme($background: black);
///   // Pass the theme to the css-vars() mixin
///   @include css-vars($my-bottom-nav-theme);
@function bottom-nav-theme(
    $schema: $light-material-schema,
    $background: null,
    $icon-color: null,
    $icon-selected-color: null,
    $label-color: null,
    $label-selected-color: null,
    $icon-disabled-color: null,
    $label-disabled-color: null,
    $border-color: null,
    $shadow: null
) {
    $selector: #{config.element-prefix() + '-' + 'bottom-nav'};
    $bottom-nav-schema: ();

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

    $theme: digest-schema($bottom-nav-schema);

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

    @if not($icon-color) and $label-color {
        $icon-color: $label-color;
    }

    @if not($label-color) and $icon-color {
        $label-color: $icon-color;
    }

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

    @if not($icon-disabled-color) and $label-disabled-color {
        $icon-disabled-color: $label-disabled-color;
    }

    @if not($label-disabled-color) and $icon-disabled-color {
        $label-disabled-color: $icon-disabled-color;
    }

    @if not($icon-selected-color) and $label-selected-color {
        $icon-selected-color: $label-selected-color;
    }

    @if not($label-selected-color) and $icon-selected-color {
        $label-selected-color: $icon-selected-color;
    }

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

    @return extend(
        $theme,
        (
            selector: $selector,
            background: $background,
            icon-color: $icon-color,
            icon-selected-color: $icon-selected-color,
            label-color: $label-color,
            label-selected-color: $label-selected-color,
            icon-disabled-color: $icon-disabled-color,
            label-disabled-color: $label-disabled-color,
            border-color: $border-color,
            elevation: $shadow,
        )
    );
}
