@import "../../assets/scss/main.scss";

$boxShadowColor: rgba(11, 17, 37, 0.5);
$minWidth: 128px;

@mixin buttonPadding {
  height: 40px;
  max-height: 40px;
  min-height: 40px;
  padding: 10px 16px;
  &.outlineStyle {
    //css border bug
    padding: 9px 15px;
  }
  @include verySmall-block {

  }

  &.small {
    height: 32px;
    max-height: 32px;
    min-height: 32px;
    padding: 6px 16px;

    &.outlineStyle {
      //css border bug
      padding: 5px 15px;
    }
  }
  &.large {
    height: 58px;
    max-height: 58px;
    min-height: 58px;
    padding: 20px 16px;

    &.outlineStyle {
      //css border bug
      padding: 19px 15px;
    }
  }

  &.fab {
    padding: 8px;
    height: 40px;
    max-height: 40px;
    min-height: 40px;
    width: 40px;
    max-width: 40px;
    min-width: 40px;

    &.small {
      height: 32px;
      max-height: 32px;
      min-height: 32px;
      padding: 4px;
      width: 32px;
      max-width: 32px;
      min-width: 32px;
    }

    &.outlineStyle {
      padding: 7px;
    }
  }
}

@mixin defaultIcon {
  &::v-deep {
    svg {
      * {
        &[stroke] {
          stroke: var(--text-color) !important;
        }

        &[fill] {
          fill: var(--text-color) !important;
        }
      }
    }
  }
}

@mixin darkIcon {
  &:not(.fab) {
    &::v-deep {
      svg {
        * {
          &[stroke] {
            stroke: $gray1000;
          }

          &[fill] {
            fill: $gray1000;
          }
        }
      }

      .svgIcon {
        &.ignoreWhite {
          svg {
            * {
              &[stroke] {
                stroke: var(--text-color);
              }

              &[fill] {
                fill: var(--text-color);
              }
            }
          }
        }
      }
    }
  }
}

@mixin notFilledButtonDisabledIcon {
  &::v-deep {
    svg {
      * {
        &[stroke] {
          stroke: $gray60 !important;
        }

        &[fill] {
          fill: $gray60 !important;
        }
      }
    }
  }
}

@mixin filledButtonDisabledIcon {
  &::v-deep {
    svg {
      * {
        &[stroke] {
          stroke: $white !important;
        }

        &[fill] {
          fill: $white !important;
        }
      }
    }
  }
}

.buttonComponent {
  letter-spacing: 0.5px;
  @include headline;
  font-weight: $bold;
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  @include buttonPadding;
  border-radius: $borderRadius;
  cursor: pointer;
  border: none;
  box-sizing: border-box;
  -moz-user-select: none;
  -khtml-user-select: none;
  user-select: none;
  max-width: 100%;
  @include defaultIcon;

  &.minWidth {
    min-width: $minWidth;
  }

  &.outlineStyle, &.transparentStyle {
    @include darkIcon;

    .buttonComponent {
      &__counter {
        color: $white;
      }
    }
  }

  &.outlineStyle {
    border: 1px solid $gray60;
  }

  &__wrapper {
    width: auto;
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    flex-shrink: 0;

    &:not(.buttonComponent__disabled) {
      .buttonComponent {
        &:hover {
          &:not(.transparentStyle):not(.outlineStyle):not(:active) {
            background: $hoverEffect;
          }

          &.transparentStyle, &.outlineStyle {
            background: $gray10 !important;
          }
        }

        &:active {
          box-shadow: inset 0 1px 4px $boxShadowColor;

          &.outlineStyle {
            border-color: $boxShadowColor;
          }
        }
      }
    }

    &.buttonComponent {
      &__disabled {
        .buttonComponent {
          background: $gray40 !important;
          color: $white !important;
          pointer-events: none !important;
          @include filledButtonDisabledIcon;

          &__counter {
            background: $white !important;
            color: $gray40 !important;
          }

          &.outlineStyle, &.transparentStyle {
            color: $gray60 !important;
            @include notFilledButtonDisabledIcon;

            .buttonComponent {
              &__counter {
                background: $gray60 !important;
                color: $white !important;
              }
            }
          }

          &.outlineStyle {
            background: $gray10 !important;
            border-color: $gray40;
          }

          &.transparentStyle {
            background: transparent !important;
          }
        }
      }
    }

    &.blockButton {
      width: 100%;

      .buttonComponent {
        width: 100%;
      }
    }

    &.bottomMargin {
      margin-bottom: 20px;
    }
  }

  &__title {
    font-family: inherit;
    font-size: 16px;
    line-height: 20px;
    text-align: center;
  }

  &__icon {
    &-before {
      margin-right: 8px;
      display: flex;
      align-items: center;
    }
  }

  &__counter {
    background: var(--text-color);
    color: var(--background-color);
    @include headline;
    font-weight: $medium;
    min-height: 24px;
    min-width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 200px;
    margin-left: 8px;
    padding: 2px 6px;
  }

  &__input {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 22;
    opacity: 0;
    cursor: pointer;
  }

  &__loading {
    margin-right: 8px;
    display: flex;
    align-items: center;
    animation: spinner .6s linear infinite;
  }

  &.fab {
    .buttonComponent__icon-before {
      margin-right: 0;
    }
  }

  &:not(.fab) {
    @include verySmall-block {
      width: 100%;
      .buttonComponent {
        width: 100%;
      }
    }
  }
}

@keyframes spinner {
  to {
    transform: rotate(360deg);
  }
}