$dropdown-selection-bg: rgba($quaternary_color, 0.35) !default;
$dropdown-selection-hover: $primary_color !default;
$dropdown-valid-color: $valid-color !default;

// Changes the colors depending on the status
@mixin dropdown-status-color($color) {
  label {
    color: $color;
  }
  .dropdown {
    .form-control {
      border-color: $color;
    }

    .btn.btn-outline-secondary {
      background: $color;
      border-color: $color;
      //span.loading {
      //  border-top-color: $color;
      //  border-left-color: $color;
      //}
    }

    &.is-expanded .btn.btn-outline-secondary {
      background: $white;
      color: $color;
      border-color: $color $color transparent transparent;
    }

    &.is-expanded.expand-upward .btn.btn-outline-secondary {
      border-color: transparent $color $color transparent;
    }

    .list-container {
      border-color: $color;

      &:not(.list-upward) {
        border-top-color: rgba($optional-color, 0.5);
      }

      &.list-upward {
        border-bottom-color: rgba($optional-color, 0.5);
      }
    }
  }
}

jb-dropdown, jb-lazy-dropdown, jb-multi-selector {
  .dropdown-form-group {
    display: inline-block;
    margin-bottom: 15px;
    position: relative; // Set it as a container for the internal relatives

    label {
      transition-property: color;
      transition-duration: 0.2s;
      font-weight: 700;
      margin-bottom: 2px;

      .info-badge {
        display: inline-block;
        margin-right: 7px;
        cursor: pointer;
      }

      .asterisk {
        margin-left: 3px;
      }
    }

    .dropdown {
      position: relative;

      // Optional image into the input (before the text)
      .input-image {
        width: 18px;
        height: 18px;
        position: absolute;
        z-index: 900;
        left: 10px;
        top: 7.5px;

        &.fade {
          opacity: 0.4;
        }
      }

      // Optional icon into the input (before the text)
      .input-icon {
        position: absolute;
        z-index: 900;
        left: 12px;
        top: 10px;

        &.fade {
          opacity: 0.4;
        }
      }

      // Input for the selected value
      .form-control {
        border: 1px solid $optional-color;

        &.has-image, &.has-icon {
          padding-left: 35px;
        }

        // If image present, make room

        height: 34px;
        font-size: 14px;
        border-right: none;

        &:focus {
          outline: 0;
          box-shadow: none; // Remove it from Bootstrap
        }
      }

      // Right button next to the input to expand the list
      .input-group-append {
        margin-left: 0;

        .btn.btn-outline-secondary {
          border-color: $dropdown-valid-color;
          background: $dropdown-valid-color;
          color: $white;
          border-left: none;
          font-size: 14px;
          padding: 0 0 0 2px;
          min-width: 36px;
          display: flex;
          align-items: center;
          justify-content: center;

          span.loading {
            animation: jbSpinAround 500ms infinite linear;
            display: inline-block;
            width: 14px;
            height: 14px;
            border: 2px solid transparent;
            border-top-color: $white;
            border-left-color: $white;
            //border-bottom: none; border-right: none;
            border-radius: 100%;
          }

          &:focus {
            box-shadow: none;
          }

          &:active {
            box-shadow: none;
          }
        }
      }

      &.is-expanded {
        &:not(.expand-upward) {
          .form-control {
            border-bottom-left-radius: 0;
            border-bottom: none;
          }

          .btn.btn-outline-secondary {
            border-bottom-right-radius: 0;
            border-bottom-color: transparent;
          }
        }

        &.expand-upward {
          .form-control {
            border-top-left-radius: 0;
            border-top: none;
          }

          .btn.btn-outline-secondary {
            border-top-right-radius: 0;
            border-top-color: transparent;
          }
        }

        .btn.btn-outline-secondary {
          border-left-color: transparent;
          background: $white;
          color: $dropdown-valid-color;
          border-top-color: $optional-color;
          border-right-color: $optional-color;

          span.loading {
            border-top-color: $focused-color;
            border-left-color: $focused-color;
          }
        }

        .list-container {
          display: block;
        }
      }

      // Expanded list to select an item
      .list-container {
        background: $white;
        display: none;
        position: absolute;
        width: 100%;
        z-index: 6000;
        max-height: 300px;
        padding: 0; // padding: 5px 0;
        overflow: auto;
        border: 1px solid $optional-color;

        &:not(.list-upward) {
          border-top-color: rgba($optional-color, 0.5);
          border-bottom-left-radius: 3px;
          border-bottom-right-radius: 3px;
        }

        &.list-upward {
          bottom: 34px; // pull it up
          border-top-left-radius: 3px;
          border-top-right-radius: 3px;
          border-bottom-color: rgba($optional-color, 0.5);
        }

        // Adjust the first / last rows (remove 1px line between)
        .option-wrapper:first-child .option-row { min-height: 37px; margin-top: 0; }
        .option-wrapper:last-child  .option-row { min-height: 37px; margin-bottom: 0; }

        .group-header {
          padding: 4px 10px;
          font-weight: bold;
          margin: 1px 0;
          min-height: 36px;
          max-height: 72px;
          display: flex;
          align-items: center;
        }

        .option-row {
          display: flex;
          align-items: center;
          cursor: pointer;
          padding: 4px 10px;
          margin: 1px 0;
          min-height: 36px;
          max-height: 72px;

          &.group-pad { padding-left: 20px; }

          &.selected {
            font-weight: 700;
            color: $white;
            background: $dropdown-selection-bg
          }

          &.candidate {
            background: $dropdown-selection-hover;
            color: $white;
          }

          // Optional image / icon into the input (left)
          .option-row-image, .option-row-icon {
            width: 18px;
            height: 18px;
            margin-right: 10px;
          }
        }

      }

    }

    &.is-disabled {
      input.form-control {
        color: $disabled-color;
        cursor: not-allowed;
      }
    }

    &.is-error { // Error message text
      .dropdown-error-text {
        color: $invalid-color;
        font-size: 11px;
        position: absolute;

        &.pull-up {
          top: -23px;
        }

        // If no label, pull message up above the box

        // errorPosition:
        &.none {
          display: none;
        }

        // Hide error text

        &.default { // Default error position:
          @media (min-width: 767px) {
            right: 5px;
            padding-top: 3px;
          }
          // Default > xs = Top right
          @media (max-width: 768px) {
            bottom: -20px;
            right: 5px;
          }
          // Default xs = Bottom right
        }

        &.top-right {
          right: 5px;
          padding-top: 3px;
        }

        &.bottom-left {
          bottom: -20px;
          left: 5px;
        }

        &.bottom-right {
          bottom: -20px;
          right: 5px;
        }
      }

      // If error text at the bottom, add extra margin
      &.error-bottom {
        margin-bottom: 30px;
      }

      @media (max-width: 768px) {
        &.error-default {
          margin-bottom: 30px;
        }
      }
      // Small default goes to the bottom too
    }

    &.is-required {
      @include dropdown-status-color($required-color);
    }

    &.is-focus {
      @include dropdown-status-color($focused-color);
    }

    &.is-error {
      @include dropdown-status-color($invalid-color);
    }
  }

  &.full-width .dropdown-form-group {
    width: 100%;
  }

  &.flat .dropdown-form-group {
    margin-bottom: 0;
  };
}



// Style extra button combination (jb-dropdown + jb-btn)
jb-dropdown.extra-btn {
  &.full-width .dropdown-form-group { width: calc(100% - 37px); }
  button {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }
  + jb-btn {
    vertical-align: bottom;
    margin-bottom: 15px;
    .disabled-tooltip .jb-btn {
      &:hover { box-shadow: none; }
      &.small-btn {
        height: 34px;
        width: 37px;
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
        box-shadow: none;
        //border-left: 1px solid rgba(white, 0.7);
      }
      .btn-icon-section {
        padding-bottom: 3px;
        box-shadow: inset 0 0 0 500px rgba(black, 0.07); // Darken 7%
      }
    }
  }
  &.flat + jb-btn { margin-bottom: 0; }
}
