@use '../abstracts/select_options' as *;
@use '../abstracts/variables' as *;
@use '../vendors/fortawesome-fontawesome/mixins' as fa;

label:not([for="nothing"]) {
  cursor: pointer;
}

input,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--input-color);
}

textarea {
  resize: vertical;
}

.checkbox,
.text-area,
.text-field {
  margin-bottom: var(--input-gutter);
  max-width: $input-max-width;

  input,
  textarea {
    max-width: $input-max-width;
  }

  & + p.help {
    margin-top: calc(-1 * var(--input-gutter));
  }
}

.checkbox {
  display: flex;

  i {
    cursor: pointer;
    font-size: 1.2rem;
    margin-right: 0.3rem;
    height: 1.2rem;
    width: 1.2rem;
  }

  label {
    padding-top: 0.05rem;
    cursor: pointer;
  }

  input {
    position: absolute;
    left: -1000px;
    opacity: 0;
  }

  &.has-badge {
    position: relative;

    .badge {
      top: 0.1em;
    }
  }

  &.is-disabled {
    i,
    label {
      color: var(--input-disabled-color);
      cursor: not-allowed;
    }
  }

  &.has-focus {
    i {
      outline: var(--input-focus-outline);
    }
  }

  & + p.help {
    margin-left: 1.1rem;
  }
}

.text-area,
.text-field {
  label {
    font-size: inherit;
    padding: 0.1rem 0.4em;
    display: block;
  }
}

.text-area,
.text-field {
  .input,
  input,
  textarea {
    background: var(--input-bg);
    color: var(--input-color);
    line-height: 2.2em;
    height: 2.2em;
    padding: 0.2em 0.5em;
    border: var(--input-border);
    border-radius: var(--input-border-radius);
    width: 100%;
    display: block;

    &::placeholder {
      color: var(--input-placeholder-color);
    }

    &[readonly] {
      background: var(--input-disabled-bg);
      color: var(--input-disabled-color);
      cursor: not-allowed;
    }

    &:focus {
      outline: var(--input-focus-outline);
      outline-width: 2px;
      outline-offset: -2px;
    }
  }

  .input {
    background: var(--input-disabled-bg);
    line-height: 1.8em;
    word-break: break-word;
    height: auto;
    max-height: none;
    cursor: not-allowed;

    &, a {
      color: var(--input-disabled-color);
    }
  }
}

.text-area textarea {
  line-height: 1.5em;
}

.text-area {
  textarea {
    min-height: 4rem;
  }
}

.form-actions {
  margin-top: var(--gutter);
  padding: var(--gutter-small) 0;

  > * {
    vertical-align: middle;
    margin-right: 0.8rem;
  }
}

.form-group {
  padding: var(--gutter-small) 0 var(--gutter) var(--gutter-small);
}

.inputs-side-by-side {
  margin-bottom: var(--input-gutter);
  display: flex;
  align-items: flex-end;

  button {
    white-space: pre;
    margin-left: var(--input-gutter);
  }

  .checkbox,
  .text-field {
    margin-bottom: 0;
    flex: 1 0 0;
  }
}

.select-field {
  line-height: 1.2em;
  height: calc(2.2em + var(--font-size) * 0.9 * 1.5);
  position: relative;
  overflow: visible;

  &.is-open {
    .select-field__options {
      box-shadow: inset -1px 1px 3px rgba(0, 0, 0, 0.1), 0px 3px 5px rgba(0, 0, 0, 0.3);
      height: auto;
      max-height: 10rem;
      display: block;
      overflow: auto;
      z-index: 1000;
    }
  }

  &:after {
    @include fa.icon(caret-down, solid);
    color: var(--input-color);
    position: absolute;
    bottom: 0.6rem;
    right: 0.6em;
    pointer-events: none;
  }

  &.is-open:after {
    @include fa.content(caret-up);
  }

  &.is-readonly:after {
    content: '-';
    text-align: center;
    width: 0.6em;
  }
}

.inputs-side-by-side .select-field:after {
  left: auto;
  right: 0.6em;
}

.select-field__options {
  @include select_options;
  height: 0;
  width: 100%;
  display: none;
  position: relative;
}

p.help {
  font-size: 0.9rem;
  padding: 0 0.4em;
}

.progress {
  background: var(--input-bg);
  border: var(--input-border);
  border-radius: var(--input-border-radius);
}

.progress__bar {
  background: var(--button-bg);
  color: var(--button-color);
  text-align: right;
  text-shadow: 0 1px 2px var(--button-bg);
  padding-left: 4px;
  padding-right: 4px;
  max-width: 100%;
  overflow: visible;
  transition: width 0.5s ease-in;
}

.text-field.has-password {
  position: relative;

  .text-field__toggle {
    color: var(--input-color);
    padding: 0; // override .sidebar-left__nav a
    position: absolute;
    top: 55%;
    right: 0.6em;
  }

  input {
    padding-right: 2em;
  }

  label + input + .text-field__toggle {
    top: 2em;
  }
}
