@import "../Tokens/tokens.scss";
@import "../../common/scss/helpers";

/*
  Textfield basestyles
*/
.textfield {
  position: relative;

  // Placeholder
  .textfield-placeholder {
    position: relative;
    height: 20px;
    font-size: 14px;
    font-weight: bold;
    color: rgba(#1D1C28, 0.5);

    label {
      margin-left: 0;
    }
  }

  // Base style for component input
  input,
  textarea {
    // reset
    background: none;
    border: 0;
    color: inherit;
    font: inherit;
    line-height: normal;
    overflow: visible;
    padding: 0;
    text-decoration: none;
    border-radius: 0;
    font-weight: normal;
    box-shadow: none;
    outline: 0;
    position: relative;
    font-size: 18px;
    line-height: 24px;
    display: block;
    width: 100%;

    // Gray bottom border
    border-bottom: 1px solid #A3A3A3;

    &::placeholder {
      color: rgba(#1D1C28, 0.58);
      font-style: italic;
    }

    &:active,
    &:visited,
    &:focus {
      color: inherit;
    }

    &[disabled] {
      cursor: not-allowed;
      opacity: 0.5;
    }
  }

  // Only if textarea
  textarea {
    resize: vertical;
  }

  // If the input is rounded
  &.rounded {
    // Only for input
    input {
      height: 48px;
      line-height: 48px;
      font-size: 16px;
      padding: 0 ($baseUnit * 3);
    }

    // Only for text area
    textarea {
      padding: $baseUnit ($baseUnit * 2);
    }

    // Common
    input, textarea {
      width: 100%;
      border-radius: 24px;
      background: #fff;
      border: 1px solid #1D1D26;
  
      &:active,
      &:visited,
      &:focus {
          color: inherit;
          outline: 0;
      }
  
      &:active,
      &:focus {
        box-shadow: 0 0 0 4px $lightBlue;
        border-color: #1D1D26;
      }

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

  // Details (Hints and errors)
  .textfield-details {
    height: 20px;
    
    overflow: hidden;
  
    .details-text {
      padding: 0;
      margin-top: 0.3rem;
      font-size: 12px;
      color: #777;
    }
  }

  // If focused
  &.focused:not(.rounded) {
    .textfield-details::before {
      position: absolute;
      content: '';
      left: 0;
      right: 0;
      border-top: 4px solid $lightBlue;
    }

    &.error {
      .textfield-details::before {
        border-top: 2px solid $red;
      }
    }
  }

  // If error
  &.error {
    input,
    textarea {
      border-bottom: 1px solid $red;

      &::placeholder {
        color: $red;
      }
    }

    .details-text {
      color: $red;
      font-weight: bold;
    }
  }

  // If rounded
  &.rounded {
    .textfield-placeholder {
      padding-left: $baseUnit * 2;
    }

    .textfield-details {
      padding-left: $baseUnit * 3;
    }

    textarea {
      border-bottom-right-radius: 0;
    }
  }

  // If no border
  &.no-border {
    input, textarea {
      border: none;
      border-bottom: none;
    }

    textarea {
      resize: none;
    }
  }
}
