// Embedded icons from Open Iconic.
// Released under MIT and copyright 2014 Waybury.
// https://useiconic.com/open

// Checkboxes and radios
//
// Base class takes care of all the key behavioral aspects.

.custom-control {
  position: relative;
  display: block;
  min-height: $line-height-base;
  padding-left: $custom-control-gutter;
  color-adjust: exact; // Keep themed appearance for print
  z-index: 0;
}

.custom-control-inline {
  display: inline-flex;
  margin-right: $custom-control-spacer-x;
}

.custom-control-input {
  position: absolute;
  left: 0;
  z-index: 0; // Put the input behind the label so it doesn't overlay text
  width: $custom-control-indicator-size;
  height: $custom-control-indicator-size;
  top: 2px;
  opacity: 0;
  &:hover{
    cursor: pointer;
  }

  [readonly] & {
    &:not(:checked):not(:indeterminate):not(:disabled) {

      ~ .custom-control-indicator::before {
        background-color: $custom-control-indicator-readonly-bg !important;
      }

      &:hover {
        ~ .custom-control-indicator::before {
          border-color: $custom-control-indicator-readonly-border;
          box-shadow: inset 0 0 0 1px $custom-control-indicator-readonly-border;
        }
      }
      &:focus {
        ~ .custom-control-indicator::before {
          border-color: $custom-control-indicator-readonly-border;
          outline: 1px solid $custom-control-indicator-readonly-border;
          box-shadow: inset 0 0 0 1px $custom-control-indicator-readonly-border;
        }
      }
    }

    &:checked {
      ~ .custom-control-indicator::before {
        color: $custom-control-indicator-checked-color;
        border-color: $custom-control-indicator-readonly-border;
        @include gradient-bg($custom-control-indicator-readonly-active-bg);
        @include box-shadow($custom-control-indicator-readonly-box-shadow);
      }
      &:hover {
        ~ .custom-control-indicator::before {
          background-color: $custom-control-indicator-readonly-active-bg !important;
          border-color: $custom-control-indicator-readonly-border !important;
          box-shadow: unset;
        }

        &:disabled {
          ~ .custom-control-indicator::before {
            background-color: $custom-control-indicator-checked-disabled-bg !important;
            border-color: transparent !important;
          }
        }
      }
      &:focus {
        ~ .custom-control-indicator::before {
          background-color: $custom-control-indicator-readonly-active-bg !important;
          border-color: $white !important;
          outline: 2px solid $custom-control-indicator-readonly-border !important;
          box-shadow: unset;
        }
      }
    }

    &:indeterminate {
      ~ .custom-control-indicator {
        &::before {
          border-color: $custom-control-indicator-readonly-border !important;
          background-color: $custom-control-indicator-readonly-active-bg !important;
        }
      }

      &:focus[aria-readonly="true"] {
        ~ .custom-control-indicator::before {
          background-color: $custom-control-indicator-readonly-active-bg !important;
          border-color: $white !important;
          outline: 2px solid $custom-control-indicator-readonly-border !important;
          box-shadow: unset;
        }
      }
    }
  }

  &:not(:checked):not(:indeterminate):not(:disabled) {
    &:hover {
      ~ .custom-control-indicator::before {
        border-color: $primary;
        box-shadow: inset 0 0 0 1px $primary;
      }
    }
    &:focus {
      ~ .custom-control-indicator::before {
        outline: 1px solid $primary;
        box-shadow: inset 0 0 0 1px $primary;
      }
    }
  }

  &:checked {
    ~ .custom-control-indicator::before {
      color: $custom-control-indicator-checked-color;
      border-color: $custom-control-indicator-checked-bg;
      @include gradient-bg($custom-control-indicator-checked-bg);
      @include box-shadow($custom-control-indicator-checked-box-shadow);
    }
    &:hover {
      ~ .custom-control-indicator::before {
        background-color: map-get($button-hover-colors, "secondary") !important;
        border-color: map-get($button-hover-colors, "secondary") !important;
        box-shadow: unset;
      }

      &:disabled {
        ~ .custom-control-indicator::before {
          background-color: $custom-control-indicator-checked-disabled-bg !important;
          border-color: transparent !important;
        }
      }
    }
    &:focus {
      ~ .custom-control-indicator::before {
        background-color: map-get($button-hover-colors, "secondary") !important;
        border-color: map-get($button-focus-colors, "secondary") !important;
        outline: 2px solid map-get($button-hover-colors, "secondary") !important;
        box-shadow: unset;
      }
    }
  }

  &:focus ~ .custom-control-indicator::before {
    // the mixin is not used here to make sure there is feedback

    /* Add focus ring as naturally as we can */
    // outline: auto 2px Highlight;
    // outline: auto 5px -webkit-focus-ring-color;
    box-shadow: 0px 0px 0px 1px $primary;
  }

  &:focus:not(:checked) ~ .custom-control-indicator::before {
    border-color: $primary;
  }
  &:not(:disabled):active ~ .custom-control-indicator::before {
    color: $custom-control-indicator-active-color;
    background-color: $custom-control-indicator-active-bg;
    border-color: $custom-control-indicator-checked-disabled-bg;
    @include box-shadow($custom-control-indicator-active-box-shadow);
  }

  // Use [disabled] and :disabled to work around https://github.com/twbs/bootstrap/issues/28247
  &[disabled],
  &:disabled {
    ~ .custom-control-indicator {
      // color: $custom-control-label-disabled-color;

      &::before {
        background-color: $custom-control-indicator-disabled-bg;
        @include gradient-bg($custom-control-indicator-disabled-bg);
      }
      @include hover-focus {
        cursor: not-allowed;
        &::before {
          border-color: $custom-control-label-disabled-color;
        }
      }
    }
    &:checked {
      ~ .custom-control-indicator {
        &::before {
          border-color: transparent;
        }
        @include hover-focus {
          cursor: not-allowed;
          &::before {
            background-color: $custom-control-indicator-checked-disabled-bg !important;
            border-color: transparent !important;
          }
        }
      }
    }
  }
}

