/// override bootstrap.form-control
@mixin input-size($parent, $input-height) {
  [data-ax5combobox] select[multiple]#{$parent} {
    height: $input-height;
  }
}

[data-ax5combobox] select[multiple].form-control {
  height: $input-height-base;
}

@include input-size(".input-sm", $input-height-small);
@include input-size(".input-lg", $input-height-large);

.form-group-sm {
  [data-ax5combobox] select[multiple].form-control {
    height: $input-height-small;
  }
}

.form-group-lg {
  [data-ax5combobox] select[multiple].form-control {
    height: $input-height-large;
  }
}

.form-inline {
  @media (min-width: $screen-sm-min) {
    // Inline-block all the things for "inline"
    [data-ax5combobox] {
      display: inline-block;
      .ax5combobox-display {
        .ax5combobox-display-table {
          table-layout: auto;
        }
      }
    }
  }
}

// select group
[data-ax5combobox] {
  position: relative;
  overflow: visible;
  display: block;
  margin: 0px;
  * {
    box-sizing: border-box;
  }

  select {
    z-index: 1;
    position: absolute;
    opacity: 0;
    user-select: none;
  }
}

@include keyframes(ax-combobox-option-group) {
  from {
    @include transform(translateY(-10%));
    opacity: 0;
  }
  to {
    @include transform(translateY(0%));
    opacity: 1;
  }
}

@include keyframes(ax-combobox-option-group-destroy) {
  from {
    @include transform(translateY(0%) scaleY(1));
    opacity: 1;
  }
  to {
    @include transform(translateY(0%) scaleY(0));
    opacity: 0;
  }
}

@mixin ax5combobox-display-theme($base-color, $back-color, $theme-color) {
  a {
    color: $base-color;
  }

  &:hover,
  &:active,
  &:focus,
  &[data-select-option-group-opened] {
    &:not([disabled]) {
      border-color: $theme-color;
      color: $base-color;
      background: $back-color;
      text-decoration: none;

      .ax5combobox-display-table {
        [data-ax5-select-display="label"] {
        }
        [data-ax5-select-display="addon"] {
          .addon-icon-closed {
            .addon-icon-arrow {
              border-top-color: $base-color;
            }
          }
          .addon-icon-opened {
            .addon-icon-arrow {
              border-bottom-color: $base-color;
            }
          }
        }
      }
    }
  }
  [disabled] {
    user-select: none;
  }
}

@mixin ax5combobox-option-group-theme(
  $base-color,
  $back-color,
  $theme-color,
  $hover-type
) {
  border-color: $theme-color;
  color: $base-color;

  .ax-combobox-body {
    .ax-combobox-option-group-content {
      .ax-combobox-option-item {
        &:hover,
        &.hover {
          @if nth($hover-type, 1) == "lighten" {
            background: lighten($theme-color, 15%) !important;
            color: lighten($base-color, nth($hover-type, 2));
          } @else if nth($hover-type, 1) == "darken" {
            background: darken($theme-color, 15%) !important;
            color: darken($base-color, nth($hover-type, 2));
          }

          .ax-combobox-option-item-holder {
            .ax-combobox-option-item-cell {
              &.ax-combobox-option-item-checkbox {
                .item-checkbox-wrap {
                  &.useCheckBox {
                    &:after {
                      box-sizing: border-box;
                      @if nth($hover-type, 1) == "lighten" {
                        border-color: lighten(
                          $base-color,
                          nth($hover-type, 2)
                        ) !important;
                      } @else if nth($hover-type, 1) == "darken" {
                        border-color: darken(
                          $base-color,
                          nth($hover-type, 2)
                        ) !important;
                      }
                    }
                  }
                }
              }
              &.ax-combobox-option-item-label {
              }
            }
          }
        }
        &[data-option-selected="true"] {
          @if nth($hover-type, 1) == "lighten" {
            background: $theme-color;
            color: lighten($base-color, nth($hover-type, 2));
          } @else if nth($hover-type, 1) == "darken" {
            background: $theme-color;
            color: darken($base-color, nth($hover-type, 2));
          }

          .ax-combobox-option-item-holder {
            .ax-combobox-option-item-cell {
              &.ax-combobox-option-item-checkbox {
                .item-checkbox-wrap {
                  &.useCheckBox {
                    &:after {
                      box-sizing: border-box;
                      @if nth($hover-type, 1) == "lighten" {
                        border-color: lighten(
                          $base-color,
                          nth($hover-type, 2)
                        ) !important;
                      } @else if nth($hover-type, 1) == "darken" {
                        border-color: darken(
                          $base-color,
                          nth($hover-type, 2)
                        ) !important;
                      }
                    }
                  }
                }
              }
              &.ax-combobox-option-item-label {
              }
            }
          }
        }
      }
      .ax-combobox-option-group {
        .ax-combobox-option-item-holder {
          .ax-combobox-option-group-label {
            background: #eee;
          }
        }
      }
    }

    .ax-combobox-option-group-buttons {
      border-top: 1px solid;
      border-color: $theme-color;
    }
  }

  &:hover {
  }
}

