////
/// @group themes
/// @author <a href="https://github.com/simeonoff" target="_blank">Simeon Simeonoff</a>
////

// Import the core module first
@import 'core';

// Import all component mixins
@import '../components/avatar/avatar-theme';
@import '../components/badge/badge-theme';
@import '../components/bottom-nav/bottom-nav-theme';
@import '../components/button/button-theme';
@import '../components/button-group/button-group-theme';
@import '../components/banner/banner-theme';
@import '../components/calendar/calendar-theme';
@import '../components/card/card-theme';
@import '../components/carousel/carousel-theme';
@import '../components/checkbox/checkbox-theme';
@import '../components/chip/chip-theme';
@import '../components/column-hiding/column-hiding-theme';
@import '../components/combo/combo-theme';
@import '../components/date-picker/date-picker-theme';
@import '../components/dialog/dialog-theme';
@import '../components/divider/divider-theme';
@import '../components/drop-down/drop-down-theme';
@import '../components/expansion-panel/expansion-panel-theme';
@import '../components/grid/grid-theme';
@import '../components/grid-summary/grid-summary-theme';
@import '../components/paginator/paginator-theme';
@import '../components/grid-toolbar/grid-toolbar-theme';
@import '../components/highlight/highlight-theme';
@import '../components/overlay/overlay-theme';
@import '../components/toast/toast-theme';
@import '../components/tooltip/tooltip-theme';
@import '../components/tabs/tabs-theme';
@import '../components/switch/switch-theme';
@import '../components/snackbar/snackbar-theme';
@import '../components/slider/slider-theme';
@import '../components/ripple/ripple-theme';
@import '../components/radio/radio-theme';
@import '../components/progress/progress-theme';
@import '../components/navbar/navbar-theme';
@import '../components/navdrawer/navdrawer-theme';
@import '../components/list/list-theme';
@import '../components/input/input-group-theme';
@import '../components/icon/icon-theme';
@import '../components/time-picker/time-picker-theme';