.is-invalid .custom-control-input {
  &:not(:checked):not(:disabled) {
    &:hover {
      ~ .custom-control-indicator::before {
        border-color: $red;
        box-shadow: inset 0 0 0 1px $red;
      }
    }
    &:focus {
      ~ .custom-control-indicator::before {
        outline: 1px solid $red;
        box-shadow: inset 0 0 0 1px $red;
      }
    }
  }

  &:checked {
    ~ .custom-control-indicator::before {
      border-color: $custom-control-indicator-checked-error-bg;
      @include gradient-bg($custom-control-indicator-checked-error-bg);
    }
    &:hover {
      ~ .custom-control-indicator::before {
        background-color: map-get($button-hover-colors, "danger") !important;
        border-color: map-get($button-hover-colors, "danger") !important;
      }
    }
    &:focus {
      ~ .custom-control-indicator::before {
        background-color: map-get($button-hover-colors, "danger") !important;
        border-color: map-get($button-focus-colors, "danger") !important;
        outline: 2px solid map-get($button-hover-colors, "danger") !important;
      }
    }
  }

  &:focus ~ .custom-control-indicator::before {
    box-shadow: 0px 0px 0px 1px $red;
  }

  &:focus:not(:checked) ~ .custom-control-indicator::before {
    border-color: $red;
  }
  &:not(:disabled):active ~ .custom-control-indicator::before {
    background-color: $custom-control-indicator-active-error-bg;
    border-color: $custom-control-indicator-checked-disabled-bg;
  }
}

// Checkboxes
//
// Tweak just a few things for checkboxes.

