//
// Copyright 2021 Google Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

@use 'sass:map';
@use '../elevation/elevation-theme';
@use '../tab/tab-theme';
@use '../theme/keys';
@use '../theme/map-ext';
@use '../tab-indicator/tab-indicator-theme';
@use '../theme/theme';
@use '../theme/theme-color';
@use '../typography/typography';

// stylelint-disable selector-class-pattern --
// Selector '.mdc-*' should only be used in this project.

$custom-property-prefix: 'tab-bar';

// TODO: `divider-color` and `divider-height` are not supported by tabs.
$primary-navigation-tabs-light-theme: (
  active-focus-state-layer-color: theme-color.$primary,
  active-focus-state-layer-opacity: 0.12,
  active-hover-state-layer-color: theme-color.$primary,
  active-hover-state-layer-opacity: 0.04,
  active-indicator-color: theme-color.$primary,
  active-indicator-height: 3px,
  active-indicator-shape: (
    3px,
    3px,
    0,
    0,
  ),
  active-pressed-state-layer-color: theme-color.$primary,
  active-pressed-state-layer-opacity: 0.1,
  container-color: theme-color.$surface,
  container-elevation: elevation-theme.get-elevation(0),
  container-height: 48px,
  container-shape: 0,
  divider-color: null,
  divider-height: 1px,
  inactive-focus-state-layer-color: theme-color.$on-surface,
  inactive-focus-state-layer-opacity: 0.12,
  inactive-hover-state-layer-color: theme-color.$on-surface,
  inactive-hover-state-layer-opacity: 0.04,
  inactive-pressed-state-layer-color: theme-color.$on-surface,
  inactive-pressed-state-layer-opacity: 0.1,
  with-icon-active-focus-icon-color: theme-color.$primary,
  with-icon-active-hover-icon-color: theme-color.$primary,
  with-icon-active-icon-color: theme-color.$primary,
  with-icon-active-pressed-icon-color: theme-color.$primary,
  with-icon-and-label-text-container-height: 64px,
  with-icon-icon-size: 24px,
  with-icon-inactive-focus-icon-color: theme-color.$on-surface,
  with-icon-inactive-hover-icon-color: theme-color.$on-surface,
  with-icon-inactive-icon-color: theme-color.$on-surface,
  with-icon-inactive-pressed-icon-color: theme-color.$on-surface,
  with-label-text-active-focus-label-text-color: theme-color.$primary,
  with-label-text-active-hover-label-text-color: theme-color.$primary,
  with-label-text-active-label-text-color: theme-color.$primary,
  with-label-text-active-pressed-label-text-color: theme-color.$primary,
  with-label-text-inactive-focus-label-text-color: theme-color.$on-surface,
  with-label-text-inactive-hover-label-text-color: theme-color.$on-surface,
  with-label-text-inactive-label-text-color: theme-color.$on-surface,
  with-label-text-inactive-pressed-label-text-color: theme-color.$on-surface,
  with-label-text-label-text-font-family: typography.get-font(subhead2),
  with-label-text-label-text-font-size: typography.get-size(subhead2),
  with-label-text-label-text-letter-spacing: typography.get-tracking(subhead2),
  with-label-text-label-text-line-height: typography.get-line-height(subhead2),
  with-label-text-label-text-weight: typography.get-weight(subhead2),
);

// TODO: `divider-color` and `divider-height` are not supported by tabs.
$secondary-navigation-tab-light-theme: (
  active-indicator-color: null,
  active-indicator-height: null,
  active-label-text-color: null,
  container-color: null,
  container-elevation: null,
  container-height: null,
  container-shadow-color: null,
  container-shape: null,
  divider-color: null,
  divider-height: null,
  focus-label-text-color: null,
  focus-state-layer-color: null,
  focus-state-layer-opacity: null,
  hover-label-text-color: null,
  hover-state-layer-color: null,
  hover-state-layer-opacity: null,
  inactive-label-text-color: null,
  label-text-font-family: null,
  label-text-font-size: null,
  label-text-letter-spacing: null,
  label-text-line-height: null,
  label-text-weight: null,
  pressed-label-text-color: null,
  pressed-state-layer-color: null,
  pressed-state-layer-opacity: null,
);

@mixin primary-navigation-tab-theme($theme) {
  @include theme.validate-theme($primary-navigation-tabs-light-theme, $theme);
  @include keys.declare-custom-properties(
    $theme,
    $prefix: $custom-property-prefix
  );
}

@mixin secondary-navigation-tab-theme($theme) {
  @include theme.validate-theme($secondary-navigation-tab-light-theme, $theme);
  @include keys.declare-custom-properties(
    $theme,
    $prefix: $custom-property-prefix
  );
}

@mixin primary-navigation-tab-theme-styles($theme) {
  .mdc-tab {
    @include tab-theme.primary-navigation-tab-theme-styles(
      map-ext.pick($theme, map.keys(tab-theme.$primary-light-theme)...)
    );
  }

  .mdc-tab-indicator {
    @include tab-indicator-theme.theme-styles(
      map-ext.pick($theme, map.keys(tab-indicator-theme.$light-theme)...)
    );
  }
}

@mixin secondary-navigation-tab-theme-styles($theme) {
  .mdc-tab {
    @include tab-theme.secondary-navigation-tab-theme-styles(
      map-ext.pick($theme, map.keys(tab-theme.$secondary-light-theme)...)
    );
  }

  .mdc-tab-indicator {
    @include tab-indicator-theme.theme-styles(
      map-ext.pick($theme, map.keys(tab-indicator-theme.$light-theme)...)
    );
  }
}