/// Generates an Ignite UI for Angular global theme.
/// @param {Map} $palette - An igx-palette to be used by the global theme.
/// @param {Map} $schema [$light-schema] - The schema used as basis for styling the components.
/// @param {List} $exclude [( )] - A list of igx components to be excluded from the global theme styles.
/// @param {Boolean} $legacy-support - Turn off support for IE11, allowing you to use css variables to style components.
/// @param {Boolean} $elevation [true] - Turns on/off elevations for all components in the theme.
/// @param {Number} $roundness [null] - Sets the global roundness factor (the value can be any decimal fraction between 0 and 1) for all components.
/// @requires {variable} $components
/// @requires {variable} $default-palette
/// @requires {function} is-component
/// @requires {mixin} igx-avatar
/// @requires {mixin} igx-badge
/// @requires {mixin} igx-button
/// @requires {mixin} igx-button-group
/// @requires {mixin} igx-calendar
/// @requires {mixin} igx-card
/// @requires {mixin} igx-carousel
/// @requires {mixin} igx-checkbox
/// @requires {mixin} igx-date-picker
/// @requires {mixin} igx-dialog
/// @requires {mixin} igx-drop-down
/// @requires {mixin} igx-expansion-panel
/// @requires {mixin} igx-grid
/// @requires {mixin} igx-grid-summary
/// @requires {mixin} igx-paginator
/// @requires {mixin} igx-icon
/// @requires {mixin} igx-input-group
/// @requires {mixin} igx-list
/// @requires {mixin} igx-navbar
/// @requires {mixin} igx-navdrawer
/// @requires {mixin} igx-progress-linear
/// @requires {mixin} igx-progress-circular
/// @requires {mixin} igx-radio
/// @requires {mixin} igx-ripple
/// @requires {mixin} igx-slider
/// @requires {mixin} igx-snackbar
/// @requires {mixin} igx-switch
/// @requires {mixin} igx-tabs
/// @requires {mixin} igx-bottom-nav
/// @requires {mixin} igx-toast
@mixin igx-theme(
    $palette,
    $schema: $light-schema,
    $exclude: (),
    $legacy-support: true,
    $roundness: null,
    $elevation: true,
) {
    // Stores all excluded component styles
    $excluded: ();

    $default-palette: $palette !global;
    $igx-legacy-support: $legacy-support !global;

    @if length($exclude) > 0 {
        $excluded: is-component($exclude);
    }

    @if length($excluded) > 0 {
        @warn unquote('You have excluded the following components from the theme: "#{$excluded}". You can now add your own themes for the excluded components.');
    }

    @if not(index($exclude, 'igx-ripple')) {
        @include igx-ripple(igx-ripple-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-avatar')) {
        @include igx-avatar(igx-avatar-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-badge')) {
        @include igx-badge(igx-badge-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-bottom-nav')) {
        @include igx-bottom-nav(igx-bottom-nav-theme(
            $palette,
            $schema,
            $shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-button')) {
        @include igx-button(igx-button-theme(
            $palette,
            $schema,
            $flat-border-radius: $roundness,
            $raised-border-radius: $roundness,
            $outlined-border-radius: $roundness,
            $fab-border-radius: $roundness,
            $icon-border-radius: $roundness,
            $raised-resting-shadow: if($elevation == false, 0, null),
            $raised-hover-shadow: if($elevation == false, 0, null),
            $raised-focus-shadow: if($elevation == false, 0, null),
            $fab-resting-shadow: if($elevation == false, 0, null),
            $fab-hover-shadow: if($elevation == false, 0, null),
            $fab-focus-shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-button-group')) {
        @include igx-button-group(igx-button-group-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-banner')) {
        @include igx-banner(igx-banner-theme(
            $palette,
            $schema,
        ));
    }

    @if not(index($exclude, 'igx-calendar')) {
        @include igx-calendar(igx-calendar-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $date-border-radius: $roundness,
            $month-border-radius: $roundness,
        ));
    }

    @if not(index($exclude, 'igx-card')) {
        @include igx-card(igx-card-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $resting-shadow: if($elevation == false, 0, null),
            $hover-shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-carousel')) {
        @include igx-carousel(igx-carousel-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $button-shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-checkbox')) {
        @include igx-checkbox(igx-checkbox-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $border-radius-ripple: $roundness,
        ));
    }

    @if not(index($exclude, 'igx-chip')) {
        @include igx-chip(igx-chip-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $ghost-shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-column-hiding')) {
        @include igx-column-hiding(igx-column-hiding-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-combo')) {
        @include igx-combo(igx-combo-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-date-picker')) {
        @include igx-date-picker(igx-calendar-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
        ));
    }

    @if not(index($exclude, 'igx-dialog')) {
        @include igx-dialog(igx-dialog-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-divider')) {
        @include igx-divider(igx-divider-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-drop-down')) {
        @include igx-drop-down(igx-drop-down-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-expansion-panel')) {
        @include igx-expansion-panel(igx-expansion-panel-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
        ));
    }

    @if not(index($exclude, 'igx-grid')) {
        @include igx-grid(igx-grid-theme(
            $palette,
            $schema,
            $drop-area-border-radius: $roundness,
            $grid-shadow: if($elevation == false, 0, null),
            $drag-shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-grid-summary')) {
        @include igx-grid-summary(igx-grid-summary-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-grid-toolbar')) {
        @include igx-grid-toolbar(igx-grid-toolbar-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-highlight')) {
        @include igx-highlight(igx-highlight-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-icon')) {
        @include igx-icon(igx-icon-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-input-group')) {
        @include igx-input-group(igx-input-group-theme(
            $palette,
            $schema,
            $box-border-radius: $roundness,
            $border-border-radius: $roundness,
            $search-border-radius: $roundness,
            $search-resting-shadow: if($elevation == false, 0, null),
            $search-hover-shadow: if($elevation == false, 0, null),
            $search-disabled-shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-list')) {
        @include igx-list(igx-list-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $item-border-radius: $roundness,
        ));
    }

    @if not(index($exclude, 'igx-navbar')) {
        @include igx-navbar(igx-navbar-theme(
            $palette,
            $schema,
            $shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-nav-drawer')) {
        @include igx-navdrawer(igx-navdrawer-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $item-border-radius: $roundness,
            $shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-overlay')) {
        @include igx-overlay(igx-overlay-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-paginator')) {
        @include igx-paginator(igx-paginator-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-circular-bar')) {
        @include igx-progress-circular(igx-progress-circular-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-linear-bar')) {
        @include igx-progress-linear(igx-progress-linear-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-radio')) {
        @include igx-radio(igx-radio-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-slider')) {
        @include igx-slider(igx-slider-theme($palette, $schema));
    }

    @if not(index($exclude, 'igx-snackbar')) {
        @include igx-snackbar(igx-snackbar-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-switch')) {
        @include igx-switch(igx-switch-theme(
            $palette,
            $schema,
            $border-radius-track: $roundness,
            $border-radius-thumb: $roundness,
            $border-radius-ripple: $roundness,
            $resting-shadow: if($elevation == false, 0, null),
            $hover-shadow: if($elevation == false, 0, null),
            $disabled-shadow: if($elevation == false, 0, null),
        ));
    }

    @if not(index($exclude, 'igx-tabs')) {
        @include igx-tabs(igx-tabs-theme(
            $palette,
            $schema,
            $disable-shadow: if($elevation == false, true, false),
        ));
    }

    @if not(index($exclude, 'igx-toast')) {
        @include igx-toast(igx-toast-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
        ));
    }

    @if not(index($exclude, 'igx-tooltip')) {
        @include igx-tooltip(igx-tooltip-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
        ));
    }

    @if not(index($exclude, 'igx-time-picker')) {
        @include igx-time-picker(igx-time-picker-theme(
            $palette,
            $schema,
            $border-radius: $roundness,
            $active-item-border-radius: $roundness,
            $modal-shadow: if($elevation == false, 0, null),
            $dropdown-shadow: if($elevation == false, 0, null),
        ));
    }
}

/// Creates a global theme that can be used with light backgrounds.
/// @param {Map} $palette - An igx-palette to be used by the global theme.
/// @param {List} $exclude [( )] - A list of igx components to be excluded from the global theme styles.
/// @param {Boolean} $legacy-support - Turn off support for IE11, allowing you to use css variables to style components.
@mixin igx-light-theme(
    $palette,
    $exclude: (),
    $legacy-support: true,
    $roundness: null,
    $elevation: true,
) {
    $grays: igx-color($palette, 'grays');
    $surface: igx-color($palette, 'surface');

    $light-palette: igx-palette(
        $primary: igx-color($palette, 'primary'),
        $secondary: igx-color($palette, 'secondary'),
        $info: igx-color($palette, 'info'),
        $success: igx-color($palette, 'success'),
        $warn: igx-color($palette, 'warn'),
        $error: igx-color($palette, 'error'),
        $surface: if($surface != #fff, $surface, #fff),
        $grays: if($grays != rgba(0, 0, 0, .38), $grays, #000),
    );

    @include igx-theme(
        $palette: $light-palette,
        $schema: $light-schema,
        $legacy-support: $legacy-support,
        $exclude: $exclude,
        $roundness: $roundness,
        $elevation: $elevation,
    );
}

/// Creates a global theme that can be used with dark backgrounds.
/// @param {Map} $palette - An igx-palette to be used by the global theme.
/// @param {List} $exclude [( )] - A list of igx components to be excluded from the global theme styles.
/// @param {Boolean} $legacy-support - Turn off support for IE11, allowing you to use css variables to style components.
@mixin igx-dark-theme(
    $palette,
    $exclude: (),
    $legacy-support: true,
    $roundness: null,
    $elevation: true,
) {
    $grays: igx-color($palette, 'grays');
    $surface: igx-color($palette, 'surface');

    $dark-palette: igx-palette(
        $primary: igx-color($palette, 'primary'),
        $secondary: igx-color($palette, 'secondary'),
        $info: igx-color($palette, 'info'),
        $success: igx-color($palette, 'success'),
        $warn: igx-color($palette, 'warn'),
        $error: igx-color($palette, 'error'),
        $surface: if($surface != #fff, $surface, #222),
        $grays: if($grays != rgba(0, 0, 0, .38), $grays, #fff),
    );

    @include igx-theme(
        $palette: $dark-palette,
        $schema: $dark-schema,
        $legacy-support: $legacy-support,
        $exclude: $exclude,
        $roundness: $roundness,
        $elevation: $elevation,
    );
}

/// Creates a global fluent theme that can be used with light backgrounds.
/// @param {Map} $palette - An igx-palette to be used by the global theme.
/// @param {List} $exclude [( )] - A list of igx components to be excluded from the global theme styles.
/// @param {Boolean} $legacy-support - Turn off support for IE11, allowing you to use css variables to style components.
@mixin igx-fluent-theme(
    $palette,
    $exclude: (),
    $legacy-support: true,
    $roundness: null,
    $elevation: true,
) {
    $primary: igx-color($palette, 'primary');
    $secondary: igx-color($palette, 'secondary');
    $surface: igx-color($palette, 'surface');

    @include igx-typography(
        $font-family: "'Open Sans', Helvetica, Arial, sans-serif",
        $type-scale: $fluent-type-scale,
        $base-color: #323130
    );

    @include igx-theme(
        $palette: igx-palette(
            $primary,
            $secondary,
            $surface: if($surface != #fff, $surface, #fff),
            $grays: #000
        ),
        $schema: $light-fluent-schema,
        $legacy-support: $legacy-support,
        $exclude: $exclude,
        $roundness: $roundness,
        $elevation: $elevation,
    );
}

/// Creates a global fluent theme that can be used with dark backgrounds.
/// @param {Map} $palette - An igx-palette to be used by the global theme.
/// @param {List} $exclude [( )] - A list of igx components to be excluded from the global theme styles.
/// @param {Boolean} $legacy-support - Turn off support for IE11, allowing you to use css variables to style components.
@mixin igx-fluent-dark-theme(
    $palette,
    $exclude: (),
    $legacy-support: true,
    $roundness: null,
    $elevation: true,
) {
    $primary: igx-color($palette, 'primary');
    $secondary: igx-color($palette, 'secondary');
    $surface: igx-color($palette, 'surface');

    @include igx-typography(
        $font-family: "'Open Sans', Helvetica, Arial, sans-serif",
        $type-scale: $fluent-type-scale,
        $base-color: #fff
    );

    @include igx-theme(
        $palette: igx-palette(
            $primary,
            $secondary,
            $surface: if($surface != #fff, $surface, #222),
            $grays: #fff
        ),
        $schema: $dark-fluent-schema,
        $legacy-support: $legacy-support,
        $exclude: $exclude,
        $roundness: $roundness,
        $elevation: $elevation,
    );
}
