@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>
///
/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
///
/// @param {Color} $bar-color [null] - The background color of the bar.
/// @param {Color} $handle-color [null] - The color for the bar drag handle.
/// @param {Color} $expander-color [null] - The color for the arrow expander's.
/// @param {List} $border-radius [null] - the border radios of the splitter bar drag handle
/// @param {Color} $focus-color [null] - The color used for focused splitter bar.
/// @param {Number} $size [null] - The size of the splitter, its width for vertical and height for horizontal splitter.
/// @requires $light-material-schema
/// @example scss Set a custom expander color
///   $my-splitter-theme: splitter-theme($expander-color: red);
///   // Pass the theme to the css-vars() mixin
///   @include css-vars($my-splitter-them);
@function splitter-theme(
    $schema: $light-material-schema,

    $bar-color: null,
    $handle-color: null,
    $expander-color: null,
    $border-radius: null,
    $focus-color: null,
    $size: null
) {
    $name: 'igx-splitter';
    $splitter-schema: ();

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

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

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

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

    @if $variant != 'indigo' {
        @if not($focus-color) and $bar-color {
            $focus-color: hsl(from var(--bar-color) h s calc(l * 0.7));
        }
    } @else {
        @if not($focus-color) and $bar-color {
            $focus-color: var(--bar-color);
        }
    }

    @return extend(
        $theme,
        (
            name: $name,
            bar-color: $bar-color,
            handle-color: $handle-color,
            expander-color: $expander-color,
            border-radius: $border-radius,
            focus-color: $focus-color,
            size: $size,
        )
    );
}
