/**Variable**/
@import './helpers/mixin.scss';

$btnThemeList: (
  (
    name: "primary",
    textColor: $vhb-primary-color,
    btnColor: #fff,
    btnBackground: $vhb-primary-color
  ),
  (
    name: "success",
    textColor: $vhb-success-color,
    btnColor: #fff,
    btnBackground: $vhb-success-color
  ),
  (
    name: "info",
    textColor: $vhb-info-color,
    btnColor: #fff,
    btnBackground: $vhb-info-color
  ),
  (
    name: "warning",
    textColor: $vhb-warning-color,
    btnColor: #fff,
    btnBackground: $vhb-warning-color
  ),
  (
    name: "danger",
    textColor: $vhb-danger-color,
    btnColor: #fff,
    btnBackground: $vhb-danger-color
  ),
  (
    name: "perfect",
    textColor: $vhb-table-header-background-color,
    btnColor: $vhb-font-color,
    btnBackground: $vhb-table-header-background-color
  )
);

.vhb-button {
  position: relative;
  text-align: center;
  background-color: $vhb-button-default-background-color;
  outline: 0;
  font-size: $vhb-font-size;
  max-width: $vhb-button-max-width;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  white-space: nowrap;
  user-select: none;
  appearance: none;
  @include animatTransition(border, .2s);
  &:not(.is--disabled) {
    color: $vhb-font-color;
    cursor: pointer;
    .vhb-button--icon {
      &.vhb-icon--zoomin {
        border-color: $vhb-font-color;
      }
    }
  }
  &.is--loading {
    cursor: progress;
    &:before {
      content: "";
      position: absolute;
      left: -1px;
      top: -1px;
      right: -1px;
      bottom: -1px;
      border-radius: inherit;
      background-color: hsla(0,0%,100%,.35);
      pointer-events: none;
    }
  }
  &.is--disabled {
    color: $vhb-disabled-color;
    .vhb-button--icon {
      &.vhb-icon--zoomin {
        border-color: $vhb-disabled-color;
      }
    }
    &:not(.is--loading) {
      cursor: no-drop;
    }
  }
  &.type--text {
    text-decoration: none;
    border: 0;
    padding: 0.1em 0.5em;
    background-color: transparent;
    &:not(.is--disabled) {
      &:focus {
        box-shadow: 0 0 0.25em 0 $vhb-primary-color;
      }
      &:hover {
        color: lighten($vhb-primary-color, 10%);
      }
    }
    @for $index from 0 to length($btnThemeList) {
      $item: nth($btnThemeList, $index + 1);
      $textColor: map-get($item, textColor);
      &.theme--#{map-get($item, name)} {
        color: $textColor;
        &:not(.is--disabled) {
          &:hover {
            color: lighten($textColor, 10%);
          }
        }
        &.is--disabled {
          color: lighten($textColor, 20%);
        }
      }
    }
  }
  &.type--button {
    font-family: inherit;
    height: $vhb-button-height-default;
    line-height: 1;
    border: 1px solid $vhb-input-border-color;
    &.is--round {
      border-radius: $vhb-button-round-border-radius-default;
    }
    &:not(.is--round) {
      border-radius: $vhb-border-radius;
    }
    &.is--circle {
      padding: 0 0.5em;
      min-width: $vhb-button-height-default;
      border-radius: 50%;
    }
    &:not(.is--circle) {
      padding: 0 1em;
    }
    &:not(.is--disabled) {
      &:hover {
        color: lighten($vhb-primary-color, 6%);
        .vhb-button--icon {
          &.vhb-icon--zoomin {
            border-color: lighten($vhb-primary-color, 6%);
          }
        }
      }
      &:focus {
        border-color: $vhb-primary-color;
        box-shadow: 0 0 0.25em 0 $vhb-primary-color;
      }
      &:active {
        color: darken($vhb-primary-color, 3%);
        border-color: darken($vhb-primary-color, 3%);
        background-color: darken($vhb-button-default-background-color, 3%);
        .vhb-button--icon {
          &.vhb-icon--zoomin {
            background-color: darken($vhb-button-default-background-color, 3%);
          }
          &.vhb-icon--zoomout {
            &:after {
              background-color: darken($vhb-button-default-background-color, 3%);
            }
          }
        }
      }
    }
    @for $index from 0 to length($btnThemeList) {
      $item: nth($btnThemeList, $index + 1);
      $btnColor: map-get($item, btnColor);
      $btnBackground: map-get($item, btnBackground);
      &.theme--#{map-get($item, name)} {
        color: $btnColor;
        .vhb-button--icon {
          &.vhb-icon--zoomin {
            border-color: $btnColor;
          }
        }
        &:not(.is--disabled) {
          border-color: $btnBackground;
          background-color: $btnBackground;
          &:hover {
            color: $btnColor;
            background-color: lighten($btnBackground, 6%);
            border-color: lighten($btnBackground, 6%);
            .vhb-button--icon {
              &.vhb-icon--zoomin {
                border-color: lighten($btnBackground, 6%);
              }
            }
          }
          &:active {
            color: $btnColor;
            background-color: darken($btnBackground, 3%);
            border-color: darken($btnBackground, 3%);
            &.vhb-icon--zoomin {
              background-color: darken($btnBackground, 3%);
            }
            &.vhb-icon--zoomout {
              &:after {
                background-color: darken($btnBackground, 3%);
              }
            }
          }
        }
        &.is--disabled {
          border-color: lighten($btnBackground, 20%);
          background-color: lighten($btnBackground, 20%);
        }
        &.is--loading {
          border-color: $btnBackground;
          background-color: $btnBackground;
        }
      }
    }
  }
  &.size--medium {
    font-size: $vhb-font-size-medium;
    &.type--button {
      height: $vhb-button-height-medium;
      &.is--circle {
        min-width: $vhb-button-height-medium;
      }
      &.is--round {
        border-radius: $vhb-button-round-border-radius-medium;
      }
    }
    .vhb-button--loading-icon,
    .vhb-button--icon {
      min-width: $vhb-font-size-medium;
    }
  }
  &.size--small {
    font-size: $vhb-font-size-small;
    &.type--button {
      height: $vhb-button-height-small;
      &.is--circle {
        min-width: $vhb-button-height-small;
      }
      &.is--round {
        border-radius: $vhb-button-round-border-radius-small;
      }
    }
    .vhb-button--loading-icon,
    .vhb-button--icon {
      min-width: $vhb-font-size-small;
    }
  }
  &.size--mini {
    font-size: $vhb-font-size-mini;
    &.type--button {
      height: $vhb-button-height-mini;
      &.is--circle {
        min-width: $vhb-button-height-mini;
      }
      &.is--round {
        border-radius: $vhb-button-round-border-radius-mini;
      }
    }
    .vhb-button--loading-icon,
    .vhb-button--icon {
      min-width: $vhb-font-size-mini;
    }
  }
}
.vhb-input,
.vhb-button {
  &+.vhb-button,
  &+.vhb-button--dropdown {
    margin-left: 12px;
  }
}
.vhb-button--loading-icon,
.vhb-button--icon,
.vhb-button--content {
  vertical-align: middle;
}
.vhb-button--loading-icon,
.vhb-button--icon {
  min-width: $vhb-font-size;
  &+.vhb-button--content {
    margin-left: 4px;
  }
}
.vhb-button--wrapper,
.vhb-button--dropdown {
  display: inline-block;
}
.vhb-button--dropdown {
  position: relative;
  &+.vhb-button,
  &+.vhb-button--dropdown {
    margin-left: 12px;
  }
  & > .vhb-button {
    &.type--button {
      @for $index from 0 to length($btnThemeList) {
        $item: nth($btnThemeList, $index + 1);
        $btnColor: map-get($item, btnColor);
        &.theme--#{map-get($item, name)} {
          color: $btnColor;
        }
      }
    }
  }
  &.is--active {
    & > .vhb-button {
      &:not(.is--disabled) {
        color: lighten($vhb-primary-color, 6%);
      }
      &.type--text {
        @for $index from 0 to length($btnThemeList) {
          $item: nth($btnThemeList, $index + 1);
          $textColor: map-get($item, textColor);
          &.theme--#{map-get($item, name)} {
            color: lighten($textColor, 10%);
          }
        }
      }
      &.type--button {
        @for $index from 0 to length($btnThemeList) {
          $item: nth($btnThemeList, $index + 1);
          $btnColor: map-get($item, btnColor);
          $btnBackground: map-get($item, btnBackground);
          &.theme--#{map-get($item, name)} {
            color: $btnColor;
            background-color: lighten($btnBackground, 6%);
            border-color: lighten($btnBackground, 6%);
          }
        }
      }
    }
    .vhb-button--dropdown-arrow {
      transform: rotate(180deg);
    }
  }
}

