// Material Design Button: https://material.io/archive/guidelines/components/buttons.html

$button-border-radius: 2px !default;
$button-fab-border-radius: 50% !default;
$button-icon-border-radius: $button-fab-border-radius !default;

$button-font-size: $body-font-size-base !default;
$button-font-size-dense: math.div($body-font-size-base * 13, 14) !default;

$button-line-height: rem(3.60) !default;
$button-line-height-dense: rem(3.20) !default;
$button-margin: rem(0.600) rem(0.800) !default;
$button-min-width: rem(8.800) !default;
$button-padding: 0 $button-left-right-padding !default;


// Fab buttons
$button-fab-line-height: rem(5.600) !default;
$button-fab-mini-width: rem(4.00) !default;
$button-fab-mini-height: rem(4.00) !default;
$button-fab-mini-line-height: rem(4.00) !default;

$button-fab-toast-offset: $button-fab-height * 0.75 !default;

$icon-button-margin: rem(0.600) !default;

// Fix issue causing buttons in Firefox to be 2px bigger than they should
button.md-button::-moz-focus-inner {
  border: 0;
}

.md-button {
  display: inline-block;
  position: relative; // Required for absolute canvas child elements.
  cursor: pointer;

  /** Alignment adjustments */
  @include dense(min-height, $button-line-height, $button-line-height-dense);
  min-width: $button-min-width;
  @include dense(line-height, $button-line-height, $button-line-height-dense);

  vertical-align: middle;
  align-items: center;
  text-align: center;

  border-radius: $button-border-radius;
  box-sizing: border-box;

  /* Reset default button appearance */
  user-select: none;
  outline: none;
  border: 0;

  /** Custom styling for button */
  padding: $button-padding;
  margin: $button-margin;

  background: transparent;
  color: currentColor;
  white-space: nowrap;

  /* Uppercase text content */
  text-transform: uppercase;
  font-weight: 500;
  @include dense(font-size, $button-font-size, $button-font-size-dense);
  font-style: inherit;
  font-variant: inherit;
  font-family: inherit;
  text-decoration: none;

  // Ink Ripple should not create any overflow.
  overflow: hidden;

  transition: box-shadow $swift-ease-out-duration $swift-ease-out-timing-function,
              background-color $swift-ease-out-duration $swift-ease-out-timing-function;

  &:focus {
    outline: none;
  }

  &:hover, &:focus {
    text-decoration: none;
  }

  // By default $ngAnimate looks for transition durations on the element, when using ng-hide, ng-if, ng-show.
  // The .md-button has a transition duration applied, which means, that $ngAnimate delays the hide process.
  // To avoid this, we need to reset the transition, when $ngAnimate looks for the duration.
  &.ng-hide, &.ng-leave {
    transition: none;
  }

  &.md-cornered {
    border-radius: 0;
  }

  &.md-icon {
    padding: 0;
    background: none;
  }

  &.md-raised {
    &:not([disabled]) {
      @include md-shadow-bottom-z-1();
    }
  }

  &.md-icon-button {
    margin: 0 $icon-button-margin;
    height: $icon-button-height;
    min-width: 0;
    line-height: $icon-size;
    padding: $baseline-grid;
    width: $icon-button-width;
    border-radius: $button-icon-border-radius;
  }

  &.md-fab {

    // Include the top/left/bottom/right fab positions
    @include fab-all-positions();

    z-index: $z-index-fab;

    line-height: $button-fab-line-height;

    min-width: 0;
    width: $button-fab-width;
    height: $button-fab-height;
    vertical-align: middle;

    @include md-shadow-bottom-z-1();
    border-radius: $button-fab-border-radius;
    background-clip: padding-box;
    overflow: hidden;

    transition: $swift-ease-in;
    transition-property: background-color, box-shadow, transform;

    &.md-mini {
      line-height: $button-fab-mini-line-height;
      width: $button-fab-mini-width;
      height: $button-fab-mini-height;
    }

    &.ng-hide, &.ng-leave {
      transition: none;
    }

    &[disabled] {
      box-shadow: none;
    }
  }

  &:not([disabled]) {
    &.md-raised,
    &.md-fab {
      &.md-focused {
        @include md-shadow-bottom-z-1();
      }
      &:active {
        @include md-shadow-bottom-z-2();
      }
    }
  }

  .md-ripple-container {
    border-radius: inherit;
    background-clip: padding-box;
    overflow: hidden;

    // Workaround for rounded corner overflow bug
    // Force Safari and Chrome to use a compositing layer
    -webkit-transform:translateZ(0);
  }
}

// Using `display:block;` is required for correct vertical alignment
// because '.md-button' uses `display:inline-block;`.
.md-button.md-icon-button,
button.md-button.md-fab {
  md-icon {
    display: block;
  }
}

.md-toast-open-top {
  .md-button.md-fab-top-left,
  .md-button.md-fab-top-right {
    transition: $swift-ease-out;
    transform: translate3d(0, $button-fab-toast-offset, 0);
    &:not([disabled]) {
      &.md-focused,
      &:hover {
        transform: translate3d(0, $button-fab-toast-offset - 1, 0);
      }
    }
  }
}

.md-toast-open-bottom {
  .md-button.md-fab-bottom-left,
  .md-button.md-fab-bottom-right {
    transition: $swift-ease-out;
    transform: translate3d(0, -$button-fab-toast-offset, 0);
    &:not([disabled]) {
      &.md-focused,
      &:hover {
        transform: translate3d(0, -$button-fab-toast-offset - 1, 0);
      }
    }
  }
}

.md-button-group {
  display: flex;
  flex: 1;
  width: 100%;

  & > .md-button {
    flex: 1;

    display: block;

    overflow: hidden;

    width: 0;

    border-width: 1px 0px 1px 1px;
    border-radius: 0;

    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;

    &:first-child {
      border-radius: 2px 0px 0px 2px;
    }
    &:last-child {
      border-right-width: 1px;
      border-radius: 0px 2px 2px 0px;
    }
  }
}
// IE only
@media screen and (-ms-high-contrast: active) {
  .md-button.md-raised,
  .md-button.md-fab {
    border: 1px solid #fff;
  }
}
