// Copyright (C) 2024 The Android Open Source Project
//
// 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.

@import "../assets/theme";

.pf-chip {
  @mixin color-theme($base-color) {
    color: $base-color;
    background: color-mix(in srgb, $base-color 15%, transparent);
  }

  display: inline-flex;
  align-items: baseline;

  font-family: var(--pf-font-compact);
  line-height: 1;
  user-select: none;
  border-radius: $border-radius;
  padding: 2px 4px;
  white-space: nowrap;
  min-width: max-content;
  border: solid 1px color-mix(in srgb, currentColor, transparent 50%);
  overflow: hidden;

  &__label {
    flex-shrink: 1;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  &--rounded {
    border-radius: 100px;
  }

  &__icon {
    align-self: center;
    margin-right: 6px;
  }

  .pf-button {
    margin-left: 6px; // Make some room between the icon and label
  }

  &:focus-visible {
    @include focus;
  }

  // Remove default background in minimal mode, showing only the text
  &.pf-intent-primary {
    @include color-theme(var(--pf-color-primary));
  }

  &.pf-intent-success {
    @include color-theme(var(--pf-color-success));
  }

  &.pf-intent-warning {
    @include color-theme(var(--pf-color-warning));
  }

  &.pf-intent-danger {
    @include color-theme(var(--pf-color-danger));
  }

  &[disabled] {
    cursor: not-allowed;
    opacity: 0.5;
  }

  // Reduce padding when compact
  &.pf-compact {
    padding: 0px 4px;
    .pf-chip__icon {
      margin-right: 2px;
    }

    .pf-button {
      margin-left: 2px;
    }
  }

  // Reduce padding when we are icon-only
  &.pf-icon-only {
    & > .pf-left-icon {
      margin: 0;
    }

    padding: 4px;

    &.pf-compact {
      padding: 0;
    }
  }
}
