// scss-lint:disable QualifyingElement

// Make the div behave like a button
.#{$btn-prefix-cls}-group,
.#{$btn-prefix-cls}-group-vertical {
  position: relative;
  display: inline-flex;
  vertical-align: middle; // match .btn alignment given font-size hack above

  > .#{$btn-prefix-cls} {
    position: relative;
    flex: 0 1 auto;
    margin-bottom: 0;

    // Bring the hover, focused, and "active" buttons to the fron to overlay
    // the borders properly
    @include hover {
      z-index: 2;
    }
    @include focus-active{
      z-index: 2;
    }
  }

  // Prevent double borders when buttons are next to each other
  .#{$btn-prefix-cls} + .#{$btn-prefix-cls},
  .#{$btn-prefix-cls} + .#{$btn-prefix-cls}-group,
  .#{$btn-prefix-cls}-group + .#{$btn-prefix-cls},
  .#{$btn-prefix-cls}-group + .#{$btn-prefix-cls}-group {
    margin-left: -$input-btn-border-width;
  }
}

// Optional: Group multiple button groups together for a toolbar
.#{$btn-prefix-cls}-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;

  .input-group {
    width: auto;
  }
}

.#{$btn-prefix-cls}-group > .#{$btn-prefix-cls}:not(:first-child):not(:last-child):not(.#{$dropdown-prefix-cls}-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
.#{$btn-prefix-cls}-group > .#{$btn-prefix-cls}:first-child {
  margin-left: 0;

  &:not(:last-child):not(.#{$dropdown-prefix-cls}-toggle) {
    @include border-right-radius(0);
  }
}
// Need .dropdown-toggle since :last-child doesn't apply given a .dropdown-menu immediately after it
.#{$btn-prefix-cls}-group > .#{$btn-prefix-cls}:last-child:not(:first-child),
.#{$btn-prefix-cls}-group > .#{$dropdown-prefix-cls}-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)
.#{$btn-prefix-cls}-group > .#{$btn-prefix-cls}-group {
  float: left;
}
.#{$btn-prefix-cls}-group > .#{$btn-prefix-cls}-group:not(:first-child):not(:last-child) > .#{$btn-prefix-cls} {
  border-radius: 0;
}
.#{$btn-prefix-cls}-group > .#{$btn-prefix-cls}-group:first-child:not(:last-child) {
  > .#{$btn-prefix-cls}:last-child,
  > .#{$dropdown-prefix-cls}-toggle {
    @include border-right-radius(0);
  }
}
.#{$btn-prefix-cls}-group > .#{$btn-prefix-cls}-group:last-child:not(:first-child) > .#{$btn-prefix-cls}:first-child {
  @include border-left-radius(0);
}

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


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

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


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

.#{$btn-prefix-cls}-group-round > .#{$btn-prefix-cls} { @extend .#{$btn-prefix-cls}-round; }


//
// Split button dropdowns
//

.#{$btn-prefix-cls} + .#{$dropdown-prefix-cls}-toggle-split {
  padding-right: $btn-padding-x * .75;
  padding-left: $btn-padding-x * .75;

  &::after {
    margin-left: 0;
  }
}

.#{$btn-prefix-cls}-sm + .#{$dropdown-prefix-cls}-toggle-split {
  padding-right: $btn-sm-padding-x * .75;
  padding-left: $btn-sm-padding-x* .75;
}

.#{$btn-prefix-cls}-lg + .#{$dropdown-prefix-cls}-toggle-split {
  padding-right: $btn-lg-padding-x * .75;
  padding-left: $btn-lg-padding-x * .75;
}


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

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


//
// Vertical button groups
//

.#{$btn-prefix-cls}-group-vertical {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;

  .#{$btn-prefix-cls},
  .#{$btn-prefix-cls}-group {
    width: 100%;
  }

  > .#{$btn-prefix-cls} + .#{$btn-prefix-cls},
  > .#{$btn-prefix-cls} + .#{$btn-prefix-cls}-group,
  > .#{$btn-prefix-cls}-group + .#{$btn-prefix-cls},
  > .#{$btn-prefix-cls}-group + .#{$btn-prefix-cls}-group {
    margin-top: -$input-btn-border-width;
    margin-left: 0;
  }
}

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


// 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"] {
  > .#{$btn-prefix-cls},
  > .#{$btn-prefix-cls}-group > .#{$btn-prefix-cls} {
    input[type="radio"],
    input[type="checkbox"] {
      position: absolute;
      clip: rect(0,0,0,0);
      pointer-events: none;
    }
  }
}
