//
// 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 '.mdc-*' should only be used in this project.

@use '@material/feature-targeting/feature-targeting';
@use '@material/ripple/ripple';
@use '@material/ripple/ripple-theme';
@use '@material/rtl/mixins' as rtl;
@use '@material/theme/theme';
@use '@material/touch-target/mixins' as touch;
@use './variables';

$ripple-target: '.mdc-deprecated-chip-trailing-action__ripple';

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

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

  @include touch.wrapper($query); // COPYBARA_COMMENT_THIS_LINE
  @include _touch-target-base($query);

  .mdc-deprecated-chip-trailing-action {
    @include size(variables.$size, $query);
    @include color(variables.$color, $query);
    @include touch-target-width(variables.$touch-target-width, $query);

    @include feature-targeting.targets($feat-structure) {
      border: none;
      display: inline-flex;
      position: relative;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      padding: 0;
      outline: none;
      cursor: pointer;
      -webkit-appearance: none;
    }

    @include feature-targeting.targets($feat-color) {
      background: none;
    }

    // Nested to increase specificity, ensuring SVG and font icon
    // color is affected regardless of load order without needing
    // !important or HTML tag targetting.
    .mdc-deprecated-chip-trailing-action__icon {
      @include feature-targeting.targets($feat-color) {
        fill: currentColor;
        color: inherit;
      }
    }
  }
}

@mixin ripple($query: feature-targeting.all()) {
  @include ripple.common($query); // COPYBARA_COMMENT_THIS_LINE
  $feat-structure: feature-targeting.create-target($query, structure);

  .mdc-deprecated-chip-trailing-action {
    @include ripple.surface($query: $query, $ripple-target: $ripple-target);
    @include ripple.radius-unbounded(
      $query: $query,
      $ripple-target: $ripple-target
    );
    @include ripple-theme.states(
      variables.$ripple-color,
      $query: $query,
      $ripple-target: $ripple-target
    );

    #{$ripple-target} {
      @include feature-targeting.targets($feat-structure) {
        position: absolute;
        // Ripple needs content-box as the box sizing and box-sizing: border-box
        // is often set as a default, so we override that here.
        box-sizing: content-box;
        width: 100%;
        height: 100%;
        overflow: hidden;
      }
    }
  }
}

/// Set the color of the trailing action
/// @param {Color} $color The trailing action color
@mixin color($color, $query: feature-targeting.all()) {
  $feat-color: feature-targeting.create-target($query, color);

  .mdc-deprecated-chip-trailing-action {
    @include feature-targeting.targets($feat-color) {
      @include theme.property(color, $color);
    }
  }
}

/// Set the size of the trailing action
/// @param {Number} $number The size of the trailing action
@mixin size($size, $query: feature-targeting.all()) {
  $feat-structure: feature-targeting.create-target($query, structure);

  .mdc-deprecated-chip-trailing-action__icon {
    @include feature-targeting.targets($feat-structure) {
      height: $size;
      width: $size;
      font-size: $size;
    }
  }
}

/// Set the horizontal spacing of the trailing action
/// @param {Number} $left The left spacing
/// @param {Number} $right The right spacing
@mixin horizontal-spacing($left, $right, $query: feature-targeting.all()) {
  $feat-structure: feature-targeting.create-target($query, structure);

  .mdc-deprecated-chip-trailing-action {
    @include feature-targeting.targets($feat-structure) {
      @include rtl.reflexive-property(margin, $left, $right);
    }
  }
}

/// Set the width of the touch target
/// @param {Number} $width The width of the touch target
@mixin touch-target-width($width, $query: feature-targeting.all()) {
  $feat-structure: feature-targeting.create-target($query, structure);

  .mdc-deprecated-chip-trailing-action__touch {
    @include feature-targeting.targets($feat-structure) {
      width: $width;
    }
  }
}

/// Private mixins

@mixin _touch-target-base($query: feature-targeting.all()) {
  .mdc-deprecated-chip-trailing-action__touch {
    @include touch.touch-target($set-width: true, $query: $query);
  }
}
