/**
 *
 * @ai-apps/angular v2.152.0 | _tag.scss
 *
 * Copyright 2014, 2023 IBM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use '../../theme' as *;
@use '../../utilities/button-reset';
@use '../../type' as *;
@use '../../motion' as *;
@use '../../config' as *;
@use '../../utilities/component-tokens' as *;
@use '../../utilities/convert' as *;
@use '../../utilities/high-contrast-mode' as *;
@use '../../spacing' as *;
@use './tokens' as *;
@use './mixins' as *;
@use '../../utilities/skeleton';

/// Tag styles
/// @access public
/// @group tag
@mixin tag {
  .#{$prefix}--tag {
    @include type-style('label-01');
    @include tag-theme($tag-background-gray, $tag-color-gray, $tag-hover-gray);

    display: inline-flex;
    // ensures tag stays pill shaped;
    min-width: rem(32px);
    // restricts size of contained elements
    max-width: 100%;
    min-height: rem(24px);
    align-items: center;
    justify-content: center;
    padding: $spacing-02 $spacing-03;
    margin: $spacing-02;
    border-radius: rem(15px);
    cursor: default;
    vertical-align: middle;
    word-break: break-word;

    &:not(:first-child) {
      margin-left: 0;
    }
  }

  .#{$prefix}--tag--red {
    @include tag-theme($tag-background-red, $tag-color-red, $tag-hover-red);
  }

  .#{$prefix}--tag--magenta {
    @include tag-theme(
      $tag-background-magenta,
      $tag-color-magenta,
      $tag-hover-magenta
    );
  }

  .#{$prefix}--tag--purple {
    @include tag-theme(
      $tag-background-purple,
      $tag-color-purple,
      $tag-hover-purple
    );
  }

  .#{$prefix}--tag--blue {
    @include tag-theme($tag-background-blue, $tag-color-blue, $tag-hover-blue);
  }

  .#{$prefix}--tag--cyan {
    @include tag-theme($tag-background-cyan, $tag-color-cyan, $tag-hover-cyan);
  }

  .#{$prefix}--tag--teal {
    @include tag-theme($tag-background-teal, $tag-color-teal, $tag-hover-teal);
  }

  .#{$prefix}--tag--green {
    @include tag-theme(
      $tag-background-green,
      $tag-color-green,
      $tag-hover-green
    );
  }

  .#{$prefix}--tag--gray {
    @include tag-theme($tag-background-gray, $tag-color-gray, $tag-hover-gray);
  }

  .#{$prefix}--tag--cool-gray {
    @include tag-theme(
      $tag-background-cool-gray,
      $tag-color-cool-gray,
      $tag-hover-cool-gray
    );
  }

  .#{$prefix}--tag--warm-gray {
    @include tag-theme(
      $tag-background-warm-gray,
      $tag-color-warm-gray,
      $tag-hover-warm-gray
    );
  }

  .#{$prefix}--tag--high-contrast {
    @include tag-theme(
      $background-inverse,
      $text-inverse,
      $background-inverse-hover
    );
  }

  .#{$prefix}--tag--outline {
    @include tag-theme($background, $text-primary, $layer-hover);

    box-shadow: inset 0 0 0 1px $background-inverse;
  }

  .#{$prefix}--tag--disabled,
  .#{$prefix}--tag--filter.#{$prefix}--tag--disabled,
  .#{$prefix}--tag--interactive.#{$prefix}--tag--disabled {
    @include tag-theme($layer, $text-disabled);

    &:hover {
      cursor: not-allowed;
    }
  }

  .#{$prefix}--tag__label {
    overflow: hidden;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .#{$prefix}--tag--interactive:focus {
    box-shadow: inset 0 0 0 1px $focus;
    outline: none;
  }

  .#{$prefix}--tag--interactive:hover {
    cursor: pointer;
  }

  // tags used for filtering
  .#{$prefix}--tag--filter {
    padding-top: 0;
    padding-right: 0;
    padding-bottom: 0;
    cursor: pointer;

    &:hover {
      outline: none;
    }
  }

  .#{$prefix}--tag--interactive {
    transition: background-color $duration-fast-01 motion(entrance, productive);
  }

  .#{$prefix}--tag__close-icon {
    display: flex;
    width: rem(24px);
    height: rem(24px);
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    margin: 0 0 0 rem(2px);
    background-color: transparent;
    border-radius: 50%;
    color: currentColor;
    cursor: pointer;
    transition: background-color $duration-fast-01 motion(standard, productive),
      box-shadow $duration-fast-01 motion(standard, productive);

    svg {
      fill: currentColor;
    }
  }

  .#{$prefix}--tag__custom-icon {
    width: rem(16px);
    height: rem(16px);
    flex-shrink: 0;
    padding: 0;
    border: 0;
    margin-right: $spacing-02;
    background-color: transparent;
    color: currentColor;
    outline: none;

    svg {
      fill: currentColor;
    }
  }

  .#{$prefix}--tag--disabled .#{$prefix}--tag__close-icon {
    cursor: not-allowed;
  }

  .#{$prefix}--tag__close-icon:focus {
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px $focus;
    outline: none;
  }

  .#{$prefix}--tag--high-contrast .#{$prefix}--tag__close-icon:focus {
    box-shadow: inset 0 0 0 1px $focus-inverse;
  }

  .#{$prefix}--tag--filter.#{$prefix}--tag--disabled
    .#{$prefix}--tag__close-icon:hover {
    background-color: transparent;
  }

  .#{$prefix}--tag--filter.#{$prefix}--tag--disabled svg {
    fill: $icon-disabled;
  }

  // small tags
  .#{$prefix}--tag--sm {
    min-height: rem(18px);
    padding: 0 $spacing-03;
  }

  .#{$prefix}--tag--sm.#{$prefix}--tag--filter {
    padding-right: 0;
  }

  .#{$prefix}--tag--sm .#{$prefix}--tag__close-icon {
    width: rem(18px);
    height: rem(18px);
    margin-left: rem(5px);
  }

  // Skeleton state
  .#{$prefix}--tag.#{$prefix}--skeleton {
    @include tag-theme(
      $bg-color: $skeleton-background,
      $text-color: $text-primary
    );

    overflow: hidden;
    width: rem(60px);

    // Safari specific bug (#7672)
    @media not all and (min-resolution: 0.001dpcm) {
      @supports (-webkit-appearance: none) and (stroke-color: transparent) {
        transform: translateZ(0);
      }
    }
  }

  // Windows HCM fix
  /* stylelint-disable */
  .#{$prefix}--tag {
    @include high-contrast-mode('outline');
  }

  .#{$prefix}--tag__close-icon svg,
  .#{$prefix}--tag__custom-icon svg {
    @include high-contrast-mode('icon-fill');
  }

  .#{$prefix}--tag__close-icon:focus {
    @include high-contrast-mode('focus');
  }
  /* stylelint-enable */
}
