// Lightning Design System 2.264.0-beta.1
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license

/**
 * @summary Initializes pill
 *
 * @name base
 * @selector .slds-pill
 * @restrict span
 * @support dev-ready
 * @variant
 */
.slds-pill {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  line-height: var(--slds-c-pill-line-height, var(--sds-c-pill-line-height, $line-height-text));
  max-width: 100%; // Required to make the container shrink when truncated
  padding-top: var(--slds-c-pill-spacing-block-start, var(--slds-c-pill-spacing-blockstart, var(--sds-c-pill-spacing-block-start, 0)));
  padding-right: var(--slds-c-pill-spacing-inline-end, var(--slds-c-pill-spacing-inlineend, var(--sds-c-pill-spacing-inline-end, 0)));
  padding-bottom: var(--slds-c-pill-spacing-block-end, var(--slds-c-pill-spacing-blockend, var(--sds-c-pill-spacing-block-end, 0)));
  padding-left: var(--slds-c-pill-spacing-inline-start, var(--slds-c-pill-spacing-inlinestart, var(--sds-c-pill-spacing-inline-start, $spacing-xxx-small)));
  border-width: var(--slds-c-pill-sizing-border, var(--sds-c-pill-sizing-border, $border-width-thin));
  border-style: solid;
  border-color: var(--slds-c-pill-color-border, var(--sds-c-pill-color-border, var(--slds-g-color-border-base-4, #{$color-border})));
  border-radius: var(--slds-c-pill-radius-border, var(--sds-c-pill-radius-border, $border-radius-medium));
  background-color: var(--slds-c-pill-color-background, var(--sds-c-pill-color-background, var(--slds-g-color-neutral-base-100, #{$color-background-pill})));
  box-shadow: var(--slds-c-pill-shadow);
  position: relative;
  min-height: $height-pill;

  + .slds-pill {
    margin-left: $spacing-xxx-small;
  }

  &:hover {
    /*! @css-var-fallback background-color */
    --slds-c-pill-color-background: var(--slds-c-pill-color-background-hover, var(--sds-c-pill-color-background-hover, var(--slds-g-color-neutral-base-95, #{$color-background-button-default-hover})));
  }

  &:focus {
    /*! @css-var-fallback box-shadow */
    --slds-c-pill-shadow: var(--slds-c-pill-shadow-focus, var(--sds-c-pill-shadow-focus, var(--slds-g-shadow-outline-focus-1, #{$shadow-button-focus})));

    outline: 0;
  }

  a {
    text-decoration: none;
  }

  .slds-popover_tooltip, .slds-popover--tooltip {
    width: max-content;
  }

  .slds-pill__remove:focus {
    box-shadow: var(--slds-g-shadow-inset-inverse-focus-1);
    outline: 0;
  }
}

/**
  * Modifier that removes border and background from a pill
  *
  * @selector .slds-pill_bare
  * @restrict .slds-pill
  * @modifier
  */
.slds-pill_bare,
.slds-pill--bare {
  /*! @css-var-fallback background-color */
  --slds-c-pill-color-background: transparent;

  /*! @css-var-fallback border-width */
  --slds-c-pill-sizing-border: 0;

  &:hover {
    /*! @css-var-fallback background-color */
    --slds-c-pill-color-background-hover: transparent;
  }
}

/**
  * Container to hold pill(s) with borders
  *
  * @selector .slds-pill_container
  * @restrict div
  */
.slds-pill_container {
  display: flex;
  min-height: calc(#{$height-input} + 2px);
  padding-top: var(--slds-c-pill-container-spacing-block-start, var(--slds-c-pill-container-spacing-blockstart, var(--sds-c-pill-container-spacing-block-start, $spacing-xxx-small)));
  padding-right: var(--slds-c-pill-container-spacing-inline-end, var(--slds-c-pill-container-spacing-inlineend, var(--sds-c-pill-container-spacing-inline-end, $spacing-xxx-small)));
  padding-bottom: var(--slds-c-pill-container-spacing-block-end, var(--slds-c-pill-container-spacing-blockend, var(--sds-c-pill-container-spacing-block-end, $spacing-xxx-small)));
  padding-left: var(--slds-c-pill-container-spacing-inline-start, var(--slds-c-pill-container-spacing-inlinestart, var(--sds-c-pill-container-spacing-inline-start, $spacing-xxx-small)));
  border-width: var(--slds-c-pill-sizing-border, var(--sds-c-pill-sizing-border, $border-width-thin));
  border-style: solid;
  border-color: var(--slds-c-pill-color-border, var(--sds-c-pill-color-border, var(--slds-g-color-border-base-4, #{$color-border})));
  border-radius: var(--slds-c-pill-radius-border, var(--sds-c-pill-radius-border, $border-radius-medium));
  background-color: var(--slds-c-pill-container-color-background, var(--sds-c-pill-container-color-background, var(--slds-g-color-neutral-base-100, #{$color-background-input})));

  .slds-listbox_inline {
    margin-left: 0;
    margin-right: 0;
  }

  .slds-pill_link,
  .slds-pill--link,
  .slds-listbox-item {

    .slds-pill__action:focus,
    .slds-pill:focus {
      box-shadow: var(--slds-g-shadow-inset-inverse-focus-1);
    }

    .slds-pill.slds-pill_bare:focus {
      outline-offset: -2px;
    }
  }
}

.slds-listbox_selection-group .slds-listbox-item .slds-pill:focus {
  box-shadow: var(--slds-g-shadow-inset-inverse-focus-1);
}

/**
  * Line of text inside a pill
  *
  * @selector .slds-pill__label
  * @restrict .slds-pill a, .slds-pill span
  */
.slds-pill__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  &:focus {
    outline: 0;
    border-radius: $border-radius-medium;
    box-shadow: var(--slds-c-pill-label-shadow-focus, var(--sds-c-pill-label-shadow-focus, var(--slds-g-shadow-outset-focus-1, #{$shadow-button-focus})));
  }
}

/**
  * Initializes pill icon or avatar that sits to the left of the label
  *
  * @selector .slds-pill__icon_container
  * @restrict .slds-pill span
  */
.slds-pill__icon,
.slds-pill__icon_container {
  @include square($square-icon-x-small-boundary);
  margin-right: $spacing-xx-small;

  .slds-icon,
  .slds-avatar {
    @include square($square-icon-x-small-boundary);
    display: block;
    font-size: $font-size-1;
  }

  ~ .slds-pill__action {
    padding-left: calc(#{$square-icon-x-small-boundary} + #{$spacing-xx-small} + 2px);
  }
}

/**
  * Initializes remove icon in pill that sits to the right of the label
  *
  * @selector .slds-pill__remove
  * @restrict .slds-pill button, .slds-pill span
  */
.slds-pill__remove {
  @include square($square-icon-xx-small-boundary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: $border-radius-small;
  padding: $spacing-xx-small;
  box-sizing:content-box;
  right: 0;

  svg {
    @include square($square-icon-xx-small-content);
  }
}

/**
 * Creates a pill with a hyperlink
 *
 * @selector .slds-pill_link
 * @restrict .slds-pill
 */
.slds-pill_link,
.slds-pill--link {
  border: 0;
  padding: 0;

  .slds-pill__icon_container {
    display: inline-block;
    position: absolute;
    top: 50%;
    left: $spacing-xxx-small;
    transform: translateY(-50%);
  }

  .slds-pill__remove {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }
}

/**
 * Actionable element inside of pill with hyperlink
 *
 * @selector .slds-pill__action
 * @restrict .slds-pill_link a
 */
.slds-pill__action {
  /*
  * In postcss calc function has a limitation that it can't take more than three variables 
  * We are creating below variables to extract more than four variables into two to solve the issue temporally
  * We may refactor this logic if we get a better solution by upgrading the versions or additional postcss plugin
  */
  --_slds-postcss-fix-calc-part-1: var(--slds-c-pill-spacing-inline-end, var(--slds-c-pill-spacing-inlineend));
  --_slds-postcss-fix-calc-part-2: var(--sds-c-pill-spacing-inline-end, #{$spacing-xxx-small});
  padding-right: calc(#{$square-icon-xx-small-boundary} +  var(--_slds-postcss-fix-calc-part-1, var(--_slds-postcss-fix-calc-part-2)) + 6px);
  padding-top: var(--slds-c-pill-spacing-block-start, var(--slds-c-pill-spacing-blockstart, var(--sds-c-pill-spacing-block-start, $spacing-xxx-small)));
  padding-bottom: var(--slds-c-pill-spacing-block-end, var(--slds-c-pill-spacing-blockend, var(--sds-c-pill-spacing-block-end, $spacing-xxx-small)));
  padding-left: var(--slds-c-pill-spacing-inline-start, var(--slds-c-pill-spacing-inlinestart, var(--sds-c-pill-spacing-inline-start, $spacing-xxx-small)));
  border-width: var(--slds-c-pill-sizing-border, var(--sds-c-pill-sizing-border, $border-width-thin));
  border-style: solid;
  border-color: var(--slds-c-pill-color-border, var(--sds-c-pill-color-border, var(--slds-g-color-border-base-4, #{$color-border})));
  border-radius: var(--slds-c-pill-radius-border, var(--sds-c-pill-radius-border, $border-radius-medium));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-grow: 1;

  &:focus {
    box-shadow: var(--slds-c-pill-action-shadow, var(--sds-c-pill-action-shadow, var(--slds-g-shadow-outline-focus-1, #{$shadow-button-focus})));
    outline: 0;
  }
}

/**
 * Pill error styles
 *
 * @selector .slds-has-error
 * @restrict .slds-pill
 * @modifier
 */
.slds-has-error {
  border-color: var(--slds-c-pill-error-color-border, var(--sds-c-pill-error-color-border, var(--slds-g-color-error-base-40, #{$color-border-error})));

  &:active {
    border-color: var(--slds-c-pill-error-color-border-active, var(--sds-c-pill-error-color-border-active, var(--slds-g-color-error-base-40, #{$color-border-error})));
  }

  .slds-pill__label {
    font-weight: $font-weight-bold;
    color: var(--slds-c-pill-error-text-color, var(--slds-c-pill-text-color-error, var(--sds-c-pill-error-text-color,
      var(--slds-g-color-error-base-40, #{$color-text-error}))));
  }

  &:hover {
    --slds-c-pill-error-text-color: var(--slds-g-color-error-base-30, #{$color-text-error});

    .slds-pill__icon_container .slds-icon-text-error {
      --slds-c-icon-color-foreground: var(--slds-g-color-error-base-30, #{$color-text-error});
    }
  }
}