@mixin ax5combobox-option-group-size($padding, $font-size) {
  .ax-combobox-body {
    padding: $ax5combobox-option-group-body-padding;
    $ax5combobox-option-item-height: $font-size + 5;
    $ax5combobox-option-item-checkbox-size: $font-size - 4;
    .ax-combobox-option-group-content {
      max-height: $ax5combobox-option-item-height * 10;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      position: relative;
      .ax-combobox-option-item {
        padding: $padding;
        text-align: left;
        cursor: pointer;
        font-size: $font-size;
        position: relative;
        box-sizing: border-box;
        overflow: hidden;
        //table-layout: fixed;

        .ax-combobox-option-item-holder {
          display: table;
          position: relative;
          border-collapse: separate;
          overflow: hidden;
          //table-layout: fixed;
          width: 100%;
          height: $ax5combobox-option-item-height;

          .ax-combobox-option-item-cell {
            box-sizing: border-box;
            display: table-cell;
            vertical-align: middle;
            white-space: nowrap;
            font-size: $font-size;
            line-height: $ax5combobox-option-item-height;
            padding: 0px 0px 0px 0px;
            user-select: none;

            &.ax-combobox-option-item-checkbox {
              overflow: hidden;
              width: $font-size;
              text-align: center;
              .item-checkbox-wrap {
                position: relative;
                display: block;
                width: $font-size;
                height: $ax5combobox-option-item-height;

                &.useCheckBox {
                  &:after {
                    box-sizing: border-box;
                    content: "";
                    width: $ax5combobox-option-item-checkbox-size;
                    height: $ax5combobox-option-item-checkbox-size / 2;
                    position: absolute;
                    top: ($ax5combobox-option-item-height) / 4;
                    right: 0px;
                    border: 2px solid #000;
                    border-top: none;
                    border-right: none;
                    background: transparent;
                    opacity: 0.1;
                    @include transform(rotate(-50deg));
                  }
                }
              }
            }
            &.ax-combobox-option-item-label {
              padding: $ax5combobox-label-padding;
              padding-right: $ax5combobox-option-item-checkbox-size;
            }
          }
        }

        &[data-option-selected="true"] {
          .ax-combobox-option-item-holder
            .ax-combobox-option-item-cell.ax-combobox-option-item-checkbox
            .item-checkbox-wrap.useCheckBox {
            &:after {
              opacity: 1;
            }
          }
        }
      }
      .ax-combobox-option-group {
        .ax-combobox-option-item-holder {
          display: table;
          position: relative;
          border-collapse: separate;
          overflow: hidden;
          //table-layout: fixed;
          width: 100%;
          height: $ax5combobox-option-item-height;

          .ax-combobox-option-group-label {
            box-sizing: border-box;
            display: table-cell;
            vertical-align: middle;
            white-space: nowrap;
            font-size: $font-size;
            line-height: $ax5combobox-option-item-height;

            padding: 5px 10px; // todo : theme 정리 나중에
            user-select: none;
          }
        }
      }
    }
    .ax-combobox-option-group-buttons {
      text-align: center;
      padding: $padding;
    }
  }
}

