//
// Button groups
// --------------------------------------------------

// Make the div behave like a button
.#{$class-prefix}-btn-group,
.#{$class-prefix}-btn-group-vertical {
  position: relative;
  display: inline-block;
  vertical-align: middle; // match .btn alignment given font-size hack above
  > .#{$class-prefix}-btn {
    position: relative;
    float: left;
    // Bring the "active" button to the front
    &:hover,
    &:focus,
    &:active,
    &.#{$class-prefix}-active {
      z-index: 2;
    }
  }
}

// Prevent double borders when buttons are next to each other
.#{$class-prefix}-btn-group {
  .#{$class-prefix}-btn + .#{$class-prefix}-btn,
  .#{$class-prefix}-btn + .#{$class-prefix}-btn-group,
  .#{$class-prefix}-btn-group + .#{$class-prefix}-btn,
  .#{$class-prefix}-btn-group + .#{$class-prefix}-btn-group {
    margin-left: -1px;
  }
}

// Optional: Group multiple button groups together for a toolbar
.#{$class-prefix}-btn-toolbar {
  margin-left: -5px; // Offset the first child's margin
  @include clearfix;

  .#{$class-prefix}-btn,
  .#{$class-prefix}-btn-group,
  .#{$class-prefix}-input-group {
    float: left;
  }
  > .#{$class-prefix}-btn,
  > .#{$class-prefix}-btn-group,
  > .#{$class-prefix}-input-group {
    margin-left: 5px;
  }
}

.#{$class-prefix}-btn-group > .#{$class-prefix}-btn:not(:first-child):not(:last-child):not(.#{$class-prefix}-dropdown-toggle) {
  border-radius: 0;
}

// Set corners individual because sometimes a single button can be in a .btn-group and we need :first-child and :last-child to both match
.#{$class-prefix}-btn-group > .#{$class-prefix}-btn:first-child {
  margin-left: 0;
  &:not(:last-child):not(.#{$class-prefix}-dropdown-toggle) {
    @include border-right-radius(0);
  }
}
// Need .dropdown-toggle since :last-child doesn't apply, given that a .dropdown-menu is used immediately after it
.#{$class-prefix}-btn-group > .#{$class-prefix}-btn:last-child:not(:first-child),
.#{$class-prefix}-btn-group > .#{$class-prefix}-dropdown-toggle:not(:first-child) {
  @include border-left-radius(0);
}

// Custom edits for including btn-groups within btn-groups (useful for including dropdown buttons within a btn-group)
.#{$class-prefix}-btn-group > .#{$class-prefix}-btn-group {
  float: left;
}
.#{$class-prefix}-btn-group > .#{$class-prefix}-btn-group:not(:first-child):not(:last-child) > .#{$class-prefix}-btn {
  border-radius: 0;
}
.#{$class-prefix}-btn-group > .#{$class-prefix}-btn-group:first-child:not(:last-child) {
  > .#{$class-prefix}-btn:last-child,
  > .#{$class-prefix}-dropdown-toggle {
    @include border-right-radius(0);
  }
}
.#{$class-prefix}-btn-group > .#{$class-prefix}-btn-group:last-child:not(:first-child) > .#{$class-prefix}-btn:first-child {
  @include border-left-radius(0);
}

// On active and open, don't show outline
.#{$class-prefix}-btn-group .#{$class-prefix}-dropdown-toggle:active,
.#{$class-prefix}-btn-group.#{$class-prefix}-open .#{$class-prefix}-dropdown-toggle {
  outline: 0;
}


// Sizing
//
// Remix the default button sizing classes into new ones for easier manipulation.

.#{$class-prefix}-btn-group-xs > .#{$class-prefix}-btn { @extend .#{$class-prefix}-btn-xs; }
.#{$class-prefix}-btn-group-sm > .#{$class-prefix}-btn { @extend .#{$class-prefix}-btn-sm; }
.#{$class-prefix}-btn-group-lg > .#{$class-prefix}-btn { @extend .#{$class-prefix}-btn-lg; }


// Split button dropdowns
// ----------------------

// Give the line between buttons some depth
.#{$class-prefix}-btn-group > .#{$class-prefix}-btn + .#{$class-prefix}-dropdown-toggle {
  padding-left: 8px;
  padding-right: 8px;
}
.#{$class-prefix}-btn-group > .#{$class-prefix}-btn-lg + .#{$class-prefix}-dropdown-toggle {
  padding-left: 12px;
  padding-right: 12px;
}

