@import '../abstracts/theme.less';

// Button: variant mixins

.button-danger() {
  color: var(--btn-text-color);
  background-color: var(--danger);
  border-color: var(--danger);

  &:hover,
  &:focus {
    color: var(--btn-text-color);
    background-color: var(--danger-hover);
    border-color: var(--danger-hover);
  }

  &:focus {
    box-shadow: 0 0 0 0.2rem var(--focus-btn-danger);
  }

  &:active {
    color: var(--btn-text-color);
    background-color: var(--danger-active);
    border-color: var(--danger-active);
  }
}

.button-primary() {
  color: var(--btn-text-color);
  background-color: var(--btn-primary-bg);
  border-color: var(--btn-primary-bg);

  &:hover,
  &:focus {
    color: var(--btn-text-color);
    background-color: var(--btn-primary-bg-hover);
    border-color: var(--btn-primary-bg-hover);
  }

  &:focus {
    box-shadow: 0 0 0 0.2rem var(--focus-btn-primary);
  }

  &:active {
    color: var(--btn-text-color);
    background-color: var(--btn-primary-bg-active);
    border-color: var(--btn-primary-bg-active);
  }
}

.button-secondary() {
  color: var(--btn-secondary-color);
  border-color: var(--btn-secondary-border);
  background-color: var(--btn-secondary-bg);

  &:focus {
    color: var(--btn-secondary-color--focus);
    border-color: var(--btn-secondary-border--focus);
    background-color: var(--btn-secondary-bg--focus);
    box-shadow: 0 0 0 0.2rem var(--focus-btn-secondary);
  }

  // Hover MUST be AFTER the focus declaration for this outlined button.
  // Otherwise, the hover styles will not be applied when hovering over a focused element
  &:hover {
    color: var(--btn-secondary-color--hover);
    border-color: var(--btn-secondary-border--hover);
    background-color: var(--btn-secondary-bg--hover);
  }

  &:active {
    color: var(--btn-secondary-color--active);
    border-color: var(--btn-secondary-border--active);
    background-color: var(--btn-secondary-bg--active);
  }
}

.button-link {
  color: var(--primary);
  background-color: transparent;
  border-color: transparent;
  font-weight: var(--btn-link-font-weight);

  &:hover,
  &:focus {
    color: var(--btn-link-color--hover);
    background-color: var(--btn-link-bg--hover);
    border-color: var(--btn-link-bg--hover);
  }

  &:focus {
    box-shadow: none;
  }

  &:active {
    color: var(--btn-link-color--active);
    background-color: var(--btn-link-bg--active);
    border-color: var(--btn-link-bg--active);
  }
}

.button-disabled {
  opacity: 0.5;
  pointer-events: none;
}

// Button styles

.yui-button {
  display: inline-block;
}

.yui-button .first-child {
  display: block;
}

.yui-button button,
input[type="button"],
input[type="reset"],
input[type="submit"],
a.yui-button:link,
a.yui-button:visited {
  box-sizing: border-box;
  // vertical padding:
  // 0.375rem == 6px == 32px (target height) - 4px (borders) - 16 (line) / 2
  padding: 0.375rem 1rem;
  margin-right: 0.25rem;
  margin-left: 0.25rem;
  min-width: 4.5rem;
  min-height: 2rem;
  cursor: pointer;
  user-select: none;
  font-size: var(--btn-font-size);
  line-height: var(--btn-line-height);
  font-weight: var(--btn-font-weight);
  text-align: center;
  vertical-align: middle;
  text-decoration: none;
  border: 2px solid;
  border-radius: 4px;
  transition:
  color 0.15s ease-in-out,
  background-color 0.15s ease-in-out,
  border-color 0.15s ease-in-out;

  .button-secondary();

  &:focus {
    outline: none;
  }

  display: inline-flex;
  align-items: center;
  justify-content: center;

  & > span {
    display: inline-block;
  }

  .svg-icon,
  i {
    width: 1rem;
    height: 1rem;
    font-size: 1rem;
    vertical-align: top;
    flex-shrink: 1;
  }

  .leading-icon {
    margin-right: 0.25rem;
  }

  .trailing-icon {
    margin-left: 0.25rem;
  }
}

.yui-button.danger button,
input[type="button"].danger,
input[type="reset"].danger,
input[type="submit"].danger {
  .button-danger();
}

.yui-button.primary button,
input[type="button"].primary,
input[type="reset"].primary,
input[type="submit"].primary {
  .button-primary();
}

.yui-button.link-button button,
input[type="button"].link-button,
input[type="reset"].link-button,
input[type="submit"].link-button {
  .button-link();
}

.yui-button.large-button button,
input[type="button"].large-button,
input[type="reset"].large-button,
input[type="submit"].large-button,
a.yui-button.large-button {
  // vertical padding
  // 0.5rem == 8px == 40px (target height) - 4px (borders) - 20 (line) / 2
  padding: 0.5rem 1rem;
  min-width: 6.5rem;
  min-height: 2.5rem;
  font-size: var(--btn-large-font-size);
  line-height: var(--btn-large-line-height);

  .svg-icon,
  i {
    vertical-align: top;
    height: 1.25rem;
    width: 1.25rem;
    font-size: 1.25rem;
  }
}

.yui-button-disabled button,
.yui-button button:disabled,
input[type="button"]:disabled,
input[type="reset"]:disabled,
input[type="submit"]:disabled,
.yui-button-disabled input[type="button"],
.yui-button-disabled input[type="reset"],
.yui-button-disabled input[type="submit"] {
  .button-disabled();
}

a.yui-button {
  &.primary {
    .button-primary();
  }

  &.danger {
    .button-danger();
  }

  &.link-button {
    .button-link();
  }

  &.disabled {
    .button-disabled();
  }
}

// Dropdown buttons
.yui-button.yui-menu-button button,
.yui-button.yui-split-button button {
  // These buttons have a caret as the :after element
  &::after {
    display: inline-block;
    margin-left: 0.4em;
    vertical-align: 0.1875em;
    content: "";
    border-top: 0.35em solid;
    border-right: 0.35em solid transparent;
    border-bottom: 0;
    border-left: 0.35em solid transparent;
  }
}

.yui-button.yui-menu-button.yui-menu-button-active button,
.yui-button.yui-split-button.yui-split-button-active button {
  &::after {
    border-bottom: 0.35em solid;
    border-top: 0;
  }
}

// Icon buttons

.yui-button.icon-button button,
a.yui-button.icon-button:link,
a.yui-button.icon-button:visited {
  padding: 0.25rem;
  min-width: 2rem;
  height: 2rem;

  .svg-icon,
  i {
    width: 1rem;
    height: 1rem;
    font-size: 1rem;
  }

  .button-link();
}

.yui-button.icon-button.large-button button,
a.yui-button.icon-button.large-button {
  padding: 0.5rem;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0.625rem;

  .svg-icon,
  i {
    width: 1.25rem;
    height: 1.25rem;
    font-size: 1.25rem;
  }
}
