@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/simeonoff" target="_blank">Simeon Simeonoff</a>
/// @author <a href="https://github.com/desig9stein" target="_blank">Marin Popov</a>
////

/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
/// @param {Color} $background [null] - The navbar background color.
/// @param {Color} $text-color [null] - The navbar text color.
/// @param {Color} $border-color [null] - The navbar border color.
/// @param {box-shadow} $shadow [null] - The shadow of the navbar.
/// @param {Color} $idle-icon-color [null] - The navbar idle icon color.
/// @param {Color} $hover-icon-color [null] - The navbar hover icon color.
/// @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
) {
    $name: 'igx-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: hsl(from (var(--idle-icon-color)) h s calc(l * 1.1));
    }

    @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: hsla(from adaptive-contrast(var(--background)) h s l / 0.3);
        }

        @if not($hover-icon-color) and $background {
            $hover-icon-color: hsla(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,
        (
            name: $name,
            background: $background,
            border-color: $border-color,
            text-color: $text-color,
            idle-icon-color: $idle-icon-color,
            hover-icon-color: $hover-icon-color,
            shadow: $shadow,
        )
    );
}
