@import "./input.vars";

// Input
// --------------------------------------------------

:host {
  /**
   * @prop --background: Background of the input
   *
   * @prop --color: Color of the input text
   *
   * @prop --padding-top: Top padding of the input
   * @prop --padding-end: Right padding if direction is left-to-right, and left padding if direction is right-to-left of the input
   * @prop --padding-bottom: Bottom padding of the input
   * @prop --padding-start: Left padding if direction is left-to-right, and right padding if direction is right-to-left of the input
   *
   * @prop --placeholder-color: Color of the input placeholder text
   * @prop --placeholder-font-style: Font style of the input placeholder text
   * @prop --placeholder-font-weight: Font weight of the input placeholder text
   * @prop --placeholder-opacity: Opacity of the input placeholder text
   */
  --placeholder-color: initial;
  --placeholder-font-style: initial;
  --placeholder-font-weight: initial;
  --placeholder-opacity: .5;
  --padding-top: 0;
  --padding-end: 0;
  --padding-bottom: 0;
  --padding-start: 0;
  --background: transparent;
  --color: initial;

  display: flex;
  position: relative;

  flex: 1;
  align-items: center;

  width: 100%;

  /* stylelint-disable-next-line all */
  padding: 0 !important;

  background: var(--background);
  color: var(--color);

  font-family: $font-family-base;

  z-index: $z-index-item-input;
}

:host-context(ion-item:not(.item-label)) {
  --padding-start: 0;
}

:host(.ion-color) {
  color: current-color(base);
}

// Native Text Input
// --------------------------------------------------

.native-input {
  @include border-radius(var(--border-radius));
  @include padding(var(--padding-top), var(--padding-end), var(--padding-bottom), var(--padding-start));
  @include text-inherit();

  display: inline-block;

  flex: 1;

  width: 100%;
  max-width: 100%;
  max-height: 100%;

  border: 0;

  outline: none;

  background: transparent;

  box-sizing: border-box;
  appearance: none;

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

    font-family: inherit;
    font-style: var(--placeholder-font-style);
    font-weight: var(--placeholder-font-weight);

    opacity: var(--placeholder-opacity);
  }

  &:-webkit-autofill {
    background-color: transparent;
  }

  &:invalid {
    box-shadow: none;
  }

  &::-ms-clear {
    display: none;
  }
}

.native-input[disabled] {
  opacity: .4;
}



// Input Cover: Unfocused
// --------------------------------------------------
// The input cover is the div that actually receives the
// tap/click event when scroll assist is configured to true.
// This make it so the native input element is not clickable.
// This will only show when the scroll assist is configured
// otherwise the .input-cover will not be rendered at all
// The input cover is not clickable when the input is disabled
.cloned-input {
  @include position(0, null, null, 0);

  position: absolute;

  pointer-events: none;
}


// Clear Input Icon
// --------------------------------------------------

.input-clear-icon {
  @include margin(0);
  @include padding(0);
  @include background-position(center);

  border: 0;

  outline: none;

  background-color: transparent;
  background-repeat: no-repeat;

  visibility: hidden;
  appearance: none;
}

:host(.has-focus.has-value) .input-clear-icon {
  visibility: visible;
}


// Input Has focus
// --------------------------------------------------
// When the input has focus, then the input cover should be hidden

:host(.has-focus) {
  pointer-events: none;
}

:host(.has-focus) input,
:host(.has-focus) a,
:host(.has-focus) button {
  pointer-events: auto;
}