.vhb-button--dropdown-arrow {
  font-size: 12px;
  margin-left: 4px;
  @include animatTransition(transform, .2s);
}

.vhb-button--dropdown-panel {
  display: none;
  position: absolute;
  right: 0;
  padding: 4px 0;
  &.animat--leave {
    display: block;
    opacity: 0;
    transform: scaleY(0.5);
    transition: transform .3s cubic-bezier(.23,1,.32,1), opacity .3s cubic-bezier(.23,1,.32,1);
    transform-origin: center top;
    backface-visibility: hidden;
    transform-style: preserve-3d;
    &[placement="top"] {
      transform-origin: center bottom;
    }
  }
  &.animat--enter {
    opacity: 1;
    transform: scaleY(1);
  }
}
.vhb-button--dropdown-wrapper {
  padding: 5px;
  background-color: $vhb-button-dropdown-panel-background-color;
  border-radius: $vhb-border-radius;
  border: 1px solid $vhb-input-border-color;
  box-shadow: 0 1px 6px rgba(0,0,0,.2);
  & > .vhb-button {
    margin-left: 0;
    margin-top: 0.4em;
    display: block;
    width: 100%;
    border: 0;
    &.type--text {
      padding: 2px 8px;
    }
    &:first-child {
      margin-top: 0;
    }
    &:last-child {
      margin-bottom: 0;
    }
  }
}