.custom-checkbox {
  // Custom control indicators
  //
  .custom-control-indicator{
    position: absolute;
    width: $custom-control-indicator-size;
    height: $custom-control-indicator-size;
    z-index: -1;

    // Background-color and (when enabled) gradient
    &::before {
      position: absolute;
      top: 2px;
      left: -$custom-control-gutter;
      display: block;
      width: $custom-control-indicator-size;
      height: $custom-control-indicator-size;
      pointer-events: none;
      content: "";
      background-color: $custom-control-indicator-bg;
      border: $input-border-color solid 2px;
      //transition: all 0.3s;
      @include box-shadow($custom-control-indicator-box-shadow);
    }

    // Foreground (icon)
    &::after {
      position: absolute;
      top: 4px;
      left: -22px;//-$custom-control-gutter;
      display: block;
      width: 1rem;//$custom-control-indicator-size;
      height: 1rem;//$custom-control-indicator-size;
      content: "";
      background-repeat: no-repeat;
    }
  }
  // Build the custom controls out of pseudo-elements.
  .custom-control-label {
    display: inline;
    position: relative;
    margin-bottom: 0;
    padding-left: 0.5rem;

    @include hover-focus {
      cursor: pointer;
    }
  }

  &.is-invalid {
    .custom-control-indicator {
      // Background-color and (when enabled) gradient
      &::before {
        border-color: $red;
      }
    }
  }

  .custom-control-indicator::before {
    @include border-radius($custom-checkbox-indicator-border-radius);
  }

  .custom-control-input:checked ~ .custom-control-indicator {
    &::after {
      background-image: escape-svg($custom-checkbox-indicator-icon-checked);
    }
  }

  .custom-control-input:indeterminate ~ .custom-control-indicator {
    &::before {
      border-color: $custom-checkbox-indicator-indeterminate-border;
      @include gradient-bg($custom-checkbox-indicator-indeterminate-bg);
      @include box-shadow($custom-checkbox-indicator-indeterminate-box-shadow);
    }
    &::after {
      background-image: escape-svg($custom-checkbox-indicator-icon-indeterminate);
    }
  }

  &.is-invalid .custom-control-input:indeterminate ~ .custom-control-label {
    &::before {
      border-color: $red;
      background: $red;
    }
  }

  .custom-control-input:indeterminate:focus {
    ~ .custom-control-indicator::before {
      background-color: map-get($button-hover-colors, "secondary") !important;
      border-color: map-get($button-focus-colors, "secondary") !important;
      outline: 2px solid map-get($button-hover-colors, "secondary") !important;
      box-shadow: unset;
    }
  }

  .custom-control-input:disabled {
    &:checked ~ .custom-control-indicator::before {
      background-color: $custom-control-indicator-checked-disabled-bg;
      border-color: transparent;
    }

    & ~ .custom-control-indicator::before {
      border-color: $custom-control-border-disabled-color;
    }

    &:indeterminate ~ .custom-control-label::before {
      border-color: transparent;
    }

    &:indeterminate ~ .custom-control-indicator::before {
      background-color: $custom-control-indicator-checked-disabled-bg;
      border-color: transparent;
    }
  }
}

// Radios
//
// Tweak just a few things for radios.
.custom-radio {
  // Custom control indicators
  //
  // Build the custom controls out of pseudo-elements.
  .custom-control-label {
    position: relative;
    margin-bottom: 0;
    padding-left: 0.5rem;

    @include hover-focus {
      cursor: pointer;
    }


  }

  .custom-control-indicator{
    position: absolute;
    width: $custom-control-indicator-size;
    height: $custom-control-indicator-size;
    z-index: -1;

    &::before {
      position: absolute;
      top: 2px;
      left: -$custom-control-gutter;
      display: block;
      width: $custom-control-indicator-size;
      height: $custom-control-indicator-size;
      pointer-events: none;
      content: "";
      background-color: $custom-control-indicator-bg;
      border: $input-border-color solid 2px;
      border-radius: $custom-radio-indicator-border-radius;
      //transition: all 0.3s;
      @include box-shadow($custom-control-indicator-box-shadow);
    }

    // Foreground (icon)
    &::after {
      position: absolute;
      top: .5rem;
      left: -18px;//-$custom-control-gutter;
      display: block;
      width: .5rem;//$custom-control-indicator-size;
      height: .5rem;//$custom-control-indicator-size;
      content: "";
      background-repeat: no-repeat;
    }
  }

  .custom-control-input{
    &:not(:disabled) {
      &:hover {
        ~.custom-control-indicator::before {
          border-color: $primary;
          box-shadow: inset 0 0 0 1px $primary;
        }
      }
    }
    // Background-color and (when enabled) gradient
    &:checked ~ .custom-control-indicator {
      &::after {
        background-image: escape-svg($custom-radio-indicator-icon-checked);
      }
    }
    &:disabled{
      & ~ .custom-control-indicator::before {
        border-color: $custom-control-border-disabled-color;
      }

      &:checked ~ .custom-control-indicator::before {
        @include gradient-bg($custom-control-indicator-checked-disabled-bg);
        border-color: transparent;
      }
    }
  }
}

