@use 'sass:map';
@use '../../functions' as *;
@use '../../schemas/' as *;
@use '../../../utils/map' as *;
@use '../../../color/functions' as *;
@use '../../../elevations/' as *;
@forward './flat-icon-button-theme';
@forward './contained-icon-button-theme';
@forward './outlined-icon-button-theme';

////
/// @group themes
/// @access public
/// @author <a href="https://github.com/SisIvanova" target="_blank">Silvia Ivanova</a>
////

@function icon-button-theme(
    $schema: $light-material-schema,

    $background: null,
    $foreground: null,
    $shadow-color: null,

    $hover-background: null,
    $hover-foreground: null,

    $focus-background: null,
    $focus-foreground: null,

    $focus-hover-background: null,
    $focus-hover-foreground: null,

    $active-background: null,
    $active-foreground: null,

    $border-radius: null,
    $border-color: null,
    $focus-border-color: null,

    $disabled-background: null,
    $disabled-foreground: null,
    $disabled-border-color: null,

    $size: null
) {
    $name: 'igx-icon-button';
    $icon-button-schema: ();

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

    $themes: ();
    $variant: null;

    @each $_name, $_schema in $icon-button-schema {
        @if not($variant) {
            $variant: map.get($schema, '_meta', 'theme');
        }

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

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

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

        @if not($focus-hover-foreground) and $focus-hover-background {
            $focus-hover-foreground: adaptive-contrast(var(--focus-hover-background));
        }

        $themes: map.merge(
            $themes,
            (
                $_name:
                    extend(
                        digest-schema($_schema),
                        (
                            name: $name,
                            background: $background,
                            foreground: $foreground,
                            shadow-color: $shadow-color,

                            hover-background: $hover-background,
                            hover-foreground: $hover-foreground,

                            focus-background: $focus-background,
                            focus-foreground: $focus-foreground,

                            focus-hover-background: $focus-hover-background,
                            focus-hover-foreground: $focus-hover-foreground,

                            active-background: $active-background,
                            active-foreground: $active-foreground,

                            border-radius: $border-radius,
                            border-color: $border-color,
                            focus-border-color: $focus-border-color,

                            disabled-background: $disabled-background,
                            disabled-foreground: $disabled-foreground,
                            disabled-border-color: $disabled-border-color,
                            size: $size,
                        )
                    ),
            )
        );
    }

    @return (name: $name, variant: $variant, themes: $themes);
}
