@import '../scss/variable';

$maptag-prefix: #{$prefix}-maptag;

@mixin maptag-variant-highlight($base-color) {
  border-color: tint($base-color, 60%);
  background-color: tint($base-color, 90%);
  color: $base-color;
  &:hover,
  &:active,
  &:focus {
    border-color: tint($base-color, 30%);
    color: shade($base-color, 15%);
  }
}

@mixin ne-maptag {
  .#{$maptag-prefix} {
    display: inline-flex;
    overflow: hidden;
    align-items: center;
    height: $maptag-height;
    margin-right: 4px;
    border: 1px solid $global-border-color;
    border-radius: $global-radius;
    background-color: $maptag-default-bg;
    color: $component-default-color;
    font-size: $maptag-font-size;
    white-space: nowrap;
    vertical-align: middle;
    transform-origin: left;
    transition: all $animation-duration-base $ease-out;
    cursor: pointer;
    &-content {
      overflow: hidden;
      min-width: 0;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    &:hover,
    &:active,
    &:focus {
      color: $primary-color;
      .#{$maptag-prefix}-icon-close {
        transform: rotate(90deg);
      }
    }

    &-checkable {
      border-color: transparent;
      background-color: transparent;

      &-disabled {
        border-color: $component-disabled-bg;
        box-shadow: none;
        background-color: $component-disabled-bg;
        color: $component-disabled-color;
        text-shadow: none;
      }
    }
    &-checked {
      border-color: $primary-color;
      background: $primary-color;
      color: $white;
      &:hover,
      &:active,
      &:focus {
        color: $white;
      }
    }
    &-icon-close {
      margin-right: -4px;
      margin-left: $icon-gutter - 4;
      transition: transform $animation-duration-base $ease-in-out;
    }

    &-create {
      padding: 0 6px;
      border: $global-border-width dashed $global-border-color;
      background-color: $white;
      &:not(.#{$maptag-prefix}-disabled):hover,
      &:not(.#{$maptag-prefix}-disabled):focus,
      &:not(.#{$maptag-prefix}-disabled):active {
        border-style: solid;
        color: $primary-color;
      }
      &-active {
        border-style: solid;
      }
      &.#{$maptag-prefix}-create-active:hover {
        color: $component-default-color;
      }
    }

    &-input {
      display: inline-flex;
      width: $maptag-input-width;
      height: 100%;
      padding: 0;
      border: none;
      outline: none;
    }

    &-closing {
      width: 0;
      margin: 0;
      padding: 0 !important;
      opacity: 0;
      transform: scale(0.2, 0.2);
    }

    &-disabled {
      cursor: not-allowed;
    }
    &-red,
    &-error {
      @include maptag-variant-highlight($error-color);
    }
    &-yellow,
    &-warning {
      @include maptag-variant-highlight($warning-color);
    }
    &-blue,
    &-info {
      @include maptag-variant-highlight($info-color);
    }
    &-green,
    &-success {
      @include maptag-variant-highlight($success-color);
    }
    &-disabled,
    &.disabled,
    &[disabled] {
      &,
      &:hover,
      &:focus,
      &:active,
      &.active {
        border-color: $component-disabled-border;
        box-shadow: none;
        background-color: $component-disabled-bg;
        color: $component-disabled-color;
        text-shadow: none;
      }
    }
  }
  .#{$maptag-prefix}-group {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    .#{$maptag-prefix} {
      margin-bottom: 2px;
    }
  }
  @each $name, $value in $sizes-map {
    .#{$maptag-prefix}-#{$name} {
      height: $value - 10;
      padding: 0 $value / 4;
      font-size: map-get($font-sizes-map, $name);
      line-height: ($global-line-height + 0.01px) / map-get($font-sizes-map, $name);
      @if ($value - 10 < $global-line-height) {
        height: $global-line-height;
      }
    }
    .#{$maptag-prefix}-group-#{$name} {
      min-height: $value;
    }
  }
}
