/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
//
// Copyright 2020 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.
//

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

@use '@material/elevation/elevation' as mdc-elevation;
@use '@material/elevation/elevation-theme' as mdc-elevation-theme;
@use '@material/feature-targeting/feature-targeting' as mdc-feature-targeting;
@use '@material/rtl/rtl' as mdc-rtl;
@use '@material/typography/typography' as mdc-typography;
@use './button-ripple';
@use './button-shared-theme';

@mixin static-styles($query: mdc-feature-targeting.all()) {
  @include static-styles-without-ripple($query: $query);
  @include button-ripple.static-styles($query: $query);
}

@mixin static-styles-without-ripple($query: mdc-feature-targeting.all()) {
  $feat-structure: mdc-feature-targeting.create-target($query, structure);

  // prettier-ignore
  @include mdc-elevation.overlay-common($query); // COPYBARA_COMMENT_THIS_LINE

  // postcss-bem-linter: define button
  .forge-button {
    @include base($query);
    // The icon CSS class overrides styles defined in the .material-icons CSS
    // class, which is loaded separately so the order of CSS definitions is not
    // guaranteed. Therefore, increase specifity by nesting this class to ensure
    // overrides apply.
    .forge-button__icon {
      @include mdc-feature-targeting.targets($feat-structure) {
        @include icon;
      }
    }
  }

  .forge-button__label ~ .forge-button__icon {
    @include mdc-feature-targeting.targets($feat-structure) {
      @include icon-trailing;
    }
  }

  svg.forge-button__icon {
    @include mdc-feature-targeting.targets($feat-structure) {
      @include icon-svg;
    }
  }

  // TODO: figure out the correct place for this rule.
  .forge-button--raised,
  .forge-button--unelevated,
  .forge-button--outlined {
    .forge-button__icon {
      @include mdc-feature-targeting.targets($feat-structure) {
        // Icons inside contained buttons have different styles due to increased button padding
        @include icon-contained;
      }
    }

    .forge-button__label ~ .forge-button__icon {
      @include mdc-feature-targeting.targets($feat-structure) {
        @include icon-contained-trailing;
      }
    }
  }
  // postcss-bem-linter: end
}

@mixin base($query) {
  $feat-structure: mdc-feature-targeting.create-target($query, structure);

  @include mdc-typography.typography(button, $query);
  @include mdc-elevation-theme.overlay-surface-position($query: $query);
  @include mdc-elevation-theme.overlay-dimensions(100%, $query: $query);

  @include mdc-feature-targeting.targets($feat-structure) {
    display: inline-flex;
    // position: relative; already set in mdc-elevation-overlay-surface-position
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 64px;
    border: none;
    outline: none;
    /* @alternate */
    line-height: inherit;
    user-select: none;
    -webkit-appearance: none;
    // Even though `visible` is the default, IE 11 computes the property as
    // `hidden` in some cases, unless it's explicitly defined here.
    overflow: visible;
    vertical-align: middle;
  }

  &::-moz-focus-inner {
    @include mdc-feature-targeting.targets($feat-structure) {
      padding: 0;
      border: 0;
    }
  }

  // postcss-bem-linter: ignore
  &:active {
    @include mdc-feature-targeting.targets($feat-structure) {
      outline: none;
    }
  }

  &:hover {
    @include mdc-feature-targeting.targets($feat-structure) {
      cursor: pointer;
    }
  }

  &:disabled {
    @include mdc-feature-targeting.targets($feat-structure) {
      cursor: default;
      pointer-events: none;
    }
  }
}

@mixin icon {
  @include mdc-rtl.reflexive-box(margin, right, 8px);

  $icon-size: mdc-typography.px-to-rem(18px);

  display: inline-block;
  font-size: $icon-size;
  height: $icon-size;
  vertical-align: top;
  width: $icon-size;
}

@mixin icon-trailing {
  @include mdc-rtl.reflexive-box(margin, left, 8px);
}

@mixin icon-svg {
  fill: currentColor;
}

@mixin icon-contained {
  @include mdc-rtl.reflexive-property(margin, -4px, 8px);
}

@mixin icon-contained-trailing {
  @include mdc-rtl.reflexive-property(margin, 8px, -4px);
}

// FORGE(new): added new dense mixin
@mixin dense() {
  @include button-shared-theme.density(-3);

  height: 1.5rem;
}