// themes
$base-colors: (
  default: $ax5combobox-default-base-color,
  primary: $ax5combobox-primary-base-color,
  success: $ax5combobox-success-base-color,
  info: $ax5combobox-info-base-color,
  warning: $ax5combobox-warning-base-color,
  danger: $ax5combobox-danger-base-color
);
$theme-colors: (
  default: $ax5combobox-default-theme-color,
  primary: $ax5combobox-primary-theme-color,
  success: $ax5combobox-success-theme-color,
  info: $ax5combobox-info-theme-color,
  warning: $ax5combobox-warning-theme-color,
  danger: $ax5combobox-danger-theme-color
);
$hover-types: (
  default: $ax5combobox-default-hover-type,
  primary: $ax5combobox-primary-hover-type,
  success: $ax5combobox-success-hover-type,
  info: $ax5combobox-info-hover-type,
  warning: $ax5combobox-warning-hover-type,
  danger: $ax5combobox-danger-hover-type
);

/// select-display
.ax5combobox-display {
  position: relative;
  z-index: 2;
  padding: 0px;
  display: block;

  &:hover,
  &:focus {
    text-decoration: none;
  }

  .ax5combobox-display-table {
    width: 100%;
    height: 100%;
    display: table;
    table-layout: fixed;
    border-collapse: collapse;

    [data-ax5combobox-display="label-holder"] {
      display: table-cell;
      vertical-align: middle;
      padding: 0px 0px;
    }
    [data-ax5combobox-display="label"] {
      display: block;
      white-space: nowrap;
      overflow: hidden;
      padding: $ax5combobox-label-padding;
      &:focus {
        outline: none;
      }
      *:focus {
        outline: 0;
      }
      text-decoration: none;
      &:hover {
        text-decoration: none;
      }
      &:after {
        content: " ";
        display: block;
        clear: both;
      }

      [data-ax5combobox-selected-label] {
        position: relative;
        display: block;
        float: left;
        background: transparent;
        padding: 0px 3px;
        border: 1px solid transparent;
        border-radius: 0px;
        margin: 1px 0px 1px -0.5em;

        @include ax-background(top, $ax5combobox-label-bg-colors);
        border: $ax5combobox-label-border;
        color: $ax5combobox-label-color;
        border-radius: 3px;
        margin-left: 0px;
        margin-right: 3px;

        &:first-child {
          margin-left: 0px;
        }

        [data-ax5combobox-remove] {
          width: 15px;
          position: absolute;
          right: 0;
          &:hover {
            color: $brand-danger;
          }
        }
        span {
          padding-right: 15px;
        }
      }
      [data-ax5combobox-display="input"] {
        float: left;
        width: 100px;
        &:focus {
          outline: none;
        }
        &::-ms-clear {
          display: none;
        }
      }
    }
    [data-ax5combobox-display="addon"] {
      display: table-cell;
      vertical-align: middle;
      width: $ax5combobox-addon-icon-height * 2 +
        $ax5combobox-addon-icon-padding-right;
      text-align: center;

      .addon-icon-reset {
        display: none;
      }
      .addon-icon-closed {
        display: block;
      }
      .addon-icon-opened {
        display: none;
      }
      .addon-icon-closed {
        width: $ax5combobox-addon-icon-height * 2 +
          $ax5combobox-addon-icon-padding-right;
        text-align: left;
        line-height: ($ax5combobox-addon-icon-height * 1.414);
        .addon-icon-arrow {
          content: "";
          width: 0px;
          height: 0px;
          display: inline-block;
          border-left: $ax5combobox-addon-icon-height solid transparent;
          border-right: $ax5combobox-addon-icon-height solid transparent;
          border-top: ($ax5combobox-addon-icon-height * 1.414) solid
            $ax5combobox-addon-icon-color;
          background: transparent;
          opacity: 1;
        }
      }
      .addon-icon-opened {
        width: $ax5combobox-addon-icon-height * 2 +
          $ax5combobox-addon-icon-padding-right;
        text-align: left;
        line-height: ($ax5combobox-addon-icon-height * 1.414);
        .addon-icon-arrow {
          content: "";
          width: 0px;
          height: 0px;
          display: inline-block;
          border-left: $ax5combobox-addon-icon-height solid transparent;
          border-right: $ax5combobox-addon-icon-height solid transparent;
          border-bottom: ($ax5combobox-addon-icon-height * 1.414) solid
            $ax5combobox-addon-icon-color;
          background: transparent;
          opacity: 1;
        }
      }
    }
  }

  &[data-select-option-group-opened] {
    @include box-shadow(inset 1px 1px 3px rgba(0, 0, 0, 0.2));
    .ax5combobox-display-table [data-ax5combobox-display="addon"] {
      .addon-icon-reset {
        display: block;
        position: absolute;
        right: $ax5combobox-addon-icon-height * 2 +
          $ax5combobox-addon-icon-padding-right * 2;
        top: 0;
        height: 100%;
      }
      .addon-icon-closed {
        display: none;
      }
      .addon-icon-opened {
        display: block;
      }
    }
  }

  @each $theme in $base-colors {
    &.#{nth($theme, 1)} {
      @include ax5combobox-display-theme(
        map_get($base-colors, nth($theme, 1)),
        $ax5combobox-option-group-bg,
        map_get($theme-colors, nth($theme, 1))
      );
    }
  }

  &.input-xs {
  }
  &.input-sm {
  }
  &.input-lg {
  }
}

