$button-sizes: (
  small: (
    class-name: 'small',
    font-size: 0.75,
    padding: 0.5,
    transform: none,
    weight: 300
  ),
  regular: (
    class-name: 'regular',
    font-size: 1,
    padding: 1,
    transform: none,
    weight: 300
  ),
  medium: (
    class-name: 'medium',
    font-size: 1,
    padding: 1,
    transform: uppercase,
    weight: 500
  ),
  large: (
    class-name: 'large',
    font-size: 1,
    padding: 1.5,
    transform: uppercase,
    weight: 500
  )
);

// Button Sizes // --------------------
@each $item, $size in $button-sizes {
  $class: map-get($size, class-name);
  $font-size: map-get($size, font-size);
  $padding: map-get($size, padding);
  $transform: map-get($size, transform);
  $weight: map-get($size, weight);

  .btn--#{$class} {
    font-size: #{$font-size}em;
    padding: #{$padding}em #{$padding * 1.5}em;
    text-transform: $transform;
    font-weight: $weight;

    @if $transform == 'uppercase' {
      letter-spacing: 1px;
    }
  }
}

$button-fills: (
  outline: (
    class-name: 'outline',
    border-width: 1,
  ),
  solid: (
    class-name: 'solid',
    border-width: 0
  )
);

.btn {
  -webkit-appearance: none;
  border-radius: 3px;
  cursor: hand;
  cursor: pointer;
  outline: 0;
  text-decoration: none;
  transition: all 0.1s ease-in-out;
  user-select: none;
  white-space: nowrap;

  .icon,
  &__icon {
    transition: fill 0.2s;
    vertical-align: bottom;
    max-width: 1em;
    max-height: 1em;
  }

  &__icon {
    &--before {
      margin-left: 0 !important;
      margin-right: 1em;
    }

    &--after {
      margin-left: 1em;
      margin-right: 0 !important;
    }
  }

  .liquid-child {
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }

  &:focus {
    box-shadow: none;
    outline: 0;
  }

  &:hover {
    .icon {
      fill: $gray;
    }
  }

  &[disabled='true'] {
    opacity: 0.4;

    .icon {
      fill: $gray;
    }

    &:hover {
      .icon {
        fill: $gray;
      }
    }
  }
}

.fixed__buttons {
  bottom: 51px;
  display: flex;
  padding: 1em;
  position: fixed;
  width: 100%;

  button {
    flex: 1;
  }

  &--white {
    background: $white;
    box-shadow: 0 0 25px 15px $white;
  }

  &--many {
    button {
      border-radius: 0;

      &:first-child {
        border-top-left-radius: 3px;
        border-bottom-left-radius: 3px;
      }

      &:last-child {
        border-top-right-radius: 3px;
        border-bottom-right-radius: 3px;
      }
    }
  }
}

.has-fixed-buttons {
  margin-bottom: 5em;
}

.btn {
  // Types
  &__toggle {
    background: palette(gray, x-dark);
    border: none;
    color: palette(gray, base);
    border-radius: 0;
  }

  &--reset {
    text-align: left;
    text-transform: none;
    font-size: 0.875em;
    letter-spacing: 0;
    font-weight: 300;
  }

  &--close-modal {
    position: absolute;
    top: 0;
    right: 0;
    transform: translate(50%, -50%);
    border-radius: 300px;
    padding: 0.3em 0.4em;

    .icon {
      fill: $white;
    }
  }

  &--full {
    width: 100%;
    display: block;
    text-align: center;

    .liquid-child {
      justify-content: center;
    }
  }

  &--no-bg {
    background: none;
    border: none;

    &.link {
      color: palette(blue);
    }
  }

  &--inline-input {
    position: absolute;
    right: 0;
    left: inherit;
    top: 32px;
  }

  &--back {
    top: 9px;
  }

  &--search {
    position: absolute;
    top: 9px;
    right: 0;
    z-index: $zIndex-10;

    svg {
      fill: $white;
    }
  }
}

.full__btns {
  padding: 0;
  display: flex;

  .btn {
    flex: 1;
    border-radius: 0;
  }
}

