@import '../colors';
@import '../mixins';

$mobile-border-radius: 4px;
$desktop-border-radius: 6px;

$border-radius: 16px;

.chips-component {
  align-items: center;
  background-color: $color-N0;
  color: $color-N800;
  cursor: pointer;
  display: inline-flex;
  margin: 4px;
  position: relative;
  user-select: none;
  transition: 0.5s ease-out background-color;
  overscroll-behavior-x: contain;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  border-radius: $border-radius;

  // Fix glitch border when tapped
  &::after {
    content: '';
    display: block;
    position: absolute;
    left: 0px;
    right: 0px;
    top: 0px;
    bottom: 0px;
    border: solid 1px $color-N200;
    z-index: 2;
    transition: 0.5s ease-out border-color;
    border-radius: $border-radius;
  }

  &.mobile {
    padding: 6px 12px;

    &.collapsed {
      .icon-name {
        margin: 0;
      }
    }
  }

  &.desktop {
    padding: 8px 12px;

    &.collapsed {
      padding: 10px 12px;

      .icon-name {
        margin: 0;
      }
    }

    .badge {
      small {
        @include font-size-small;
      }
    }
  }

  .ripple-wrapper {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    overflow: hidden;
    z-index: 1;

    .ripple {
      width: 20px;
      height: 20px;
      top: calc(50% - 10px);
      left: calc(50% - 10px);
      position: absolute;
      background-color: $color-N0;
      display: block;
      content: '';
      border-radius: 9999px;
      opacity: 1;
      animation: 1s ease 1 forwards ripple-effect;
    }
  }

  .chip-label {
    opacity: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
    position: relative;
    z-index: 2;
  }

  img {
    margin-right: 8px;
    object-fit: cover;
    height: 16px;
    width: 16px;
    z-index: 2;

    &.right-icon {
      margin-right: 0;
      margin-left: 8px;
    }
  }

  .icon-name,
  i {
    color: $color-N800;
    margin-right: 6px;
    z-index: 2;

    &.right-icon {
      margin-right: 0;
      margin-left: 6px;
    }
  }

  &.tag {
    img {
      margin-right: 4px;

      &.right-icon {
        margin-right: 0;
        margin-left: 4px;
      }
    }

    .badge {
      display: inline-flex;
      margin-left: 5px;
      z-index: 2;
    }
  }

  &.active {
    background-color: $color-B100;
    color: $color-B400;
    transition: 0.5s ease-out all;

    &.action {
      &::after {
        border-color: $color-N200;
      }
    }

    .icon-name {
      color: $color-B400;
    }

    .ripple-wrapper {
      .ripple {
        background-color: $color-B100;
      }
    }
  }

  &.inverted {
    background-color: rgba(255, 255, 255, 0.4);

    .chip-label {
      color: $color-N0;
    }

    &.active {
      background-color: $color-N0;
      border-color: transparent;

      .chip-label {
        color: $color-B400;
      }

      .ripple-wrapper {
        .ripple {
          background-color: $color-B100;
        }
      }
    }
  }

  &.filtered {
    &.active {
      i {
        color: $color-B400;
        margin-right: 6px;
      }
    }
  }

  &.action {
    background-color: $color-N0;
    color: $color-N800;

    &.active {
      background-color: $color-N0;
      color: $color-N800;

      i {
        color: $color-N800;
      }
    }

    &.active {
      &:before {
        background-color: $color-G500;
        border: solid 1.5px $color-N0;
        border-radius: 50%;
        content: '';
        height: 11px;
        position: absolute;
        right: 0;
        top: 0;
        width: 11px;
        transform: translate(2px, -4px);
        z-index: 3;
      }
    }

    &.inverted {
      &.active i {
        color: $color-B400;
      }
    }
  }

  &.collapsed {
    .chip-label {
      z-index: 1;
    }

    i,
    img,
    .badge {
      margin: 0;
    }

    .badge {
      display: none;
    }

    .chip-label,
    .badge {
      max-width: 0;
      animation: animate-filter-collapse 250ms ease 0s alternate;
    }

    i,
    img {
      position: relative;
      z-index: 2;
      margin: 0;
    }

    &.active {
      i {
        margin: 0;
      }
    }
  }

  &.filter-action {
    i,
    img {
      position: relative;
      transition: margin 280ms ease 0s;
      z-index: 2;
    }

    .chip-label {
      z-index: 1;
    }

    img {
      margin-right: 4px;
    }

    .badge {
      margin-left: 5px;
    }

    i {
      margin-right: 6px;
    }

    .chip-label,
    .badge {
      max-width: 100%;
      animation: animate-filter 250ms ease 0s alternate;
    }
  }

  &.disable {
    background: $color-N100;
    border-color: $color-N100;
    color: $color-N400;
    cursor: not-allowed;
  }
}

.chips-component-wrapper {
  white-space: nowrap;
  position: relative;

  .no-scroll {
    flex-wrap: wrap;

    .chips-component {
      margin-bottom: 10px;
    }
  }

  .chip-flex {
    display: flex;
    width: 100%;
  }

  .sticky {
    position: relative;
    margin-left: 0;
    display: flex;
    z-index: 9;
  }

  .multiple-chip {
    display: flex;
    overflow-x: auto;

    &::-webkit-scrollbar {
      display: none;
    }
  }
}

@keyframes ripple-effect {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(10);
    opacity: 0.375;
  }
  100% {
    transform: scale(35);
    opacity: 0;
  }
}

@keyframes animate-filter-collapse {
  0% {
    max-width: 100%;
    opacity: 1;
    margin-left: 0;
  }
  50% {
    max-width: 50%;
    opacity: 0.5;
    margin-left: -10px;
  }
  100% {
    max-width: 0;
    opacity: 0;
    margin-left: -16px;
  }
}

@keyframes animate-filter {
  0% {
    max-width: 0;
    opacity: 0;
    margin-left: -16px;
  }
  50% {
    max-width: 50%;
    opacity: 0.5;
    margin-left: -10px;
  }
  100% {
    max-width: 100%;
    opacity: 1;
    margin-left: 0;
  }
}
