@import "../../globals.md";
@import "./input";

// Material Design Input
// --------------------------------------------------

$text-input-md-background-color:            $list-md-background-color !default;
$text-input-md-highlight-color:             color($colors-md, primary) !default;
$text-input-md-hightlight-color-valid:      color($colors-md, secondary) !default;
$text-input-md-hightlight-color-invalid:    color($colors-md, danger) !default;

$text-input-md-margin-top:                  $item-md-padding-top !default;
$text-input-md-margin-right:                ($item-md-padding-right / 2) !default;
$text-input-md-margin-bottom:               $item-md-padding-bottom !default;
$text-input-md-margin-left:                 ($item-md-padding-left / 2) !default;

$text-input-md-input-clear-icon-width:      30px !default;
$text-input-md-input-clear-icon-color:      #5b5b5b !default;
$text-input-md-input-clear-icon-svg:        "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><polygon fill='" + $text-input-md-input-clear-icon-color + "' points='405,136.798 375.202,107 256,226.202 136.798,107 107,136.798 226.202,256 107,375.202 136.798,405 256,285.798 375.202,405 405,375.202 285.798,256'/></svg>" !default;
$text-input-md-input-clear-icon-size:       22px !default;

$text-input-md-show-success-highlight:      true !default;
$text-input-md-show-error-highlight:        true !default;


// Material Design Default Input
// --------------------------------------------------

.text-input {
  margin: $text-input-md-margin-top $text-input-md-margin-right $text-input-md-margin-bottom $text-input-md-margin-left;
  padding: 0;

  width: calc(100% - #{$text-input-md-margin-right} - #{$text-input-md-margin-left});
}


// Material Design Inset Input
// --------------------------------------------------

.inset-input {
  margin: ($item-md-padding-top / 2) $item-md-padding-right ($item-md-padding-bottom / 2) $item-md-padding-left;
  padding: ($item-md-padding-top / 2) ($item-md-padding-right / 2) ($item-md-padding-bottom / 2) ($item-md-padding-left / 2);
}


// Material Design Highlighted Input
// --------------------------------------------------

.item-input::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: $item-md-padding-left;

  border-bottom-width: 2px;
  border-bottom-style: solid;
  border-bottom-color: transparent;
  content: "";
}

.item-input.input-has-focus::after {
  border-bottom-color: $text-input-md-highlight-color;
}

@if($text-input-md-show-success-highlight) {
  .item-input.ng-valid.input-has-value {
    &::after {
      border-bottom-color: $text-input-md-hightlight-color-valid;
    }

    &.input-has-focus::after {
      border-bottom-color: $text-input-md-highlight-color;
    }
  }
}

@if($text-input-md-show-error-highlight) {
  .item-input.ng-invalid.ng-touched {
    &::after {
      border-bottom-color: $text-input-md-hightlight-color-invalid;
    }

    &.input-has-focus::after {
      border-bottom-color: $text-input-md-highlight-color;
    }
  }
}


// Material Design Stacked & Floating Inputs
// --------------------------------------------------

.item-label-stacked .text-input,
.item-label-floating .text-input {
  margin-top: 8px;
  margin-bottom: 8px;
  margin-left: 0;

  width: calc(100% - #{$text-input-md-margin-right});
}

.item-label-stacked ion-select,
.item-label-floating ion-select {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 0;
}

.item-label-floating .text-input.cloned-input {
  top: 32px;
}

.item-label-stacked .text-input.cloned-input {
  top: 27px;
}


// Material Design Clear Input Icon
// --------------------------------------------------

ion-input[clearInput] {
  position: relative;

  .text-input {
    padding-right: $text-input-md-input-clear-icon-width;
  }
}

.text-input-clear-icon {
  @include svg-background-image($text-input-md-input-clear-icon-svg);

  right: ($item-md-padding-right / 2);
  bottom: 4px;

  width: $text-input-md-input-clear-icon-width;

  background-size: $text-input-md-input-clear-icon-size;
}
