//
// Copyright 2016 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.
//

@import "@material/elevation/mixins";
@import "@material/ripple/mixins";
@import "@material/rtl/mixins";
@import "@material/theme/functions";
@import "@material/theme/mixins";
@import "@material/typography/mixins";
@import "./variables";

@mixin mdc-button-filled-accessible($container-fill-color) {
  $fill-tone: mdc-theme-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;
}

@mixin mdc-button-base_() {
  @include mdc-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 mdc-elevation(2);

  transition: mdc-elevation-transition-value();

  &:hover,
  &:focus {
    @include mdc-elevation(4);
  }

  &:active {
    @include mdc-elevation(8);
  }

  &:disabled {
    @include mdc-elevation(0);
  }
}

@mixin mdc-button--dense_() {
  height: $mdc-dense-button-height;
  font-size: .8125rem; // 13sp
}
