@import '../../style/mixins';
@import '../../style/themes/default';
@buttonPrefixCls: fm-button;

.size(@width; @height) {
  width: @width;
  height: @height;
}

.square(@size) {
  .size(@size; @size);
}

.button-size(@height; @padding; @font-size; @border-radius) {
  height: @height;
  padding: @padding;
  font-size: @font-size;
  border-radius: @border-radius;
}

// round button
.btn-round(@btnClassName: btn) {
  opacity: 1;
  .button-size(@button-height; 0 @button-height / 2; @font-size-base + 2px; @button-height);
  &.@{btnClassName}-small {
    .button-size(@button-height-sm; 0 @button-height-sm / 2; @font-size-base; @button-height-sm);
  }
}

// circle button: the content only contains icon
.btn-circle(@btnClassName: btn) {
  .square(@button-height);
  .button-size(@button-height; 0; @font-size-base + 2px; 50%);
  &.@{btnClassName}-small {
    .square(@button-height-sm);
    .button-size(@button-height-sm; 0; @font-size-base; 50%);
  }
}

.btn-ghost(@color; @border: @color) {
  color: @color;
  border-color: @border;

  &.@{buttonPrefixCls}-active {
    color: fade(@color, 30%);
    border-color: fade(@color, 30%);
  }
  &.@{buttonPrefixCls}-disabled {
    color: fade(@color, 60%);
    border-color: fade(@color, 60%);
  }
}

.@{buttonPrefixCls} {
  // do not use width:100%, can not set margin
  display: block;
  outline: 0 none;
  cursor: pointer;
  -webkit-appearance: none;
  box-sizing: border-box;
  padding: 0;
  text-align: center;
  font-size: @button-font-size;
  height: @button-height;
  line-height: @button-height;

  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  white-space: nowrap;

  // default
  color: @color-text-base;
  background-color: @fill-base;

  .hairline('all', @border-color-base, @radius-md);

  &&-active {
    background-color: @fill-tap;
  }
  &&-disabled {
    color: fade(@color-text-base, 30%);
    opacity: 0.6;
    pointer-events: none;
  }

  &-primary {
    color: @color-text-base-inverse;
    background-color: @primary-button-fill;
    .hairline('all', @primary-button-fill, @radius-md);

    &.@{buttonPrefixCls}-active {
      color: fade(@color-text-base-inverse, 30%);
      background-color: @primary-button-fill-tap;
    }
    &.@{buttonPrefixCls}-disabled {
      color: fade(@color-text-base-inverse, 60%);
      opacity: 0.4;
    }
  }

  &-danger {
    color: @color-text-base-inverse;
    background-color: @warning-button-fill;

    &.@{buttonPrefixCls}-active {
      color: fade(@color-text-base-inverse, 30%);
      background-color: @warning-button-fill-tap;
    }
    &.@{buttonPrefixCls}-disabled {
      color: fade(@color-text-base-inverse, 60%);
      opacity: 0.4;
    }
  }

  &&-loading {
    position: relative;
    pointer-events: none;
    &:before {
      background: #fff;
      opacity: 0.35;
    }
  }

  &-font {
    width: auto;
    height: auto;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    &:hover,
    &:focus,
    &:active,
    &.active {
      background: transparent;
    }
    &:before {
      border: none !important;
    }
  }

  &-inline {
    display: inline-block;
    padding: 0 @h-spacing-lg;
    &.@{buttonPrefixCls}-icon {
      display: inline-flex;
    }
  }

  &-small {
    font-size: @button-font-size-sm;
    height: @button-height-sm;
    line-height: @button-height-sm;
    padding: 0 @h-spacing-lg;
  }

  &-round {
    .btn-round(@buttonPrefixCls);
    .hairline-remove('all');
  }

  &-circle {
    .btn-circle(@buttonPrefixCls);
    .hairline-remove('all');
  }

  &-full {
    display: block;
    width: 100%;
    border-radius: 0;
    .hairline-remove('all');
    .hairline('top');
    .hairline('bottom');
  }

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

  &-background-ghost {
    background: transparent!important;
    .btn-ghost(@color-text-base-inverse)
  }

  &-primary&-background-ghost {
    .btn-ghost(@primary-button-fill)
  }

  &-background-ghost&-danger {
    .btn-ghost(@warning-button-fill)
  }

  > .@{buttonPrefixCls}-icon {
    margin-left: 0.5em;
    margin-right: 0.5em;
  }
}
