@use 'mixins/mixins' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

@keyframes btnload {
  100% {
    transform: rotate(360deg);
  }
}
@keyframes btnupload {
  0% {
    transform: translate(0, 110%);
  }
  100% {
    transform: translate(0, -110%);
  }
}

@include b(button) {
  @include set-component-var('', $button);
}

@include b(button) {
  @include flex(center, center);
  // margin: getCssVar(margin);
  margin-left: getCssVar(margin);
  border-radius: getCssVar(border-radius);
  transition: getCssVar(transition-ease);
  border: 0;
  padding: 0;
  position: relative;
  z-index: 1;
  overflow: hidden;
  user-select: none;
  outline: none;
  font-size: 0.8rem;

  &.#{$namespace}-component--dark {
    @include m(transparent) {
      color: getColor('text') !important;
    }
  }
  //
  &--fff {
    &:focus {
      color: rgba(30, 30, 30, 1) !important;
    }
  }
  &:focus-visible {
    outline: 2px solid getColor(primary, 0.7);
    outline-offset: 1px;
  }
  @include e(content) {
    padding: getCssVar(padding);
    width: 100%;
    @include flex(center, center);
  }
  @include pseudo(disabled) {
    pointer-events: none;
    opacity: 0.35;
  }
  @include m(animate) {
    &:not(.#{$namespace}-button--animate-inactive) {
      @include e(content) {
        transition: transform 0.25s ease;
        i {
          font-size: 1.15rem;
        }
      }
      @include pseudo(hover) {
        @include e(content) {
          transform: translate(-100%);
        }
        @include e(animate) {
          transform: translate(0%);
        }
      }
      &.#{$namespace}-button {
        @include m(animate) {
          &-vertical {
            @include pseudo(hover) {
              @include e(content) {
                transform: translate(0, -100%) !important;
                opacity: 0;
              }
              @include e(animate) {
                transform: translate(0%) !important;
              }
            }
          }
          &-scale {
            @include pseudo(hover) {
              @include e(content) {
                transform: scale(1.4) !important;
                opacity: 0;
              }
              @include e(animate) {
                opacity: 1;
                transform: scale(1);
              }
            }
          }
          &-rotate {
            @include pseudo(hover) {
              @include e(content) {
                transform: rotate(180deg) !important;
                opacity: 0;
              }
              @include e(animate) {
                opacity: 1;
                transform: rotate(0);
              }
            }
          }
        }
      }
    }
  }

  @include e(animate) {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    @include flex(center, center);
    transition: transform 0.25s ease;
    transform: translate(100%);
    pointer-events: none;

    @include m(vertical) {
      transform: translate(0, 100%);
    }
    @include m(scale) {
      transform: scale(0.5);
      opacity: 0;
    }
    @include m(rotate) {
      transform: rotate(-180deg);
      opacity: 0;
    }
  }

  @include m(block) {
    width: 100%;
    display: block;
  }
  @include m(upload) {
    @include pseudo(after) {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: getColor(color, 0.4);
      z-index: 1200;
      animation: btnupload 0.7s ease infinite;
      box-sizing: border-box;
    }
  }
  @include m(loading) {
    pointer-events: none;
    user-select: none;
  }
  @include e(loading) {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;

    @include pseudo(before) {
      content: '';
      @include absolute-full;
      background-color: getColor(color, 0.68);
    }

    .#{$namespace}-icon-loading {
      --#{$namespace}-color: 255, 255, 255;
      transform: scale(0.4);
    }
  }

  // SIZE -----
  @include e(size) {
    @include m(xl) {
      border-radius: 20px;
      @include e(content) {
        padding: 15px 20px;
        font-size: 1.1rem;
      }
    }
    @include m(large) {
      font-size: 1rem;
      border-radius: 15px;
      @include e(content) {
        padding: 10px 15px;
      }
    }
    @include m(small) {
      font-size: 0.75rem;
      border-radius: 9px;
      @include e(content) {
        padding: 5px 10px;
      }
    }
    @include m(mini) {
      font-size: 0.6rem;
      border-radius: 7px;
      @include e(content) {
        padding: 3px 8px;
      }
    }
  }
  // SIZE - CLOSE -----
  @include m(circle) {
    border-radius: 25px;
  }
  @include m(square) {
    border-radius: 0;
  }
  @include m(icon) {
    @include flex(center, center);

    @include e(content) {
      padding: 8px 8px;
    }
    i {
      font-size: 1.15rem;
    }
  }
}

