// Font Sizes
$mf-font-size: 1.1rem !default;
$mf-active-font-size: $mf-font-size * 0.6 !default;
$mf-active-top: -$mf-font-size * 0.8 !default;

// Margin & Paddings
$mf-gap: $mf-font-size * 1.5 !default;
$mf-min-height: 2.25rem;
$mf-spacer: $mf-font-size / 8 !default;
$mf-fieldset-margin: 0 0 $mf-gap * 2 !default;
$mf-checkbox-gap: $mf-font-size * 2 !default;
$mf-checkbox-top: 0 !default;
$mf-radio-margin: $mf-font-size / -4 !default;
$mf-icon-gutter: 1.375rem;
$mf-icon-top: 0.4375rem;

// Colors
$mf-input-color: $body-color !default;
$mf-border-color: #999 !default;
$mf-label-color: lighten($mf-border-color, 10%) !default;
$mf-active-color: darken($mf-border-color, 10%) !default;
$mf-focus-color: $brand-primary !default;
$mf-error-color: $brand-danger !default;
$mf-focus-border-color: $charcoal !default;

// Animation
$mf-transition-speed: 0.28s !default;

// The Styles for the form
fieldset {
  padding: 0;
  border: none;
}

// input 設定
.form-group {
  position: relative;
  display: flex;
  flex-direction: row;
  min-height: $mf-min-height;
  margin-top: ($mf-font-size * 0.2);

  .input-group {
    position: relative;
    display: block;
  }

  .input-icon {
    position: absolute;
  }


  //下拉選單
  &.select-form-group {
    .dropdown-toggle::after {
      display: none;
    }

    .dropdown-menu {
      width: 100%;
    }

    .dropdown-item {
      cursor: pointer;
      justify-content: space-between;

      .selected-icon {
        display: none;
        margin-left: 0.35rem;
      }

      &.selected {
        color: $mf-focus-color;

        .selected-icon {
          display: inline-block;
        }
      }
    }

    .bar::before {
      display: none;
    }
  }

  &.form-group-w-btn {
    .btn {
      align-self: flex-end;
    }
  }

  //一般input 有icon 要放右邊
  &.with-icon-right {
    input {
      padding-right: $mf-icon-gutter;
    }

    .input-icon {
      top: 30px;
      right: 4px;
      @include PC-small{
        top: 20px;
      }
    }
  }

  //input 有icon 要放左邊
  &.with-icon-left {
    input,
    textarea
    {
      padding-left: $mf-icon-gutter;

      ~ .control-label {
        padding-left: $mf-icon-gutter;
      }
    }

    select,
    input:focus,
    input:valid,
    input.form-file,
    input.has-value,
    textarea:focus,
    textarea:valid,
    textarea.form-file,
    textarea.has-value {
      color: $mf-input-color;

      ~ .control-label {
        padding-left: 0;
      }
    }

    .icon-left {
      left: 0;
    }
  }

  
  // error icon
  .error-icon{
    display: none;
  }

  &.has-error{
    .error-icon{
      display: inline-block;
      color: $theme-red;
    }
  }

  // 清除input icon
  .fa-times{
    cursor: pointer;
  }

  @include text-emphasis-variant(".text-secondary", $mf-label-color);
}

.form-inline {
  > .form-group,
  > .btn {
    display: inline-block;
    margin-bottom: 0;
  }
}

.form-help {
  margin-top: $mf-spacer;
  margin-left: $mf-spacer;
  color: $mf-label-color;
  font-size: $mf-active-font-size;

  .form-group & {
    position: absolute;
    width: 100%;
  }

  .checkbox & {
    position: relative;
    margin-bottom: $mf-font-size;
  }
}

.form-group {
  textarea {
    resize: none;
  }

  select {
    width: 100%;
    font-size: $mf-font-size;
    height: ($mf-font-size * 1.6);
    padding: $mf-spacer $mf-spacer ($mf-spacer / 2);
    background: none;
    border: none;
    line-height: 1.6;
    box-shadow: none;
  }

  .control-label {
    position: absolute;
    top: ($mf-font-size / 4);
    left: 0;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    pointer-events: none;
    padding-left: $mf-spacer;
    z-index: 1;
    color: $mf-label-color;
    font-size: $mf-font-size;
    font-weight: normal;
    transition: all $mf-transition-speed ease;
  }

  .bar {
    position: relative;
    border-bottom: ($mf-font-size / 16) solid $mf-border-color;
    display: block;

    &::before {
      content: '';
      height: ($mf-font-size / 8);
      width: 0;
      left: 50%;
      bottom: ($mf-font-size / -16);
      position: absolute;
      background: $mf-focus-border-color;
      transition: left $mf-transition-speed ease, width $mf-transition-speed ease;
      z-index: 2;
    }
  }

  input,
  textarea {
    display: block;
    background: none;
    padding: $mf-spacer $mf-spacer ($mf-spacer / 2);
    font-size: $mf-font-size;
    border-width: 0;
    line-height: 1.9;
    width: 100%;
    box-shadow: none;
    @include PC-small{
      font-size: 15px;
      line-height: 1.5;
    }
  }

  input[type="file"] {
    line-height: 1;

    ~ .bar {
      display: none;
    }
  }

  &.show input,
  select,
  input:focus,
  input:valid,
  input.form-file,
  input.has-value,
  textarea:focus,
  textarea:valid,
  textarea.form-file,
  textarea.has-value {
    color: $text-color;

    ~ .control-label {
      font-size: $mf-active-font-size;
      color: $main-theme;
      text-transform: uppercase;
      top: $mf-active-top;
      left: 0;
    }
  }

  select,
  input,
  textarea {
    &:focus {
      outline: none;

      ~ .control-label {
        color: $main-theme;
      }

      ~ .bar {
        &::before {
          width: 100%;
          left: 0;
        }
      }
    }
  }
}

.valid {
  .legend.legend,
  &.form-group .control-label.control-label {
    color: $main-theme;
  }

  .valid-icon {
    display: inline-block;
    color: $main-theme;
  }
}

.has-error {
  .legend.legend,
  &.form-group .control-label.control-label {
    color: $mf-error-color;
  }

  &.form-group,
  &.checkbox {
    .form-help,
    .helper {
      color: $mf-error-color;
    }
  }

  .bar {
    &::before {
      background: $mf-error-color;
      left: 0;
      width: 100%;
    }
  }
}
