@import (reference) "../core/_typography.less";

// Form validation states

.form-control-validation(@text-color; @border-color; @border-hover;) {
  border-color: @border-color !important;

  // DEPRECATED: use `Field` component (or in some edge cases `Label` component) instead
  .control-label,

  // Color the label and help text
  .radio,
  .checkbox,
  .radio-inline,
  .checkbox-inline,
  &.radio label,
  &.checkbox label,
  &.radio-inline label,
  &.checkbox-inline label,
  .radio label,
  .checkbox label,
  .radio-inline label,
  .checkbox-inline label,
  .input-group-addon {
    color: @text-color !important;
    border-color: @border-color !important;
  }

  // Set the border and box shadow on specific inputs to match
  .form-control,
  .btn-input,
  .btn-input:not(.disabled, :disabled):focus,
  .btn-input:not(.disabled, :disabled):hover,
  .input-group-addon,
  .alert {
    border-color: @border-color !important;
  }

  &:active,
  &:focus,
  &:focus-within {
    .form-control,
    &.radio label,
    &.checkbox label,
    .btn-input,
    .input-group-addon,
    .input-group .form-control:focus,
    .alert {
      border-color: @border-hover !important;
    }
  }

  &:not(.disabled, :disabled):hover {
    &.radio label,
    &.checkbox label,
    .btn-input,
    .alert {
      border-color: @border-hover !important;
    }
  }

  // Optional feedback icon
  .form-control-feedback {
    color: @text-color;
  }

  .radio,
  &.checkbox {
    > label {
      &:not(.disabled, :disabled) {
        border-color: @border-color;
        color: var(--color-content-primary);
      }

      &:not(.disabled, :disabled):hover,
      &:focus-within {
        border-color: @border-hover !important;

        .tw-checkbox-button,
        .tw-radio-button {
          border-color: @border-hover !important;
        }
      }
    }

    .tw-checkbox-button,
    .tw-radio-button {
      border-color: @border-color;
    }
  }
}

// Form control focus state
//
// Generate a customized focus state and for any input with the specified color,
// which defaults to the `var(--color-interactive-secondary-active)` CSS custom prop.
//
// We highly encourage you to not customize the default value, but instead use
// this to tweak colors on an as-needed basis. This aesthetic change is based on
// WebKit's default styles, but applicable to a wider range of browsers. Its
// usability and accessibility should be taken into account with any change.
//
// Example usage: change the default blue border and shadow to white for better
// contrast against a dark gray background.
.form-control-focus(@color: var(--color-interactive-primary)) {
  &:not(.disabled, :disabled):focus {
    border-color: @color;
    outline: 0;
  }
}

// Form control sizing
//
// Relative text size, padding, and border-radii changes for form controls. For
// horizontal sizing, wrap controls in the predefined grid classes. `<select>`
// element gets special love because it's special, and that's a fact!
.input-size(@input-height; @input-padding; @border-radius) {
  min-height: @input-height;
  padding: @input-padding;
  border-radius: @border-radius;

  select& {
    min-height: @input-height;
  }

  textarea&,
  select[multiple]& {
    height: auto;
  }
}
