/// Bootstap btn groups already have styling
/// The issue surrounds the following scenario
/// <pui-button-group>
///   <pui-button></pui-button>
/// </pui-button-group>
/// Which in browsers supporting shadow doms looks like:
/// <pui-button-group>
///   <div class="btn-group">
///    <pui-button>
///     <button class="btn">Button 1</button>
///    </pui-button>
///    <pui-button>
///     <button class="btn">Button 2</button>
///    </pui-button>
///   </div>
/// </pui-button-group>
/// Default styling does not ignore the shadow elements so we need to duplicate styling for this case only
/// Many mixins and variables are used in the Metronic/Bootstrap theme for button-group style
/// TODO: Figure out a better way than this......
$border-radius-base: 4px !default;
/// Border radius of buttons
$btn-border-radius-base: $border-radius-base !default;
//** Width of the `border` for generating carets that indicate dropdowns.
$caret-width-base: 4px !default;
//** Carets increase slightly in size for larger components.
$caret-width-large: 5px !default;
@mixin clearfix() {
  &:before,
  &:after {
    content: " "; // 1
    display: table; // 2
  }
  &:after {
    clear: both;
  }
}

@mixin border-top-radius($radius) {
  border-top-right-radius: $radius;
  border-top-left-radius: $radius;
}

@mixin border-right-radius($radius) {
  border-bottom-right-radius: $radius;
  border-top-right-radius: $radius;
}

@mixin border-bottom-radius($radius) {
  border-bottom-right-radius: $radius;
  border-bottom-left-radius: $radius;
}

@mixin border-left-radius($radius) {
  border-bottom-left-radius: $radius;
  border-top-left-radius: $radius;
}

//
// Button groups
// --------------------------------------------------
// Make the div behave like a button
.btn-group,
.btn-group-vertical {
  position: relative;
  display: inline-block;
  vertical-align: middle; // match .btn alignment given font-size hack above
  .btn {
    position: relative;
    float: left;
    // Bring the "active" button to the front
    &:hover,
    &:focus,
    &:active,
    &.active {
      z-index: 2;
    }
  }
}

// Prevent double borders when buttons are next to each other
.btn-group {
  .btn,
  .btn-group,
  .btn,
  .btn-group {
    margin-left: -1px;
  }
}

// Optional: Group multiple button groups together for a toolbar
.btn-toolbar {
  margin-left: -5px; // Offset the first child's margin
  @include clearfix;
  .btn,
  .btn-group {
    float: left;
  }
  .btn,
  .btn-group {
    margin-left: 5px;
  }
}

.btn-group>pui-button:not(:first-child):not(:last-child):not(.dropdown-toggle)>.btn {
  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-group>pui-button:first-child {
  >.btn {
    margin-left: 0;
  }
  &:not(:last-child):not(.dropdown-toggle) {
    >.btn {
      @include border-right-radius(0);
    }
  }
}

// Need .dropdown-toggle since :last-child doesn't apply, given that a .dropdown-menu is used immediately after it
.btn-group>pui-button:last-child:not(:first-child)>.btn {
  @include border-left-radius(0);
}

// Custom edits for including btn-groups within btn-groups (useful for including dropdown buttons within a btn-group)
.btn-group>pui-button-group>.btn-group {
  float: left;
}

// Move specifier from .btn-group to pui-button-group
.btn-group>pui-button-group:not(:first-child):not(:last-child)>.btn-group>pui-button>.btn {
  border-radius: 0;
}

// Move specifier from .btn-group to pui-button-group
.btn-group>pui-button-group:first-child:not(:last-child)>.btn-group {
  >.btn:last-child,
  >.dropdown-toggle {
    @include border-right-radius(0);
  }
}

// Move specifier from .btn-group to pui-button-group
// Move specifier from .btn to pui-button
.btn-group>pui-button-group:last-child:not(:first-child)>.btn-group>pui-button:first-child>.btn {
  @include border-left-radius(0);
}

// On active and open, don't show outline
.btn-group .dropdown-toggle:active,
.btn-group.open .dropdown-toggle {
  outline: 0;
}

// Split button dropdowns
// ----------------------
// Give the line between buttons some depth
.btn-group>pui-button>.btn+.dropdown-toggle {
  padding-left: 8px;
  padding-right: 8px;
}

.btn-group>pui-button>.btn-lg+.dropdown-toggle {
  padding-left: 12px;
  padding-right: 12px;
}

// Upside down carets for .dropup
.dropup pui-button>.btn-lg .caret {
  border-width: 0 $caret-width-large $caret-width-large;
}

// Vertical button groups
// ----------------------
.btn-group-vertical {
  .btn,
  .btn-group {
    display: block;
    float: none;
    width: 100%;
    max-width: 100%;
    margin-top: -1px;
    margin-left: 0;
    // Clear floats so dropdown menus can be properly placed
    @include clearfix;
    .btn {
      float: none;
    }
  }
}

.btn-group-vertical>pui-button {
  &:not(:first-child):not(:last-child) {
    >.btn {
      border-radius: 0;
    }
  }
  &:first-child:not(:last-child) {
    >.btn {
      @include border-top-radius($btn-border-radius-base);
      @include border-bottom-radius(0);
    }
  }
  &:last-child:not(:first-child) {
    >.btn {
      @include border-top-radius(0);
      @include border-bottom-radius($btn-border-radius-base);
    }
  }
}

.btn-group-vertical>pui-button-group:not(:first-child):not(:last-child)>.btn-group>.btn {
  border-radius: 0;
}

.btn-group-vertical>pui-button-group:first-child:not(:last-child)>.btn-group {
  >pui-button:last-child>.btn,
  >.dropdown-toggle {
    @include border-bottom-radius(0);
  }
}

.btn-group-vertical>pui-button-group:last-child:not(:first-child)>.btn-group>pui-button:first-child>.btn {
  @include border-top-radius(0);
}

// Justified button groups
// ----------------------
.btn-group-justified {
  display: table;
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  .btn,
  .btn-group {
    float: none;
    display: table-cell;
    width: 1%;
  }
  .btn-group .btn {
    width: 100%;
  }
  .btn-group .dropdown-menu {
    left: auto;
  }
}

.btn-group.btn-group-circle>*:first-child>.btn {
  border-radius: 25px 0 0 25px !important;
}

.btn-group.btn-group-circle>*:last-child>.btn {
  border-radius: 0 25px 25px 0 !important;
}

.btn-group-vertical.btn-group-vertical-circle>*:first-child>.btn {
  border-radius: 25px 25px 0 0 !important;
}

.btn-group-vertical.btn-group-vertical-circle>*:last-child>.btn {
  border-radius: 0 0 25px 25px !important;
}

// 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,
  .btn-group .btn {
    input[type="radio"],
    input[type="checkbox"] {
      position: absolute;
      clip: rect(0, 0, 0, 0);
      pointer-events: none;
    }
  }
}