@use 'variables' as *;
@use '../button/variables' as btn;

@include export-module('button-group-layout') {
/* stylelint-disable */
  *.e-btn-group,
  *.e-css.e-btn-group {
    display: -webkit-inline-flex;
    display: inline-flex;
    border-radius: $btn-grp-wrapper-border;
    -webkit-flex-direction: row;
    flex-direction: row;
    position: relative;
    @if $skin-name == 'Material3' {
      border-radius: btn.$btn-border-radius;
      box-shadow: btn.$btn-active-box-shadow;
    }

    input:focus+label.e-btn,
    .e-btn:focus,
    .e-btn:hover {
      @if $skin-name == 'tailwind' or $skin-name == 'tailwind3' or $skin-name == 'bootstrap5' or $skin-name == 'bootstrap5.3' or $skin-name == 'bootstrap4' {
        z-index: 2;
      }
    }

    input + label.e-btn {
      margin-bottom: $btn-group-zero-margin-padding;
    }

    input {
      -moz-appearance: none;
      height: $btn-group-input-height;
      margin: $btn-group-input-margin;
      opacity: 0;
      position: absolute;
      width: $btn-group-input-width;
    }

    // Disabled
    input:disabled+label.e-btn,
    :disabled {
      cursor: default;
      pointer-events: none;
    }

    .e-btn-icon {
      font-size: $btn-grp-icon-font-size;
    }

    // Sharp corner for sides individual Button and SplitButton
    &:not(.e-rtl):not(.e-vertical) {
      .e-btn {
        @if $skin-name != 'Material3' and $skin-name != 'fluent2' {
          margin-left: $btn-grp-margin-left;
        }

        &:not(:first-of-type):not(:last-of-type) {
          border-radius: $btn-zero-radius;
        }

        &:first-of-type,
        &:last-of-type:not(:last-child) {
          border-bottom-right-radius: $btn-zero-radius;
          border-top-right-radius: $btn-zero-radius;
        }

        &:last-of-type {
          border-bottom-left-radius: $btn-zero-radius;
          border-top-left-radius: $btn-zero-radius;
        }
      }

      .e-split-btn-wrapper {
        +.e-btn {
          border-bottom-left-radius: $btn-zero-radius;
          border-top-left-radius: $btn-zero-radius;
        }

        &:not(:first-child):not(:last-child) {
          .e-btn:last-child {
            border-bottom-right-radius: $btn-zero-radius;
            border-top-right-radius: $btn-zero-radius;
          }

          .e-btn:first-child {
            border-bottom-left-radius: $btn-zero-radius;
            border-top-left-radius: $btn-zero-radius;
          }
        }

        &:first-child {
          .e-btn:last-child {
            border-bottom-right-radius: $btn-zero-radius;
            border-top-right-radius: $btn-zero-radius;
          }
        }

        &:last-child {
          .e-btn:first-child {
            border-bottom-left-radius: $btn-zero-radius;
            border-top-left-radius: $btn-zero-radius;
          }
        }
      }
    }

    // RTL with Sharp corner combinations
    &.e-rtl {
      .e-btn {
        margin-left: $btn-grp-margin-left;

        &:not(:first-of-type):not(:last-of-type) {
          border-radius: $btn-zero-radius;
        }

        &:first-of-type,
        &:last-of-type:not(:last-child) {
          border-bottom-left-radius: $btn-zero-radius;
          border-top-left-radius: $btn-zero-radius;
        }

        &:last-of-type {
          border-bottom-right-radius: $btn-zero-radius;
          border-top-right-radius: $btn-zero-radius;
        }
      }

      .e-split-btn-wrapper {
        +.e-btn {
          border-bottom-right-radius: $btn-zero-radius;
          border-top-right-radius: $btn-zero-radius;
        }

        &:not(:first-child):not(:last-child) {
          .e-btn:last-child {
            border-bottom-left-radius: $btn-zero-radius;
            border-top-left-radius: $btn-zero-radius;
          }

          .e-btn:first-child {
            border-bottom-right-radius: $btn-zero-radius;
            border-top-right-radius: $btn-zero-radius;
          }
        }

        &:first-child {
          .e-btn:last-child {
            border-bottom-left-radius: $btn-zero-radius;
            border-top-left-radius: $btn-zero-radius;
          }
        }

        &:last-child {
          .e-btn:first-child {
            border-bottom-right-radius: $btn-zero-radius;
            border-top-right-radius: $btn-zero-radius;
          }
        }
      }
    }

    // Vertical Orientation
    &.e-vertical {
      -webkit-flex-direction: column;
      flex-direction: column;

      input {
        margin: $btn-vertical-grp-margin;
      }

      // Round corner
      .e-btn {
        &:not(.e-outline) {
          margin-top: $btn-grp-margin;
        }

        &:not(:first-of-type):not(:last-of-type) {
          border-radius: $btn-zero-radius;
        }

        &:first-of-type {
          border-bottom-left-radius: $btn-zero-radius;
          border-bottom-right-radius: $btn-zero-radius;
          border-top-left-radius: $btn-top-radius;
          border-top-right-radius: $btn-top-radius;
        }

        &:last-of-type {
          border-bottom-left-radius: $btn-top-radius;
          border-bottom-right-radius: $btn-top-radius;
          border-top-left-radius: $btn-zero-radius;
          border-top-right-radius: $btn-zero-radius;
        }
      }
    }

    // Rounded Corner
    &.e-round-corner:not(.e-vertical) {
      &:not(.e-rtl) {
        border-radius: $btn-grp-round-radius;

        .e-btn {
          &:first-of-type {
            border-bottom-left-radius: $btn-grp-round-radius;
            border-top-left-radius: $btn-grp-round-radius;
          }

          &:last-of-type {
            border-bottom-right-radius: $btn-grp-round-radius;
            border-top-right-radius: $btn-grp-round-radius;
          }

          &:last-of-type:not(:last-child) {
            border-bottom-right-radius: $btn-zero-radius;
            border-top-right-radius: $btn-zero-radius;
          }
        }

        .e-split-btn-wrapper {
          +.e-btn {
            border-bottom-left-radius: $btn-zero-radius;
            border-top-left-radius: $btn-zero-radius;
          }

          &:first-child {
            .e-btn:first-child {
              border-bottom-left-radius: $btn-grp-round-radius;
              border-top-left-radius: $btn-grp-round-radius;
            }

            .e-btn:last-child {
              border-bottom-right-radius: $btn-zero-radius;
              border-top-right-radius: $btn-zero-radius;
            }
          }

          &:last-child {
             .e-btn:first-child {
              border-bottom-left-radius: $btn-zero-radius;
              border-top-left-radius: $btn-zero-radius;
            }

            .e-btn:last-child {
              border-bottom-right-radius: $btn-grp-round-radius;
              border-top-right-radius: $btn-grp-round-radius;
            }
          }
        }
      }

      // Rounded corner with RTL
      &.e-rtl {
        border-radius: $btn-grp-round-radius;

        .e-btn {
          &:first-of-type {
            border-bottom-right-radius: $btn-grp-round-radius;
            border-top-right-radius: $btn-grp-round-radius;
          }

          &:last-of-type {
            border-bottom-left-radius: $btn-grp-round-radius;
            border-top-left-radius: $btn-grp-round-radius;
          }

          &:last-of-type:not(:last-child) {
            border-bottom-left-radius: $btn-zero-radius;
            border-top-left-radius: $btn-zero-radius;
          }

          &:first-of-type:not(:first-child) {
            border-bottom-right-radius: $btn-zero-radius;
            border-top-right-radius: $btn-zero-radius;
          }
        }
      }
    }
  }
}