/// select-option-group
.ax5combobox-option-group {
  box-sizing: border-box;
  z-index: $ax5combobox-option-group-z-index;
  position: absolute;
  left: 0;
  top: 0;
  border-radius: $ax5combobox-option-group-border-radius;
  box-shadow: $ax5combobox-option-group-box-shadow;
  border: $ax5combobox-option-group-inner-border;
  overflow: hidden;
  @include ax-background($ax5combobox-option-group-bg);
  @include animation(
    ax-combobox-option-group $ax5combobox-option-group-easing-time-open ease-out
  );
  @include transform(translateZ(0));
  @include transform-origin(center top);

  &.destroy {
    @include animation(
      ax-combobox-option-group-destroy
        $ax5combobox-option-group-easing-time-close $ease-in-back forwards
    );
  }
  &.direction-top {
    @include transform-origin(center top);
  }
  &.direction-bottom {
    @include transform-origin(center bottom);
  }

  @each $theme in $base-colors {
    &.#{nth($theme, 1)} {
      @include ax5combobox-option-group-theme(
        map_get($base-colors, nth($theme, 1)),
        $ax5combobox-option-group-bg,
        map_get($theme-colors, nth($theme, 1)),
        map_get($hover-types, nth($theme, 1))
      );
    }
  }

  @include ax5combobox-option-group-size(
    $ax5combobox-option-item-padding,
    $ax5combobox-option-item-font-size
  );
  &.ax5combobox-option-group-lg {
    @include ax5combobox-option-group-size(
      $ax5combobox-option-item-padding-lg,
      $ax5combobox-option-item-font-size-lg
    );
  }
  &.ax5combobox-option-group-sm {
    @include ax5combobox-option-group-size(
      $ax5combobox-option-item-padding-sm,
      $ax5combobox-option-item-font-size-sm
    );
  }
  &.ax5combobox-option-group-xs {
    @include ax5combobox-option-group-size(
      $ax5combobox-option-item-padding-xs,
      $ax5combobox-option-item-font-size-xs
    );
  }
}
