@use "sass:map";
@import '../theme/utilities/function';
@import '../theme/light-theme/light-theme.scss';
@import '../theme/dark-theme/dark-theme.scss';
@import './components-theme/_menu.scss';
@import './components-theme/_layout.scss';
@import './components-theme/_button.scss';
@import './components-theme/user';
@import './components-theme/action';
@import './components-theme/context-menu';
@import './components-theme/card';
@import './components-theme/radio';
@import './components-theme/checkbox';
@import './components-theme/input';
@import './components-theme/tooltip';
@import './components-theme/switch';
@import './components-theme/date-picker';
@import './components-theme/spinner';
@import './components-theme/tabset';
@import './components-theme/stepper';
@import './components-theme/badge';
@import './components-theme/table';
@import './components-theme/pagination';
@import './components-theme/affix';
@import './components-theme/time-picker';

/// Set a theme.
///
/// @author Federico Gambardella<fedega86@libero.it>
/// @param {string} $theme-name
///   The name of theme.
/// @param {map} $theme-map
///   The theme map.

@mixin themable($theme-name, $theme-map) {
    .#{$theme-name} {
        @each $section, $map in $theme-map {
            @include component-layout( $section, $map);
            @include component-menu ($section, $map);
            @include component-button($section, $map);
            @include component-user($section, $map);
            @include component-action($section, $map);
            @include component-context-menu($section, $map);
            @include component-card($section, $map);
            @include component-radio($section, $map);
            @include component-checkbox($section, $map);
            @include component-input($section, $map);
            @include component-tooltip($section, $map);
            @include component-switch($section,$map);
            @include component-date-picker($section, $map);
            @include component-spinner($section, $map);
            @include component-tabset($section, $map);
            @include component-stepper($section, $map);
            @include component-badge($section, $map);
            @include component-table($section, $map);
            @include component-pagination($section, $map);
            @include component-affix($section, $map);
            @include component-time-picker($section, $map);
            @content($section, $map);
        }   
        
    }
 }

 ///Themes map
 $themes-map: (
    light: (
        name: 'light-theme',
        map: $light-theme
    ),
    dark: (
        name: 'dark-theme',
        map: $dark-theme
    )
);

///Set themes present in themes map.
///
/// @author Federico Gambardella<fedega86@libero.it>
@mixin setThemes() {
    @each $section, $map in $themes-map {
       @include themable(map-get($map, name), map-get($map, map)) using($section, $map) {
        @content($section, $map);
       }
    }
}

///Register theme.
///
/// @author Federico Gambardella<fedega86@libero.it>
/// @param {map} $theme-maps
@mixin registerTheme($theme-maps) {
    $themes-map: map-merge($themes-map, $theme-maps)!global;
}

///Write css class properties.
///
///@author Federico Gambardella<fedega86@libero.it>
/// @param {map} $map
@mixin writeClassProperty($map) {
    @each $key, $submap in $map {
        #{$key}: $submap;
     }
}

/// Register theme by parent.
///
/// @author Federico Gambardella<fedega86@libero.it>
/// @param $theme 
/// @param $parent-theme-name
/// @param $theme-name
@mixin registerThemeByParent($theme, $parent-theme-name, $theme-name) {
    $parent-theme-map: retriveThemebyName($parent-theme-name);
    @each $key, $submap in $parent-theme-map {
        @each $key2, $submap2 in $theme {
          @if($key == $key2) {
            $parent-theme-map: map-remove($parent-theme-map, $key);
          }
        }
     }
    $theme: map-merge($theme, $parent-theme-map );
    $map:(
        $theme-name :(
          'name': $theme-name,
          'map': $theme
        )
    );
    @include registerTheme($map);
}


///Extend an exsisting theme
///
/// @author Federico Gambardella<fedega86@libero.it>
/// @param $theme-name
/// @param $map
@mixin extendTheme($theme-name, $map) {
    $theme-map: retriveThemebyName($theme-name);
    $theme-map: map-merge($theme-map, $map);
    @each $key, $submap in $themes-map {
        @if ($key == $theme-name) {
            $themes-map: map-remove($themes-map, $key)!global;
            $map: (
                $theme-name: (
                    "name": $theme-name,
                    "map": $theme-map,
                ),
            );
            $themes-map: map-merge($themes-map, $map )!global;
        }
    }
}




