$tag-background-color: v("background") !default
$tag-color: v("text") !default
$tag-radius: v("radius") !default
$tag-delete-margin: 1px !default

+register(tag-background-color,$tag-background-color, true)
+register(tag-radius,$tag-radius, true)
+register(tag-color,$tag-color, true)
+register(tag-delete-margin,$tag-delete-margin, true)

.tags
  align-items: center
  display: flex
  flex-wrap: wrap
  justify-content: flex-start
  .tag
    margin-bottom: 0.5rem
    &:not(:last-child)
      +ltr-property("margin-right", 0.5rem)
  &:last-child
    margin-bottom: -0.5rem
  &:not(:last-child)
    margin-bottom: 1rem
  // Sizes
  &.are-medium
    .tag:not(.is-normal):not(.is-large)
      font-size: v("size-normal")
  &.are-large
    .tag:not(.is-normal):not(.is-medium)
      font-size: v("size-medium")
  &.is-centered
    justify-content: center
    .tag
      margin-right: 0.25rem
      margin-left: 0.25rem
  &.is-right
    justify-content: flex-end
    .tag
      &:not(:first-child)
        margin-left: 0.5rem
      &:not(:last-child)
        margin-right: 0
  &.has-addons
    .tag
      +ltr-property("margin-right", 0)
      &:not(:first-child)
        +ltr-property("margin-left", 0)
        +ltr-property("border-top-left-radius", 0)
        +ltr-property("border-bottom-left-radius", 0)
      &:not(:last-child)
        +ltr-property("border-top-right-radius", 0)
        +ltr-property("border-bottom-right-radius", 0)

.tag:not(body)
  align-items: center
  background-color: v("tag-background-color")
  border-radius: v("tag-radius")
  color: v("tag-color")
  display: inline-flex
  font-size: v("size-small")
  height: 2em
  justify-content: center
  line-height: 1.5
  padding-left: 0.75em
  padding-right: 0.75em
  white-space: nowrap
  .delete
    +ltr-property("margin-left", 0.25rem)
    +ltr-property("margin-right", -0.375rem)
  // Colors
  @each $name in $colors-list
    $color: v($name)
    $color-invert: v($name+"-invert")
    &.is-#{$name}
      background-color: $color
      color: $color-invert
      // If a light and dark colors are provided
      @if isRegistered($name+'-dark')
        $color-light: v($name+'-light')
        $color-dark: v($name+'-dark')
        &.is-light
          background-color: $color-light
          color: $color-dark
  // Sizes
  &.is-normal
    font-size: v("size-small")
  &.is-medium
    font-size: v("size-normal")
  &.is-large
    font-size: v("size-medium")
  .icon
    &:first-child:not(:last-child)
      +ltr-property("margin-left", -0.375em)
      +ltr-property("margin-right", 0.1875em)
    &:last-child:not(:first-child)
      +ltr-property("margin-left", 0.1875em)
      +ltr-property("margin-right", -0.375em)
    &:first-child:last-child
      +ltr-property("margin-left", -0.375em)
      +ltr-property("margin-right", -0.375em)
  // Modifiers
  &.is-delete
    +ltr-property("margin-left", v("tag-delete-margin"))
    padding: 0
    position: relative
    width: 2em
    &::before,
    &::after
      background-color: currentColor
      content: ""
      display: block
      left: 50%
      position: absolute
      top: 50%
      transform: translateX(-50%) translateY(-50%) rotate(45deg)
      transform-origin: center center
    &::before
      height: 1px
      width: 50%
    &::after
      height: 50%
      width: 1px
    &:hover,
    &:focus
      background-color: vDarken("tag-background-color",  5%)
    &:active
      background-color: vDarken("tag-background-color",  10%)
  &.is-rounded
    border-radius: v("radius-rounded")

a.tag
  &:hover
    text-decoration: underline