// Toggle
//
.custom-toggle {
  .custom-control-label {
    display: flex;
    align-items: center;
  }
}

// Select
//
// Replaces the browser default select with a custom one, mostly pulled from
// http://primercss.io.
//

.custom-select {
  display: block;
  //max-width: 100%;
  width: 100%;
  height: $input-height;
  padding: $custom-select-padding-y ($custom-select-padding-x + $custom-select-indicator-padding)
    $custom-select-padding-y $custom-select-padding-x;
  line-height: $custom-select-line-height;
  color: $custom-select-color;
  vertical-align: middle;
  background: $custom-select-bg $custom-select-indicator no-repeat right $custom-select-padding-x center;
  background-size: $custom-select-bg-size;
  @if $enable-rounded {
    border-radius: $custom-select-border-radius;
  } @else {
    border-radius: 0;
  }
  -webkit-appearance: none;

  &:focus {
    border-color: $custom-select-focus-border-color;
    outline: none;

    &::-ms-value {
      // For visual consistency with other platforms/browsers,
      // supress the default white text on blue background highlight given to
      // the selected option text when the (still closed) <select> receives focus
      // in IE and (under certain conditions) Edge.
      // See https://github.com/twbs/bootstrap/issues/19398.
      color: $input-color;
      background-color: $input-bg;
    }
  }

  &[multiple],
  &[size]:not([size="1"]) {
    height: auto;
    padding-right: $custom-select-padding-x;
    background-image: none;
  }

  &:disabled {
    color: $custom-select-disabled-color;
    background-color: $custom-select-disabled-bg;
  }

  // Hides the default caret in IE11
  &::-ms-expand {
    opacity: 0;
  }
}

// File
//
// Custom file input.

.custom-file {
  position: relative;
  display: inline-block;
  max-width: 100%;
  height: $custom-file-height;
  margin-bottom: 0;
}

.custom-file-input {
  position: relative;
  z-index: 2;
  width: 100%;
  height: $custom-file-height;
  margin: 0;
  opacity: 0;

  &:focus ~ .custom-file-control {
    border-color: $custom-file-focus-border-color;
    box-shadow: $custom-file-focus-box-shadow;

    &::before {
      border-color: $custom-file-focus-border-color;
    }
  }

  @each $lang, $value in $custom-file-text {
    &:lang(#{$lang}) ~ .custom-file-label::after {
      content: $value;
    }
  }
}

.custom-file-label {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1;
  height: $custom-file-height;
  padding: $custom-file-padding-y $custom-file-padding-x;
  line-height: $custom-file-line-height;
  color: $custom-file-color;
  background-color: $custom-file-bg;
  border: $custom-file-border-width solid $custom-file-border-color;
  @include border-radius($custom-file-border-radius);
  @include box-shadow($custom-file-box-shadow);

  &::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    display: block;
    height: calc(#{$custom-file-height} - #{$custom-file-border-width} * 2);
    padding: $custom-file-padding-y $custom-file-padding-x;
    line-height: $custom-file-line-height;
    color: $custom-file-button-color;
    content: "Browse";
    @include gradient-bg($custom-file-button-bg);
    border-left: $custom-file-border-width solid $custom-file-border-color;
    @include border-radius(0 $custom-file-border-radius $custom-file-border-radius 0);
  }
}
