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

/// Navbar Theme
///
/// PRIMARY TOKENS:
/// - `$background` — The navbar background color.
///
/// Setting just `$background` will create a complete navbar theme with proper contrast.
///
/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
/// @param {Color} $background [null] - The navbar background color. PRIMARY - derives text-color and icon colors.
/// @param {Color} $text-color [null] - The navbar text color. Auto-derived from background.
/// @param {Color} $border-color [null] - The navbar border color. Auto-derived from background (indigo).
/// @param {List} $shadow [null] - The shadow of the navbar.
/// @param {Color} $idle-icon-color [null] - The navbar idle icon color. Auto-derived from background.
/// @param {Color} $hover-icon-color [null] - The navbar hover icon color. Auto-derived from idle-icon-color or background.
/// @param {Bool} $disable-shadow [true] - Sets the navbar shadow visibility.
/// @requires $light-material-schema
/// @example scss - Change the background color
///   $my-navbar-theme: navbar-theme($background: green);
///   // Pass the theme to the css-vars() mixin
///   @include css-vars($my-navbar-theme);
@function navbar-theme(
    $schema: $light-material-schema,
    $background: null,
    $border-color: null,
    $text-color: null,
    $shadow: null,
    $idle-icon-color: null,
    $hover-icon-color: null,
    $disable-shadow: false
) {
    $selector: #{config.element-prefix() + '-' + 'navbar'};
    $navbar-schema: ();

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

    $theme: digest-schema($navbar-schema);
    $variant: map.get($theme, '_meta', 'theme');

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

    @if not($hover-icon-color) and $idle-icon-color {
        $hover-icon-color: dynamic-shade(var(--idle-icon-color));
    }

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

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

        @if not($hover-icon-color) and $background {
            $hover-icon-color: hsl(from adaptive-contrast(var(--background)) h s l / 0.7);
        }
    } @else {
        @if not($hover-icon-color) and $background {
            $hover-icon-color: adaptive-contrast(var(--background));
        }
    }

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

    @if $disable-shadow {
        $shadow: none;
    }

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