// themes
$base-colors: (
    default: $ax6ui-select-default-base-color
);
$theme-colors: (
    default: $ax6ui-select-default-theme-color
);
$hover-types: (
    default: $ax6ui-select-default-hover-type
);

@include keyframes(ax-select-option-group) {
  from {
    @include transform(scale(1, 0));
    max-height: 0;
    opacity: 0;
  }
  to {
    //max-height: 100%;
    @include transform(scale(1, 1));
    opacity: 1;
  }
}

@include keyframes(ax-select-option-group-destroy) {
  from {
    @include transform(scale(1, 1));
    opacity: 1;
  }
  to {
    @include transform(scale(1, 0));
    opacity: 0;
  }
}

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

      .ax6select-display-table {
        [data-ax6ui-select-display="label"] {

        }
        [data-ax6ui-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 ax6ui-select-option-group-theme($base-color, $back-color, $theme-color, $hover-type) {
  border-color: $theme-color;
  color: $base-color;

  .ax-select-body {
    .ax-select-option-group-content {
      .ax-select-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-select-option-item-holder {
            .ax-select-option-item-cell {
              &.ax-select-option-item-checkbox {
                .item-checkbox-wrap {
                  &.useCheckBox {
                    &:after {
                      @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-select-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-select-option-item-holder {
            .ax-select-option-item-cell {
              &.ax-select-option-item-checkbox {
                .item-checkbox-wrap {
                  &.useCheckBox {
                    &:after {
                      @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-select-option-item-label {
              }
            }
          }
        }
      }
      .ax-select-option-group {
        .ax-select-option-item-holder {
          .ax-select-option-group-label {
            background: #eee;
          }
        }
      }
    }
    .ax-select-option-group-buttons {
      border-top: 1px solid;
      border-color: $theme-color;
    }
  }
  &:hover {

  }
}

@mixin ax6ui-select-option-group($padding, $font-size) {
  .ax-select-body {
    padding: $ax6ui-select-option-group-body-padding;
    $ax6ui-select-option-item-height: $font-size + 5;
    $ax6ui-select-option-item-checkbox-size: $font-size - 4;
    .ax-select-option-group-content {
      max-height: $ax6ui-select-option-item-height * 10;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      position: relative;
      .ax-select-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-select-option-item-holder {
          display: table;
          position: relative;
          border-collapse: separate;
          overflow: hidden;
          //table-layout: fixed;
          width: 100%;
          height: $ax6ui-select-option-item-height;

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

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

                &.useCheckBox {
                  &:after {
                    content: '';
                    width: $ax6ui-select-option-item-checkbox-size;
                    height: $ax6ui-select-option-item-checkbox-size / 2;
                    position: absolute;
                    top: ($ax6ui-select-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-select-option-item-label {
              padding: $ax6ui-select-label-padding;
              padding-right: $ax6ui-select-option-item-checkbox-size;
            }
          }
        }

        &[data-option-selected="true"] {
          .ax-select-option-item-holder .ax-select-option-item-cell.ax-select-option-item-checkbox .item-checkbox-wrap.useCheckBox {
            &:after {
              opacity: 1;
            }
          }
        }
      }
      .ax-select-option-group {

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

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

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



// select group
[data-ax6ui-select] {
  position: relative;
  overflow: visible;
  display: block;
  box-sizing: border-box;
  *,
  *:before,
  *:after {
    box-sizing: border-box;
  }

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

/// select-display
.ax6ui-select-display {
  position: relative;
  z-index: 2;
  padding: 0;

  display: block;
  height: $ax-input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  font-size: $ax-font-size-base;
  border-radius: $ax-input-border-radius; // Note: This has no effect on <select>s in some browsers, due to the limited stylability of <select>s in CSS.

  @include ax-background(top, $ax6ui-select-label-bg-colors);
  border: $ax6ui-select-label-border;
  color: $ax6ui-select-label-color;

  text-decoration: none;
  @include box-shadow(none);
  // @include box-shadow(inset 0px -2px 5px rgba(0,0,0,.075));

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

  .ax6ui-select-display-table {
    width: 100%;
    height: 100%;
    display: table;
    //table-layout: fixed;
    border-collapse: collapse;
    user-select: none;

    [data-ax6ui-select-display="label"] {
      display: table-cell;
      vertical-align: middle;
      padding: $ax6ui-select-label-padding;
      color: $ax6ui-select-label-color;
      white-space: nowrap;
    }
    [data-ax6ui-select-display="addon"] {
      display: table-cell;
      vertical-align: middle;
      width: $ax6ui-select-addon-icon-height * 2 + $ax6ui-select-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: $ax6ui-select-addon-icon-height * 2 + $ax6ui-select-addon-icon-padding-right;
        text-align: left;
        line-height: ($ax6ui-select-addon-icon-height * 1.414);
        .addon-icon-arrow {
          content: '';
          width: 0px;
          height: 0px;
          display: inline-block;
          border-left: $ax6ui-select-addon-icon-height solid transparent;
          border-right: $ax6ui-select-addon-icon-height solid transparent;
          border-top: ($ax6ui-select-addon-icon-height * 1.414) solid $ax6ui-select-addon-icon-color;
          background: transparent;
          opacity: 1;
        }
      }
      .addon-icon-opened {
        width: $ax6ui-select-addon-icon-height * 2 + $ax6ui-select-addon-icon-padding-right;
        text-align: left;
        line-height: ($ax6ui-select-addon-icon-height * 1.414);
        .addon-icon-arrow {
          content: '';
          width: 0px;
          height: 0px;
          display: inline-block;
          border-left: $ax6ui-select-addon-icon-height solid transparent;
          border-right: $ax6ui-select-addon-icon-height solid transparent;
          border-bottom: ($ax6ui-select-addon-icon-height * 1.414) solid $ax6ui-select-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));
    background-image: none; // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214
    .ax6ui-select-display-table [data-ax6ui-select-display="addon"] {
      .addon-icon-reset {
        display: block;
        position: absolute;
        right: $ax6ui-select-addon-icon-height * 2 + $ax6ui-select-addon-icon-padding-right * 2;
        top: 0px;
        height: 100%;
      }
      .addon-icon-closed {
        display: none;
      }
      .addon-icon-opened {
        display: block;
      }
    }
  }

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

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

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

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

  @include ax6ui-select-option-group($ax6ui-select-option-item-padding, $ax6ui-select-option-item-font-size);
}