@import '../../style/var';
@import '../../style/mixins/_hairline';

.hl-button {
  position: relative;
  display: inline-block;
  box-sizing: border-box;
  height: $button-default-height;
  margin: 0;
  padding: 0;
  font-size: $button-default-font-size;
  line-height: $button-default-line-height;
  text-align: center;
  border-radius: $button-border-radius;
  cursor: pointer;
  -webkit-appearance: none;

  &::before {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background-color: $black;
    border: inherit;
    border-color: $black;
    border-radius: inherit; /* inherit parent's border radius */
    transform: translate(-50%, -50%);
    opacity: 0;
    content: ' ';
  }

  &:active::before {
    opacity: 0.1;
  }

  &--disabled {
    cursor: not-allowed;
    opacity: $button-disabled-opacity;
    &::before {
      display: none;
    }
  }

  // type
  &--default {
    color: $button-default-color;
    background-color: $button-default-background-color;
    border: $button-border-width solid $button-default-border-color;
  }

  &--primary {
    color: $button-primary-color;
    background-color: $button-primary-background-color;
    border: $button-border-width solid $button-primary-border-color;
  }

  &--success {
    color: $button-success-color;
    background-color: $button-success-background-color;
    border: $button-border-width solid $button-success-border-color;
  }

  &--danger {
    color: $button-danger-color;
    background-color: $button-danger-background-color;
    border: $button-border-width solid $button-danger-border-color;
  }

  &--warning {
    color: $button-warning-color;
    background-color: $button-warning-background-color;
    border: $button-border-width solid $button-warning-border-color;
  }

  &--reset {
    color: $button-reset-color;
    background-color: $button-reset-background-color;
    border: $button-border-width solid $button-reset-border-color;
  }

  // plain
  &--plain {
    background-color: $button-plain-background-color;

    &.hl-button--primary {
      color: $button-primary-background-color;
    }

    &.hl-button--success {
      color: $button-success-background-color;
    }

    &.hl-button--danger {
      color: $button-danger-background-color;
    }

    &.hl-button--warning {
      color: $button-warning-background-color;
    }
  }

  // size
  &--large {
    width: 100%;
    height: $button-large-height;
  }

  &--normal {
    padding: 0 15px;
    font-size: $button-normal-font-size;
  }

  &--small {
    height: $button-small-height;
    padding: 0 $padding-xs;
    font-size: $button-small-font-size;
  }

  &--mini {
    height: $button-mini-height;
    padding: 0 $padding-base;
    font-size: $button-mini-font-size;

    & + .hl-button--mini {
      margin-left: $padding-base;
    }
  }

  // block
  &--block {
    display: block;
    width: 100%;
  }

  // shape
  &--rect {
    border-radius: 0;
  }
  &--square {
    width: $button-square-with;
    height: $button-square-with;
    padding: 0;
    line-height: $button-square-with;
  }
  &--round {
    border-radius: $button-round-border-radius;
  }

  // align-items are ignored when flex container is a button in legacy safari
  // see: https://bugs.webkit.org/show_bug.cgi?id=169700
  &__content {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }

  // icon
  &__icon {
    font-size: 1.2em;
    line-height: inherit;
  }
  &__icon + &__text,
  &__text + &__icon {
    margin-left: $padding-base;
  }

  // hairline
  &--hairline {
    border-width: 0;

    &::after {
      @include hairline();

      border-color: inherit;
      border-radius: $button-border-radius * 2;
    }

    &.hl-button--round::after {
      @include hairline();

      border-radius: $button-round-border-radius;
    }

    &.hl-button--square::after {
      @include hairline();

      border-radius: 0;
    }
  }
}