@each $theme, $color in $ui-colors {
  .btn--#{$theme} {
    border: none;
    background: $color;

    .liquid-child::selection {
      background: $color;
      color: $white;
    }

    &:hover {
      color: rgba(white, 0.6);
    }

    &.btn--active {
      background: darken($color, 5%);
    }

    @if (lightness($color) > 60) {
      color: darken($color, 25%);

      .icon {
        fill: darken($color, 25%);
        // stroke: darken($color, 25%);
      }
    }

    @else {
      color: $white;

      .icon {
        fill: $white;
        // stroke: $white;
      }
    }

    @if $theme == 'off-light' {
      color: palette(gray);

      &.active {
        background: palette(blue);
        color: $white !important;
      }

      .liquid-child::selection {
        color: palette(gray);
      }

      .icon {
        stroke: palette(gray) !important;
      }
    }

    @if $theme == 'link' {
      color: palette(blue) !important;
      background: none;

      .liquid-child::selection {
        color: palette(blue);
      }
    }

    @if $theme == 'transparent' {
      color: palette(blue) !important;

      .liquid-child::selection {
        background: $color;
        color: palette(blue);
      }

      .icon {
        stroke: palette(blue);
      }
    }
  }

  .btn--outline.btn--#{$theme} {
    color: $color;
  }
}

// Button fills
@each $item, $fill in $button-fills {
  $class: map-get($fill, class-name);
  $border-width: map-get($fill, border-width);

  .btn--#{$class} {
    @if $border-width != 0 {
      border: #{$border-width}px solid;
      background: none;
      color: inherit;

      .icon {
        stroke: palette(gray);
      }
    }

    @else {
      border: none;
    }
  }
}

.btn-group {
  display: flex;

  // .btn + .btn {
  //   margin-left: 1em;
  // }

  &--center {
    align-items: center;
    display: flex;
    justify-content: center;
  }

  &--flex-grow {
    .btn {
      flex: 1;
      text-align: center;
    }
  }
}
$spinner-size: 22px;

.async-button {
  .icon {
    height: $spinner-size;
    margin-right: 10px;
    width: $spinner-size;
  }

  &.btn--sm {
    .icon {
      width: 16px;
      height: 16px;
    }
  }

  &.btn--lg {
    .icon {
      height: 32px;
    }
  }
}

.filters {
  .filter-group {
    max-width: 480px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 auto;

    > label {
      margin: 1em auto;
      color: #646567;
    }

    .radio-group {
      display: flex;
      margin-bottom: 1em;

      &__item {
        flex: 1;
        display: flex;
        background: white;

        &:first-child {
          label {
            border-radius: 3px 0 0 3px;
            border-right: none;
          }
        }

        &:last-child {
          label {
            border-radius: 0 3px 3px 0;
            border-left: none;
          }
        }
      }

      &__input {
        display: none;

        &:checked + label {
          background: palette(blue);
          color: $white;
        }
      }

      &__label {
        white-space: nowrap;
        flex: 1;
        text-align: center;
        padding: 1em;
        transition: background 0.2s ease, color 0.2s ease;
        border: 1px solid rgba(black, 0.2);

        &:hover {
          cursor: pointer;
        }
      }
    }
  }
}

.fixed__buttons {
  bottom: 0;

  .has-footer & {
    bottom: 51px;
  }

  &--stacked {
    flex-direction: column;
  }
}

.btn {
  .icon--menu {
    stroke: none;
    max-width: 1.5em;
    max-height: 1.5em;
    margin: 0;
  }

  &:hover {
    .icon--menu {
      fill: $white;
      opacity: 0.7;
    }
  }
}

.link-magenta {
  color: #ec008c;
  font-weight: 500;
}

.btn--magenta {
  background-color: #ec008c;
  color: white;
  border-radius: 2px;
  border: none;
}

.btn--modal--color {
  margin: 0.5em;
  border-radius: 3px;
}

.async-button.btn--lg .icon {
  height: 21px;
}
$offset: 178;
$duration: 1.8s;

@keyframes rotator {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(720deg);
  }
}

@keyframes dash {
  0% {
    stroke-dashoffset: $offset;
  }

  50% {
    stroke-dashoffset: $offset / 4;
    transform: rotate(15deg);
  }

  100% {
    stroke-dashoffset: $offset;
    transform: rotate(360deg);
  }
}

.spinner {
  animation: rotator $duration linear infinite;
  stroke: $white;
}

.path {
  animation: dash $duration ease-in-out infinite;
  stroke-dasharray: $offset;
  stroke-dashoffset: 0;
  stroke-width: 8;
  transform-origin: center;
}
