//
// Copyright 2019 Stijn de Witt. Some rights reserved.
// Licensed under the MIT Open Source license. 
// https://opensource.org/licenses/MIT
// See LICENSE for details.
//
// Based on code copyright 2018 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// http://www.apache.org/licenses/LICENSE-2.0
// See LICENSE-MDC for details.
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under these licenses is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the licenses for the specific language governing permissions and
// limitations under these licenses.
// 

@import "../elevation/mixins";
@import "../ripple/mixins";
@import "../rtl/mixins";
@import "../theme/functions";
@import "../theme/mixins";
@import "../typography/mixins";
@import "./variables";

@mixin mdc-button-filled-accessible($container-fill-color) {
  $fill-tone: tone($container-fill-color);

  @include mdc-button-container-fill-color($container-fill-color);

  @if ($fill-tone == "dark") {
    @include mdc-button-ink-color(text-primary-on-dark);
    @include mdc-states(text-primary-on-dark);
  } @else {
    @include mdc-button-ink-color(text-primary-on-light);
    @include mdc-states(text-primary-on-light);
  }
}

@mixin mdc-button-container-fill-color($color) {
  // :not(:disabled) is used to support link styled as button
  // as link does not support :enabled style
  &:not(:disabled) {
    @include mdc-theme-prop(background-color, $color, $edgeOptOut: true);
  }
}

@mixin mdc-button-outline-color($color) {
  &:not(:disabled) {
    @include mdc-theme-prop(border-color, $color);
  }
}

@mixin mdc-button-icon-color($color) {
  &:not(:disabled) .mdc-button__icon {
    @include mdc-theme-prop(color, $color);
  }
}

@mixin mdc-button-ink-color($color) {
  &:not(:disabled) {
    @include mdc-theme-prop(color, $color);
  }
}

@mixin mdc-button-corner-radius($corner-radius) {
  border-radius: $corner-radius;
}

@mixin mdc-button-horizontal-padding($padding) {
  // $padding should be a single value; enforce it by specifying all 4 sides in the output
  padding: 0 $padding 0 $padding;
}

@mixin mdc-button-outline-width($outline-width, $padding: $mdc-button-contained-horizontal-padding) {
  // Note: Adjust padding to maintain consistent width with non-outlined buttons
  $padding-value: max($padding - $outline-width, 0);

  @include mdc-button-horizontal-padding($padding-value);

  border-width: $outline-width;
  // Note: line height is adjusted for outline button because borders are not
  // considered as space available to text on the Web
  line-height: $mdc-button-height - $outline-width * 2;

  // postcss-bem-linter: ignore
  &.mdc-button--dense {
    // Minus extra 1 to accommodate odd font size of dense button
    line-height: $mdc-dense-button-height - $outline-width * 2 - 1;
  }
}

@mixin mdc-button-base_() {
  @include typography(button);
  @include mdc-ripple-surface;
  @include mdc-ripple-radius-bounded;
  @include mdc-button-horizontal-padding($mdc-button-horizontal-padding);

  display: inline-flex;
  position: relative;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 64px;
  height: $mdc-button-height;
  border: none;
  outline: none;

  /* @alternate */
  line-height: inherit;
  user-select: none;
  -webkit-appearance: none;
  overflow: hidden;
  vertical-align: middle;

  &::-moz-focus-inner {
    padding: 0;
    border: 0;
  }

  // postcss-bem-linter: ignore
  &:active {
    outline: none;
  }

  &:hover {
    cursor: pointer;
  }

  &:disabled {
    @include mdc-theme-prop(background-color, transparent);

    color: $mdc-button-disabled-ink-color;
    cursor: default;
    pointer-events: none;
  }
}

@mixin mdc-button__icon_ {
  @include mdc-rtl-reflexive-box(margin, right, 8px);

  display: inline-block;
  width: 18px;
  height: 18px;
  font-size: 18px;
  vertical-align: top;
}

@mixin mdc-button__icon-svg_ {
  fill: currentColor;
}

@mixin mdc-button__icon-contained_ {
  @include mdc-rtl-reflexive-property(margin, -4px, 8px);
}

@mixin mdc-button--outlined_() {
  border-style: solid;

  &:disabled {
    border-color: $mdc-button-disabled-ink-color;
  }
}

@mixin mdc-button--filled_() {
  @include mdc-button-horizontal-padding($mdc-button-contained-horizontal-padding);

  &:disabled {
    background-color: rgba(mdc-theme-prop-value(on-surface), .12);
    color: $mdc-button-disabled-ink-color;
  }
}

@mixin mdc-button--raised_() {
  @include elevation(2);

  transition: elevation-transition-value();

  &:hover,
  &:focus {
    @include elevation(4);
  }

  &:active {
    @include elevation(8);
  }

  &:disabled {
    @include elevation(0);
  }
}

@mixin mdc-button--dense_() {
  height: $mdc-dense-button-height;
  font-size: .8125rem; // 13sp
  line-height: $mdc-dense-button-height;
}
