@use "mixins/button";
@use "mixins/shadow";
@use "variables";

@use "sass:color";

// Buttons
.btn {
  appearance: none;
  background: variables.$bg-color-light;
  border: variables.$border-width solid variables.$primary-color;
  border-radius: variables.$border-radius;
  color: variables.$primary-color;
  cursor: pointer;
  display: inline-block;
  font-size: variables.$font-size;
  height: variables.$control-size;
  line-height: variables.$line-height;
  outline: none;
  padding: variables.$control-padding-y variables.$control-padding-x;
  text-align: center;
  text-decoration: none;
  transition: background .2s, border .2s, box-shadow .2s, color .2s;
  user-select: none;
  vertical-align: middle;
  white-space: nowrap;
  &:focus {
    @include shadow.control-shadow();
  }
  &:focus,
  &:hover {
    background: variables.$secondary-color;
    border-color: variables.$primary-color-dark;
    text-decoration: none;
  }
  &:active,
  &.active {
    background: variables.$primary-color-dark;
    border-color: color.adjust(variables.$primary-color-dark, $lightness: -5%, $space: hsl);
    color: variables.$light-color;
    text-decoration: none;
    &.loading {
      &::after {
        border-bottom-color: variables.$light-color;
        border-left-color: variables.$light-color;
      }
    }
  }
  &[disabled],
  &:disabled,
  &.disabled {
    cursor: default;
    opacity: .5;
    pointer-events: none;
  }

  // Button Primary
  &.btn-primary {
    background: variables.$primary-color;
    border-color: variables.$primary-color-dark;
    color: variables.$light-color;
    &:focus,
    &:hover {
      background: color.adjust(variables.$primary-color-dark, $lightness: -2%, $space: hsl);
      border-color: color.adjust(variables.$primary-color-dark, $lightness: -5%, $space: hsl);
      color: variables.$light-color;
    }
    &:active,
    &.active {
      background: color.adjust(variables.$primary-color-dark, $lightness: -4%, $space: hsl);
      border-color: color.adjust(variables.$primary-color-dark, $lightness: -7%, $space: hsl);
      color: variables.$light-color;
    }
    &.loading {
      &::after {
        border-bottom-color: variables.$light-color;
        border-left-color: variables.$light-color;
      }
    }
  }

  // Button Colors
  &.btn-success {
    @include button.button-variant(variables.$success-color);
  }

  &.btn-error {
    @include button.button-variant(variables.$error-color);
  }

  // Button Link
  &.btn-link {
    background: transparent;
    border-color: transparent;
    color: variables.$link-color;
    &:focus,
    &:hover,
    &:active,
    &.active {
      color: variables.$link-color-dark;
    }
  }

  // Button Sizes
  &.btn-sm {
    font-size: variables.$font-size-sm;
    height: variables.$control-size-sm;
    padding: variables.$control-padding-y-sm variables.$control-padding-x-sm;
  }

  &.btn-lg {
    font-size: variables.$font-size-lg;
    height: variables.$control-size-lg;
    padding: variables.$control-padding-y-lg variables.$control-padding-x-lg;
  }

  // Button Block
  &.btn-block {
    display: block;
    width: 100%;
  }

  // Button Action
  &.btn-action {
    width: variables.$control-size;
    padding-left: 0;
    padding-right: 0;

    &.btn-sm {
      width: variables.$control-size-sm;
    }

    &.btn-lg {
      width: variables.$control-size-lg;
    }
  }

  // Button Clear
  &.btn-clear {
    background: transparent;
    border: 0;
    color: currentColor;
    height: variables.$unit-5;
    line-height: variables.$unit-4;
    margin-left: variables.$unit-1;
    margin-right: -2px;
    opacity: 1;
    padding: variables.$unit-h;
    text-decoration: none;
    width: variables.$unit-5;

    &:focus,
    &:hover {
      background: rgba(variables.$bg-color, .5);
      opacity: .95;
    }

    &::before {
      content: "\2715";
    }
  }
}

// Button groups
.btn-group {
  display: inline-flex;
  flex-wrap: wrap;

  .btn {
    flex: 1 0 auto;
    &:first-child:not(:last-child) {
      border-bottom-right-radius: 0;
      border-top-right-radius: 0;
    }
    &:not(:first-child):not(:last-child) {
      border-radius: 0;
      margin-left: -(variables.$border-width);
    }
    &:last-child:not(:first-child) {
      border-bottom-left-radius: 0;
      border-top-left-radius: 0;
      margin-left: -(variables.$border-width);
    }
    &:focus,
    &:hover,
    &:active,
    &.active {
      z-index: variables.$zindex-0;
    }
  }

  &.btn-group-block {
    display: flex;

    .btn {
      flex: 1 0 0;
    }
  }
}