// Type Button Style
@include b(button) {
  @include m(default) {
    background: getColor(color);
    color: #fff;
    &.#{$namespace}-button--active {
      box-shadow: 0 10px 20px -10px getColor(color);
      transform: translate(0, -3px);
    }
    &:hover {
      box-shadow: 0 10px 20px -10px getColor(color);
      transform: translate(0, -3px);
    }
  }
  @include m(flat) {
    background: getColor(color, 0.15);
    color: getColor(color);
    &.#{$namespace}-component--dark {
      color: getColor(text);
    }
    &:hover {
      background: getColor(color, 0.25);
    }
    &:focus {
      color: #fff;
      background: getColor(color);
      transition: getCssVar(transition-ease), background 0.25s ease 0.25s;
    }
    &.#{$namespace}-button--active {
      background: getColor(color);
      color: #fff;
    }
  }
  @include m(floating) {
    background: getColor(color);
    color: #fff;
    box-shadow: 0 8px 20px -6px getColor(color);
    transform: translate(0, -3px);
    &:hover {
      box-shadow: 0 8px 20px -6px getColor(color);
      transform: translate(0, -6px);
    }
    &:focus {
      transform: translate(0, 0);
      box-shadow: 0 0 0 0 getColor(color);
    }
    &.#{$namespace}-button--active {
      transform: translate(0, 0);
      box-shadow: 0 0 0 0 getColor(color);
    }
  }
  @include m(border) {
    background: getColor(color, 0);
    color: getColor(color);
    &:before {
      content: '';
      border: 2px solid getColor(color, 1);
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border-radius: inherit;
      background: transparent;
      pointer-events: none;
      transition: getCssVar(transition-ease);
      box-sizing: border-box;
    }
    &:hover {
      &:before {
        border: 2px solid getColor(color, 0.5);
      }
    }
    &:focus {
      color: #fff;
      background: getColor(color);
    }
    &.#{$namespace}-button--active {
      background: getColor(color);
      color: #fff;
    }
  }
  @include m(gradient) {
    background: getColor('color');
    color: #fff;
    overflow: hidden;
    &.#{$namespace}-component--primary,
    &.#{$namespace}-component--success {
      &::before {
        filter: hue-rotate(40deg);
      }
    }
    &::before {
      content: '';
      background: linear-gradient(
        30deg,
        getColor('color', 0) 33%,
        getColor('color') 100%
      );
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border-radius: inherit;
      pointer-events: none;
      transition: all 0.4s ease;
      z-index: -1;
      filter: hue-rotate(-40deg);
      box-sizing: border-box;
    }

    &:hover {
      transform: translate(0, -3px);
      box-shadow: 0 10px 20px -10px getColor('color', 0.7);
      &::before {
        opacity: 0;
      }
    }
    &.#{$namespace}-button--active {
      transform: translate(0, -3px);
      box-shadow: 0 10px 20px -10px rgba(0, 0, 0, 0.35);
    }
  }
  @include m(relief) {
    background: getColor('color');
    color: #fff;
    overflow: hidden;
    transform: translate(0) scale(1, 1);
    @include e(content) {
      transition: getCssVar(transition-ease);
    }
    &.#{$namespace}-button--icon {
      &.#{$namespace}-button--active {
        height: auto;
      }
    }
    &::before {
      content: '';
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: calc(100% - 3px);
      border-radius: inherit;
      pointer-events: none;
      transition: all 0.4s ease;
      z-index: -1;
      filter: contrast(2) grayscale(0.4);
      border-bottom: 3px solid getColor('color');
      box-sizing: border-box;
    }
    &:active {
      transform: translate(0, 1px);
      @include e(content) {
        padding-bottom: 6px;
      }
      &::before {
        border-bottom: 0 solid getColor('color');
      }
    }
    &.#{$namespace}-button--active {
      transform: translate(0, 1px);
      @include e(content) {
        padding-bottom: 6px;
      }
      &::before {
        border-bottom: 0 solid getColor('color');
      }
    }
  }
  @include m(transparent) {
    background: transparent;
    color: getColor('color');
    overflow: hidden;
    &::before {
      content: '';
      background: getColor('color', 0.1);
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border-radius: inherit;
      pointer-events: none;
      transition: getCssVar(transition-ease);
      z-index: -1;
      transform: scale(0.5);
      opacity: 0;
      box-sizing: border-box;
    }
    &:active:not(.#{$namespace}-button--active) {
      &::before {
        transform: scale(0.9) !important;
      }
    }
    &:hover {
      &::before {
        opacity: 1;
        transform: scale(1);
      }
    }
    &.#{$namespace}-button--active {
      &::before {
        background: getColor('color', 0.2);
        opacity: 1;
        transform: scale(1);
      }
    }
  }
  @include m(shadow) {
    background: getColor('background');
    color: getColor('text');
    overflow: hidden;
    box-shadow: 0 0 0 0 rgba(0, 0, 0, getCssVar(shadow-opacity));
    &:active:not(.#{$namespace}-button--active) {
      transform: translate(0, -1px);
      box-shadow: 0 5px 15px 0 rgba(0, 0, 0, getCssVar(shadow-opacity)) !important;
    }
    &:hover {
      transform: translate(0, -3px);
      box-shadow: 0 8px 25px 0 rgba(0, 0, 0, getCssVar(shadow-opacity));
    }
    &.#{$namespace}-button--active {
      transform: translate(0, -3px);
      box-shadow: 0 8px 25px 0 rgba(0, 0, 0, getCssVar(shadow-opacity));
    }
  }
}
