@import "./textarea.vars";

// Textarea
// --------------------------------------------------

:host {
  /**
   * @prop --background: Background of the textarea
   *
   * @prop --border-radius: Border radius of the textarea
   *
   * @prop --color: Color of the text
   *
   * @prop --placeholder-color: Color of the placeholder text
   * @prop --placeholder-font-style: Style of the placeholder text
   * @prop --placeholder-font-weight: Weight of the placeholder text
   * @prop --placeholder-opacity: Opacity of the placeholder text
   *
   * @prop --padding-top: Top padding of the textarea
   * @prop --padding-end: Right padding if direction is left-to-right, and left padding if direction is right-to-left of the textarea
   * @prop --padding-bottom: Bottom padding of the textarea
   * @prop --padding-start: Left padding if direction is left-to-right, and right padding if direction is right-to-left of the textarea
   */
  --background: initial;
  --color: initial;
  --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;
  --border-radius: 0;

  display: block;
  position: relative;

  flex: 1;

  width: 100%;

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

  font-family: $font-family-base;

  white-space: pre-wrap;

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

  box-sizing: border-box;
}

:host(.ion-color) {
  background: initial;
}

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

// Textarea Within An Item
// --------------------------------------------------

:host-context(ion-item) {
  align-self: baseline;
}

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


// Native Textarea
// --------------------------------------------------

.textarea-wrapper {
  min-width: inherit;
  max-width: inherit;
  min-height: inherit;
  max-height: inherit;
}

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

  display: block;

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

  border: 0;

  outline: none;

  background: transparent;
  box-sizing: border-box;
  resize: none;
  appearance: none;

  &::placeholder {
    @include padding(0);

    color: var(--placeholder-color);

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

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

.native-textarea[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;
}


// Item Floating: Placeholder
// ----------------------------------------------------------------
// When used with a floating item the placeholder should hide

:host-context(.item-label-floating.item-has-placeholder:not(.item-has-value)) {
  opacity: 0;
}

:host-context(.item-label-floating.item-has-placeholder:not(.item-has-value).item-has-focus) {
  transition: opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);

  opacity: 1;
}
