@use 'sass:map';

@use 'common/var' as *;
@use 'mixins/button' as *;
@use 'mixins/mixins' as *;
@use 'mixins/utils' as *;
@use 'mixins/var' as *;

@include b(button) {
  @include set-component-css-var('button', $button);
}

@include b(button) {
  display: inline-block;
  line-height: 1;
  min-height: map.get($input-height, 'default');
  white-space: nowrap;
  cursor: pointer;
  background-color: var(--el-button-bg-color, #{map.get($button, 'bg-color')});
  border: var(--el-border-base);
  border-color: var(
    --el-button-border-color,
    #{map.get($button, 'border-color')}
  );
  color: var(--el-button-text-color, #{map.get($button, 'text-color')});
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  transition: 0.1s;
  font-weight: var(--el-button-font-weight);
  user-select: none;

  & + & {
    margin-left: 12px;
  }
  // icon默认14px字体大小，小尺寸el-button下应该被覆盖
  & .el-icon {
    font-size: inherit;
  }

  @include button-size(
    map.get($button-padding-vertical, 'default'),
    map.get($button-padding-horizontal, 'default'),
    map.get($button-font-size, 'default'),
    map.get($button-border-radius, 'default')
  );

  &:hover,
  &:focus {
    color: var(--el-button-hover-text-color);
    border-color: var(--el-button-hover-border-color);
    background-color: var(--el-button-hover-bg-color);
    outline: none;
  }

  &:active {
    color: var(--el-button-active-text-color);
    border-color: var(--el-button-active-border-color);
    background-color: var(--el-button-active-bg-color);
    outline: none;
  }

  &::-moz-focus-inner {
    border: 0;
  }

  & [class*='#{$namespace}-icon'] {
    & + span {
      margin-left: 8px;
    }
    svg {
      vertical-align: bottom;
    }
  }

  @include when(line) {
    --el-button-bg-color: var(--el-color-white);
    --el-button-text-color: var(--el-color-primary);
    --el-button-border-color: var(--el-color-primary);
    --el-button-hover-text-color: var(--el-color-primary);
    --el-button-hover-bg-color: var(--el-color-primary-light-9);
    --el-button-hover-border-color: var(--el-color-primary);
    --el-button-active-text-color: var(--el-color-white);
    --el-button-active-bg-color: var(--el-color-primary);
    --el-button-active-border-color: var(--el-color-primary);
    --el-button-disabled-text-color: var(--el-color-primary-light-5);
    --el-button-disabled-bg-color: var(--el-color-white);
    --el-button-disabled-border-color: var(--el-color-primary-light-5);
  }

  @include when(disabled) {
    &,
    &:hover,
    &:focus {
      color: var(--el-button-disabled-text-color);
      cursor: not-allowed;
      background-image: none;
      background-color: var(--el-button-disabled-bg-color);
      border-color: var(--el-button-disabled-border-color);
    }

    &.#{$namespace}-button--text {
      background-color: transparent;
    }

    &.is-plain {
      &,
      &:hover,
      &:focus {
        background-color: var(--el-button-disabled-bg-color);
        border-color: var(--el-button-disabled-border-color);
        color: var(--el-button-disabled-text-color);
      }
    }
  }

  @include when(loading) {
    position: relative;
    pointer-events: none;

    &:before {
      pointer-events: none;
      content: '';
      position: absolute;
      left: -1px;
      top: -1px;
      right: -1px;
      bottom: -1px;
      border-radius: inherit;
      background-color: rgba(255, 255, 255, 0.35);
    }
  }

  @include when(circle) {
    border-radius: 50%;
    padding: map.get($button-padding-vertical, 'default');
  }

  @include e(text) {
    @include m(expand) {
      letter-spacing: 0.3em;
      margin-right: -0.3em;
    }
  }

  @each $size in (large, medium, small) {
    @include m($size) {
      min-height: map.get($input-height, $size);

      @include button-size(
        map.get($button-padding-vertical, $size),
        map.get($button-padding-horizontal, $size),
        map.get($button-font-size, $size),
        map.get($button-border-radius, $size)
      );

      @include when(circle) {
        padding: map.get($button-padding-vertical, $size);
      }
    }
  }

  @include m(text) {
    border-color: transparent;
    color: var(--el-color-primary);
    background: transparent;
    padding: 0;
    min-height: 0;

    &:hover,
    &:focus {
      color: var(--el-color-primary-light-2);
      border-color: transparent;
      background-color: transparent;
    }
    &:active {
      color: var(--el-color-primary-dark-2);
      border-color: transparent;
      background-color: transparent;
    }

    &.is-disabled,
    &.is-disabled:hover,
    &.is-disabled:focus {
      color: var(--el-color-primary-light-5);
      border-color: transparent;
    }
  }
}
