@use 'sass:map';
@use '../../base' as *;
@use '../../themes/schemas' 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>
////

/// Returns a map containing all style properties related to the theming the tooltip directive.
/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
///
/// @param {Color} $background [null] - The background color of the tooltip.
/// @param {Color} $text-color [null] - The text color of the tooltip.
///
/// @param {List} $border-radius [null] - The border radius used for the tooltip component.
/// @param {box-shadow} $shadow [null] - Sets a shadow to be used for the tooltip component.
///
/// @requires $light-material-schema
///
/// @example scss Change the tooltip background
///   $my-tooltip-theme: tooltip-theme($background: magenta);
///   // Pass the theme to the css-vars() mixin
///   @include css-vars($my-tooltip-theme);
@function tooltip-theme(
    $schema: $light-material-schema,

    $border-radius: null,
    $shadow: null,
    $background: null,
    $text-color: null
) {
    $name: 'igx-tooltip';
    $selector: '.igx-tooltip';
    $tooltip-schema: ();

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

    $theme: digest-schema($tooltip-schema);
    $meta: map.get($theme, '_meta');

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

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

    @return extend($theme, (
        name: $name,
        selector: $selector,
        background: $background,
        text-color: $text-color,
        border-radius: $border-radius,
        shadow: $shadow,
        theme: map.get($schema, '_meta', 'theme'),
        _meta: map.merge(if($meta, $meta, ()), (
            variant: map.get($schema, '_meta', 'theme')
        )),
    ));
}

/// @deprecated Use the `css-vars` mixin instead.
/// @see {mixin} css-vars
/// @param {Map} $theme - The theme used to style the component.
@mixin tooltip($theme) {
    @include css-vars($theme);
    $variant: map.get($theme, '_meta', 'variant');

    %tooltip-display {
        display: inline-flex;
        justify-content: center;
        flex-flow: column wrap;
        background: var-get($theme, 'background');
        color: var-get($theme, 'text-color');
        border-radius: var-get($theme, 'border-radius');
        box-shadow: map.get($theme, 'shadow');
        margin: 0 auto;
        padding: 0 rem(8px);
        min-height: rem(24px);

        @if $variant == 'indigo' {
            padding: rem(4px) rem(8px);
        }
    }

    %tooltip--hidden {
        display: none;
    }
}

/// Adds typography styles for the igx-tooltip component.
/// Uses custom typography.
/// @group typography
/// @param {Map} $categories [(tooltip-text: null] - The categories from the typographic scale used for type styles.
@mixin tooltip-typography(
    $categories: (tooltip-text: null)
) {
    $tooltip-text: map.get($categories, 'tooltip-text');

    @if $tooltip-text {
        %tooltip-display {
            @include type-style($tooltip-text);
        }
    } @else {
        %tooltip-display {
            font-size: rem(10px);
            font-weight: 600;
        }
    }
}
