/*------------------------------------------------------------
FIELDS
input, textarea, select, number, checkbox, radio, switch
====================================*/

/* Select */
select.selectpicker {
  display: block !important;
  color: $input-color;
  appearance: none;
}
.bootstrap-select {
  // Bouton
  &>.dropdown-toggle {
    display: inline-flex;
    justify-content: space-between;
    align-items: center;
    height: $custom-select-height;
    padding: $custom-select-padding-y $custom-select-padding-x;
    text-transform: none;
    font-weight: $custom-select-font-weight;
    font-size: $custom-select-font-size;
    color: $custom-select-color;
    background: $custom-select-bg;
    border: $custom-select-border-width solid $custom-select-border-color;
    border-radius: $custom-select-border-radius;
    outline: none;

    // Hover
    &:hover {
      color: $custom-select-color;
      background: $custom-select-bg;
      border: $custom-select-border-width solid $custom-select-border-color;
      box-shadow: initial;
    }

    // Selected
    &.active {
      background: $custom-select-bg;
      border: $custom-select-border-width solid $custom-select-border-color;
      color: $input-color;
      box-shadow: $custom-select-box-shadow;
    }

    // Actif
    &:active,
    &:focus {
      outline: none !important; // override library
      color: $input-color;
      background-color: $custom-select-bg;
      border: $custom-select-focus-width solid $custom-select-focus-border-color;
      box-shadow: $custom-select-focus-box-shadow;
    }

    // Icon
    &:after {
      content: '';
      width: $custom-select-icon-width;
      height: $custom-select-icon-height;
      background: {
        image: $custom-select-icon;
        repeat: no-repeat;
        size: contain;
      };
      border: none;
      transform: rotate(180deg);
    }

    // Text
    .filter-option {
      display: flex;
      align-items: center;
      color: $input-color;
    }
  }

  // menu ouvert
  &.show {
    // Bouton
    &>.dropdown-toggle,
    &>.dropdown-toggle:hover {
      color: $input-color;
      background-color: $custom-select-bg;
      border: $custom-select-focus-width solid $custom-select-focus-border-color;
      box-shadow: $custom-select-focus-box-shadow;
    }
  }
  .dropdown-menu {
    margin: 0;
    padding: 0;
    border-color: $custom-select-focus-border-color;
    box-shadow: $custom-select-focus-box-shadow;
    &[x-placement=bottom-start] {
      padding-top: $custom-select-border-radius;
      margin-top: -$custom-select-border-width - $custom-select-border-radius;
      border-top: 0;
      border-top-left-radius: 0;
      border-top-right-radius: 0;
      border-bottom-left-radius: $custom-select-border-radius;
      border-bottom-right-radius: $custom-select-border-radius;
    }
    &[x-placement=top-start] {
      padding-bottom: $custom-select-border-radius;
      margin-bottom: -$custom-select-border-width;
      border-bottom: 0;
      border-top-left-radius: $custom-select-border-radius;
      border-top-right-radius: $custom-select-border-radius;
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
    }
  }

  // options
  .dropdown-item {
    padding: $custom-select-dropdown-padding-y $custom-select-dropdown-padding-x;
    white-space: normal;
    &:active, &.active {
      color: $custom-select-dropdown-active-color;
      background: $custom-select-dropdown-active-bg;
    }
    &:hover, &:focus {
      color: $custom-select-dropdown-hover-color;
      background: $custom-select-dropdown-hover-bg;
    }
  }
}
.bootstrap-select.disabled {
  & > .dropdown-toggle {
    opacity: 1;
    background: $custom-select-disabled-bg;
    border-color: $custom-select-border-color;
    box-shadow: $custom-select-box-shadow;
    cursor: default;
  }
}

/* Textarea */
textarea.form-control {
  min-height: $input-height;
  padding: $input-padding-x;
}

/* checkbox, radio, switch */
.custom-control {
  display: flex;
  padding: 0;
  margin-bottom: 0.5rem;
  min-height: $custom-control-indicator-size;

  input:checked ~ .custom-control-field {
    border-color: $custom-control-indicator-checked-border-color;
  }
}
.custom-control-field {
  display: inline-block;
  position: relative;
  flex-shrink: 0;
  margin-right: $custom-control-gutter*2;
  background: $custom-control-indicator-bg;
  border: $custom-control-indicator-border-width solid $custom-control-indicator-border-color;
  &:before {
    content: '';
    display: inline-block;
    position: absolute;
  }
}
.custom-control-text {
  align-self: center;
  font-size: $input-font-size;
  font-weight: $custom-checkbox-font-weight;
}
.custom-control.disabled {
  .custom-control-field,
  input:checked ~ .custom-control-field{
    border-color: $custom-control-indicator-disabled-bg;
  }

  .custom-control-text {
    color: $custom-control-label-disabled-color;
  }
}

