@use "sass:map";

@import 'mixins/mixins';
@import 'mixins/var';
@import 'common/var';

$types: (primary, success, warning, info, danger, focus);

$--tag-color: () !default;

@each $type in $types {
  $--tag-color: map.merge(
    (
      $type: map.get($--colors, $type, 'base'),
    ),
    $--tag-color
  ) !global;
}

@include b(tag) {
  @include set-component-css-var('tag', $--tag);

  @each $type in $types {
    --el-tag-#{$type}-color: var(--el-color-#{$type});
  }
}

@mixin genTheme(
  $backgroundColorWeight,
  $borderColorWeight,
  $fontColorWeight,
  $hoverColorWeight
) {
  background-color: mix(
    map.get($--tag-color, 'primary'),
    $--color-white,
    $backgroundColorWeight
  );
  border-color: mix(
    map.get($--tag-color, 'primary'),
    $--color-white,
    $borderColorWeight
  );
  color: mix(
    map.get($--tag-color, 'primary'),
    $--color-white,
    $fontColorWeight
  );

  @include when(hit) {
    border-color: map.get($--tag-color, 'primary');
  }

  .#{$namespace}-tag__close {
    color: mix(
      map.get($--tag-color, 'primary'),
      $--color-white,
      $fontColorWeight
    );
    &:hover {
      color: $--color-white;
      background-color: mix(
        map.get($--tag-color, 'primary'),
        $--color-white,
        $hoverColorWeight
      );
    }
  }

  @each $type in $types {
    &.#{$namespace}-tag--#{$type} {
      background-color: mix(
        map.get($--tag-color, $type),
        $--color-white,
        $backgroundColorWeight
      );
      border-color: mix(
        map.get($--tag-color, $type),
        $--color-white,
        $borderColorWeight
      );
      color: mix(
        map.get($--tag-color, $type),
        $--color-white,
        $fontColorWeight
      );

      @include when(hit) {
        border-color: map.get($--tag-color, $type);
      }

      .#{$namespace}-tag__close {
        color: mix(
          map.get($--tag-color, $type),
          $--color-white,
          $fontColorWeight
        );
        &:hover {
          color: $--color-white;
          background-color: mix(
            map.get($--tag-color, $type),
            $--color-white,
            $hoverColorWeight
          );
        }
      }
    }
  }
}

@include b(tag) {
  @include genTheme(10%, 20%, 100%, 100%);
  display: inline-block;
  height: 32px;
  padding: var(--el-tag-padding);
  line-height: 30px;
  font-size: var(--el-tag-font-size);
  color: map.get($--tag-color, 'primary');
  border-width: 1px;
  border-style: solid;
  border-radius: var(--el-tag-border-radius);
  box-sizing: border-box;
  white-space: nowrap;

  .#{$namespace}-icon-close {
    border-radius: 50%;
    text-align: center;
    position: relative;
    cursor: pointer;
    font-size: 12px;
    height: 16px;
    width: 16px;
    line-height: 16px;
    vertical-align: middle;
    top: -1px;
    right: -5px;

    &::before {
      display: block;
    }
  }

  @include m(dark) {
    @include genTheme(100%, 100%, 0, 80%);
  }

  @include m(plain) {
    @include genTheme(0, 40%, 100%, 100%);
  }

  @include m(medium) {
    height: 28px;
    line-height: 26px;

    .#{$namespace}-icon-close {
      transform: scale(0.8);
    }
  }

  @include m(small) {
    height: 24px;
    padding: 0 8px;
    line-height: 22px;

    .#{$namespace}-icon-close {
      transform: scale(0.8);
    }
  }

  @include m(mini) {
    height: 20px;
    padding: 0 5px;
    line-height: 19px;

    .#{$namespace}-icon-close {
      margin-left: -3px;
      transform: scale(0.7);
    }
  }
}