// The clickable button for toggling the menu
// Remove the gradient and set the same inset shadow as the :active state
.#{$class-prefix}-btn-group.#{$class-prefix}-open .#{$class-prefix}-dropdown-toggle {
  @include box-shadow(inset 0 3px 5px rgba(0,0,0,.125));

  // Show no shadow for `.btn-link` since it has no other button styles.
  &.#{$class-prefix}-btn-link {
    @include box-shadow(none);
  }
}


// Reposition the caret
.#{$class-prefix}-btn .#{$class-prefix}-caret {
  margin-left: 0;
}
// Carets in other button sizes
.#{$class-prefix}-btn-lg .#{$class-prefix}-caret {
  border-width: $caret-width-large $caret-width-large 0;
  border-bottom-width: 0;
}
// Upside down carets for .dropup
.#{$class-prefix}-dropup .#{$class-prefix}-btn-lg .#{$class-prefix}-caret {
  border-width: 0 $caret-width-large $caret-width-large;
}


// Vertical button groups
// ----------------------

.#{$class-prefix}-btn-group-vertical {
  > .#{$class-prefix}-btn,
  > .#{$class-prefix}-btn-group,
  > .#{$class-prefix}-btn-group > .#{$class-prefix}-btn {
    display: block;
    float: none;
    width: 100%;
    max-width: 100%;
  }

  // Clear floats so dropdown menus can be properly placed
  > .#{$class-prefix}-btn-group {
    @include clearfix;
    > .#{$class-prefix}-btn {
      float: none;
    }
  }

  > .#{$class-prefix}-btn + .#{$class-prefix}-btn,
  > .#{$class-prefix}-btn + .#{$class-prefix}-btn-group,
  > .#{$class-prefix}-btn-group + .#{$class-prefix}-btn,
  > .#{$class-prefix}-btn-group + .#{$class-prefix}-btn-group {
    margin-top: -1px;
    margin-left: 0;
  }
}

.#{$class-prefix}-btn-group-vertical > .#{$class-prefix}-btn {
  &:not(:first-child):not(:last-child) {
    border-radius: 0;
  }
  &:first-child:not(:last-child) {
    @include border-top-radius($btn-border-radius-base);
    @include border-bottom-radius(0);
  }
  &:last-child:not(:first-child) {
    @include border-top-radius(0);
    @include border-bottom-radius($btn-border-radius-base);
  }
}
.#{$class-prefix}-btn-group-vertical > .#{$class-prefix}-btn-group:not(:first-child):not(:last-child) > .#{$class-prefix}-btn {
  border-radius: 0;
}
.#{$class-prefix}-btn-group-vertical > .#{$class-prefix}-btn-group:first-child:not(:last-child) {
  > .#{$class-prefix}-btn:last-child,
  > .#{$class-prefix}-dropdown-toggle {
    @include border-bottom-radius(0);
  }
}
.#{$class-prefix}-btn-group-vertical > .#{$class-prefix}-btn-group:last-child:not(:first-child) > .#{$class-prefix}-btn:first-child {
  @include border-top-radius(0);
}


// Justified button groups
// ----------------------

.#{$class-prefix}-btn-group-justified {
  display: table;
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  > .#{$class-prefix}-btn,
  > .#{$class-prefix}-btn-group {
    float: none;
    display: table-cell;
    width: 1%;
  }
  > .#{$class-prefix}-btn-group .#{$class-prefix}-btn {
    width: 100%;
  }

  > .#{$class-prefix}-btn-group .#{$class-prefix}-dropdown-menu {
    left: auto;
  }
}


// Checkbox and radio options
//
// In order to support the browser's form validation feedback, powered by the
// `required` attribute, we have to "hide" the inputs via `clip`. We cannot use
// `display: none;` or `visibility: hidden;` as that also hides the popover.
// Simply visually hiding the inputs via `opacity` would leave them clickable in
// certain cases which is prevented by using `clip` and `pointer-events`.
// This way, we ensure a DOM element is visible to position the popover from.
//
// See https://github.com/twbs/bootstrap/pull/12794 and
// https://github.com/twbs/bootstrap/pull/14559 for more information.

[data-toggle="buttons"] {
  > .#{$class-prefix}-btn,
  > .#{$class-prefix}-btn-group > .#{$class-prefix}-btn {
    .#{$class-prefix}-html-input[type="radio"],
    .#{$class-prefix}-html-input[type="checkbox"] {
      position: absolute;
      clip: rect(0,0,0,0);
      pointer-events: none;
    }
  }
}