/* checkbox */
.custom-checkbox {
  .custom-control-field {
    width: $custom-control-indicator-size;
    height: $custom-control-indicator-size;
    border-radius: $custom-checkbox-indicator-border-radius;
  }

  input:checked ~ .custom-control-field:before {
    width: $custom-checkbox-indicator-checked-width;
    height: $custom-checkbox-indicator-checked-height;
    background: $custom-control-indicator-checked-bg left top no-repeat;
    background-image: str_replace($custom-checkbox-indicator-icon-checked, "#", "%23");
    background-size: contain;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}
.custom-checkbox.disabled {
  input:checked ~ .custom-control-field:before {
    background-image: str_replace(str_replace($custom-checkbox-indicator-icon-checked, "#{$custom-control-indicator-checked-color}", "#{$custom-control-indicator-disabled-bg}"), "#", "%23");
  }
}

/* radio */
.custom-radio {
  .custom-control-field {
    width: $custom-control-indicator-size;
    height: $custom-control-indicator-size;
    border-radius: 100%;
  }

  input:checked ~ .custom-control-field:before {
    width: $custom-radio-indicator-checked-width;
    height: $custom-radio-indicator-checked-height;
    background: $custom-radio-indicator-checked-bg;
    position: absolute;
    left: 50%;
    top: 50%;
    border-radius: 100%;
    transform: translate(-50%, -50%);
  }
}
.custom-radio.disabled {
  input:checked ~ .custom-control-field:before {
    background: $custom-control-indicator-disabled-bg;
  }
}

/* switch */
.custom-switch {
  .custom-control-field {
    width: $custom-switch-width;
    height: $custom-control-indicator-size;
    border-radius: $custom-control-indicator-size*0.5;

    &:before {
      top: 50%;
      left: $custom-switch-padding-x;
      width: $custom-switch-indicator-checked-width;
      height: $custom-switch-indicator-checked-height;
      background: $custom-switch-indicator-bg;
      border-radius: 100%;
      transform: translateY(-50%);
      transition: 0.3s;
    }
  }

  input:checked ~ .custom-control-field {
    background: $custom-switch-checked-bg;
    border-color: $custom-switch-checked-border-color;
    &:before {
      left: 100%;
      margin-left: -$custom-switch-padding-x;
      background: $custom-switch-checked-indicator-bg;
      transform: translate(-100%, -50%);
    }
  }
}
.custom-switch.disabled {
  .custom-control-field {
    &:before {
      background: $custom-control-indicator-disabled-bg;
    }
  }

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

/* number */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield;
}
.input-number {
  padding-left: 1rem;
  padding-right: 4rem;
  text-align: center;
}
.input-group.custom-input-number {
  position: relative;
  height: $input-height;

  & > .form-control {
    padding-left: 1rem;
    padding-right: 4rem;
    border-right: $input-border-width solid $input-border-color;
    &:focus {
      border-right: $input-border-width solid $input-focus-border-color;
    }
  }
  .input-group-prepend, .input-group-append {
    position: absolute;
    right: $input-border-width;
    z-index: 4;
    min-width: 0;
    width: 3rem;
    height: 50%;
    .btn {
      width: 100%;
      padding: 0;
      border: 0;
      &:before {
        content:'';
        display: block;
        background: {
          image: $custom-number-icon;
          size: 1rem 1rem;
          repeat: no-repeat;
          position: center right;
        };
        width: 1rem;
        height: 0.5rem;
        margin-top: 0.5rem;
        transition: .5s;
      }
      &:hover {
        background: transparent;
        box-shadow: none;
        &:before {
          opacity: 0.5;
        }
      }
    }
  }
  .input-group-prepend {
    bottom: 0;
    .btn {
      &:before {
        margin-top: -0.6rem;
        margin-left: -0.1rem;
        transform: rotate(180deg);
      }
    }
  }
  .input-group-append {
    top: 0;
  }
}
