@use 'sass:map';
@use '../../config';
@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';

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

/// Icon Button Theme
///
/// PRIMARY TOKENS:
/// - `$background` — Background color for the icon button.
/// - `$hover-background` — Background color on hover.
/// - `$focus-background` — Background color on focus.
/// - `$focus-hover-background` — Background color on focus + hover.
///
/// Derived colors are auto-calculated for contrast.
///
/// Generates a theme map for the icon button component.
/// @deprecated Use flat-icon-button-theme(), contained-icon-button-theme(), or outlined-icon-button-theme() instead.
/// @param {Map} $schema [$light-material-schema] - The schema map or icon-button schema to use.
/// @param {Color} $background [null] - Background color for the icon button. PRIMARY - derives foreground.
/// @param {Color} $foreground [null] - Foreground (icon) color. Auto-derived from background.
/// @param {Color} $shadow-color [null] - Shadow color for the icon button.
/// @param {Color} $hover-background [null] - Background color on hover. PRIMARY - derives hover-foreground.
/// @param {Color} $hover-foreground [null] - Foreground color on hover. Auto-derived from hover-background.
/// @param {Color} $focus-background [null] - Background color on focus. PRIMARY - derives focus-foreground.
/// @param {Color} $focus-foreground [null] - Foreground color on focus. Auto-derived from focus-background.
/// @param {Color} $focus-hover-background [null] - Background color on focus + hover. PRIMARY - derives focus-hover-foreground.
/// @param {Color} $focus-hover-foreground [null] - Foreground color on focus + hover. Auto-derived from focus-hover-background.
/// @param {Color} $active-background [null] - Background color when active.
/// @param {Color} $active-foreground [null] - Foreground color when active.
/// @param {Length} $border-radius [null] - Border radius for the icon button.
/// @param {Color} $border-color [null] - Border color.
/// @param {Color} $focus-border-color [null] - Border color on focus.
/// @param {Color} $disabled-background [null] - Background color when disabled.
/// @param {Color} $disabled-foreground [null] - Foreground color when disabled.
/// @param {Color} $disabled-border-color [null] - Border color when disabled.
/// @param {Length} $size [null] - Size of the icon button.
/// @requires $light-material-schema
/// @return {Map} A map containing the theme name, variant, and themes for the icon button.
/// @see {function} flat-icon-button-theme
/// @see {function} contained-icon-button-theme
/// @see {function} outlined-icon-button-theme
@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
) {
    @warn 'icon-button-theme() is deprecated. Use the variant-specific theme functions instead: flat-icon-button-theme(), contained-icon-button-theme(), outlined-icon-button-theme().';

    $selector: #{config.element-prefix() + '-' + '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),
                        (
                            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 (selector: $selector, variant: $variant, themes: $themes);
}
