/**Variable**/
@import './helpers/mixin.scss';

$iconWidth: 1.6em;

.vhb-input--inner {
  width: 100%;
  height: 100%;
  border-radius: $vhb-border-radius;
  outline: 0;
  margin: 0;
  font-size: inherit;
  font-family: inherit;
  line-height: inherit;
  padding: 0 0.6em;
  color: $vhb-font-color;
  border: 1px solid $vhb-input-border-color;
  background-color: $vhb-input-background-color;
  box-shadow: none;
  &::placeholder {
    color: $vhb-input-placeholder-color;
  }
  &::-webkit-autofill {
    background-color: $vhb-input-background-color;
  }
  &[type="number"] {
    appearance: none;
    -moz-appearance: textfield;
  }
  &[type="search"],
  &[type="search"]::-webkit-search-cancel-button,
  &[type="number"]::-webkit-outer-spin-button,
  &[type="number"]::-webkit-inner-spin-button {
    appearance: none;
  }
  &[disabled] {
    cursor: not-allowed;
    color: $vhb-disabled-color;
    background-color: $vhb-input-disabled-background-color;
  }
}

.vhb-input {
  display: inline-block;
  position: relative;
  width: 180px;
  &.is--disabled {
    .vhb-input--date-picker-suffix,
    .vhb-input--search-suffix,
    .vhb-input--suffix,
    .vhb-input--password-suffix,
    .vhb-input--number-suffix {
      cursor: no-drop;
    }
  }
  &:not(.is--disabled) {
    .vhb-input--search-suffix,
    .vhb-input--clear-icon,
    .vhb-input--password-suffix,
    .vhb-input--number-suffix {
      cursor: pointer;
    }
    &.is--active {
      .vhb-input--inner {
        border: 1px solid $vhb-primary-color;
      }
    }
  }
  .vhb-input--prefix,
  .vhb-input--suffix,
  .vhb-input--extra-suffix {
    display: flex;
    position: absolute;
    top: 0;
    width: $iconWidth;
    height: 100%;
    user-select: none;
    align-items: center;
    justify-content: center;
    color: $vhb-table-column-icon-border-color;
  }
}

// 前缀图标
.vhb-input {
  .vhb-input--prefix {
    left: 0.2em;
  }
  &.is--prefix {
    .vhb-input--inner {
      padding-left: $iconWidth + 0.2em;
    }
  }
}

// 后缀图标
.vhb-input {
  .vhb-input--clear-icon {
    display: none;
  }
  .vhb-input--suffix,
  .vhb-input--extra-suffix {
    right: 0.2em;
  }
  &.is--suffix {
    .vhb-input--inner {
      padding-right: $iconWidth + 0.2em;
    }
  }
  &.is--left {
    .vhb-input--inner {
      text-align: left;
    }
  }
  &.is--center {
    .vhb-input--inner {
      text-align: center;
    }
  }
  &.is--right {
    .vhb-input--inner {
      text-align: right;
    }
  }
  &.is--controls {
    &.type--search,
    &.type--password,
    &.type--number,
    &.type--integer,
    &.type--float,
    &.type--date,
    &.type--datetime,
    &.type--week,
    &.type--month,
    &.type--quarter,
    &.type--year,
    &.type--time {
      .vhb-input--inner {
        padding-right: $iconWidth + 0.2em;
      }
      .vhb-input--suffix {
        right: $iconWidth;
      }
    }
  }
  &.is--suffix {
    &.is--controls {
      &.type--search,
      &.type--password,
      &.type--number,
      &.type--integer,
      &.type--float,
      &.type--date,
      &.type--datetime,
      &.type--week,
      &.type--month,
      &.type--quarter,
      &.type--year,
      &.type--time {
        .vhb-input--inner {
          padding-right: $iconWidth * 2;
        }
      }
    }
  }
  &.is--suffix {
    &:hover {
      .vhb-input--suffix {
        &.is--clear {
          .vhb-input--suffix-icon {
            display: none;
          }
          .vhb-input--clear-icon {
            display: inline;
          }
        }
      }
    }
  }
  &:not(.is--disabled) {
    .vhb-input--suffix {
      &:hover {
        .vhb-input--clear-icon {
          color: $vhb-font-color;
        }
      }
      &:active {
        .vhb-input--clear-icon {
          color: $vhb-primary-color;
        }
      }
    }
    .vhb-input--extra-suffix {
      &:hover {
        .vhb-input--search-suffix,
        .vhb-input--password-suffix {
          color: $vhb-font-color;
        }
      }
      &:active {
        .vhb-input--search-suffix,
        .vhb-input--password-suffix {
          color: $vhb-primary-color;
        }
      }
    }
    .vhb-input--number-prev,
    .vhb-input--number-next {
      &:hover {
        color: $vhb-font-color;
      }
      &:active {
        color: $vhb-primary-color;
      }
    }
  }
}

.vhb-input {
  .vhb-input--password-suffix,
  .vhb-input--number-suffix,
  .vhb-input--date-picker-suffix,
  .vhb-input--search-suffix {
    position: relative;
    width: 100%;
    height: 100%;
  }

  .vhb-input--date-picker-icon,
  .vhb-input--search-icon,
  .vhb-input--password-icon {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }

  .vhb-input--date-picker-suffix {
    display: flex;
    align-items: center;
    justify-content: center;
    .vhb-input--panel-icon {
      @include animatTransition(transform, .2s);
    }
  }

  .vhb-input--number-prev,
  .vhb-input--number-next {
    position: relative;
    display: block;
    height: 50%;
    width: 100%;
    text-align: center;
  }
  .vhb-input--number-prev-icon,
  .vhb-input--number-next-icon {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }
  .vhb-input--number-prev-icon {
    bottom: 0;
  }
  .vhb-input--number-next-icon {
    top: 0;
  }
}

.vhb-input--panel {
  display: none;
  position: absolute;
  left: 0;
  padding: 4px 0;
  color: $vhb-font-color;
  font-size: $vhb-font-size;
  text-align: left;
  &:not(.is--transfer) {
    min-width: 100%;
  }
  &.is--transfer {
    position: fixed;
  }
  &.animat--leave {
    display: block;
    opacity: 0;
    transform: scaleY(0.5);
    transition: transform .3s cubic-bezier(.23,1,.32,1), opacity .3s cubic-bezier(.23,1,.32,1);
    transform-origin: center top;
    backface-visibility: hidden;
    transform-style: preserve-3d;
    &[placement="top"] {
      transform-origin: center bottom;
    }
  }
  &.animat--enter {
    opacity: 1;
    transform: scaleY(1);
  }
}

.vhb-input--panel-wrapper,
.vhb-input--panel-layout-wrapper {
  background-color: $vhb-input-panel-background-color;
  border: 1px solid $vhb-table-popup-border-color;
  box-shadow: 0 0 6px 2px rgba(0, 0, 0, 0.1);
  border-radius: $vhb-border-radius;
}

.vhb-input--panel-wrapper {
  overflow-x: hidden;
  overflow-y: auto;
}

.vhb-input--panel-layout-wrapper {
  display: flex;
  flex-direction: row;
}

.vhb-input--panel {
  &.type--date,
  &.type--week,
  &.type--month,
  &.type--quarter,
  &.type--year {
    user-select: none;
  }
  &.type--datetime {
    .vhb-input--panel-right-wrapper {
      display: flex;
      flex-direction: column;
      border-left: 1px solid $vhb-input-border-color;
    }
  }
  &.type--date,
  &.type--datetime {
    .vhb-input--date-picker-body {
      th {
        width: 14.28571%;
      }
    }
  }
  &.type--week {
    .vhb-input--date-picker-body {
      table {
        th {
          width: 12%;
          &:first-child {
            width: 14%;
          }
        }
      }
    }
  }
  &.type--quarter {
    .vhb-input--date-picker-body {
      table {
        th {
          width: 50%;
        }
      }
    }
  }
  &.type--month,
  &.type--year {
    .vhb-input--date-picker-body {
      td {
        width: 25%;
      }
    }
  }
}

.vhb-input--time-picker-title {
  display: inline-block;
  text-align: center;
  border: 1px solid $vhb-input-border-color;
  border-radius: $vhb-border-radius;
}
.vhb-input--time-picker-confirm {
  position: absolute;
  right: 0;
  top: 0;
  outline: 0;
  border: 1px solid $vhb-input-border-color;
  border-radius: $vhb-border-radius;
  cursor: pointer;
  color: $vhb-input-date-time-confirm-button-color;
  border-color: $vhb-primary-color;
  background-color: $vhb-primary-color;
  &:hover {
    background-color: lighten($vhb-primary-color, 6%);
    border-color: lighten($vhb-primary-color, 6%);
  }
  &:active {
    background-color: darken($vhb-primary-color, 3%);
    border-color: darken($vhb-primary-color, 3%);
  }
}

.vhb-input--time-picker-header {
  display: flex;
  position: relative;
  flex-shrink: 0;
}

.vhb-input--date-picker-header {
  display: flex;
  flex-direction: row;
  user-select: none;
  .vhb-input--date-picker-type-wrapper {
    flex-grow: 1;
  }
  .vhb-input--date-picker-btn-wrapper {
    flex-shrink: 0;
    text-align: center;
  }
}
.vhb-input--date-picker-type-wrapper {
  .vhb-input--date-picker-label,
  .vhb-input--date-picker-btn {
    display: inline-block;
  }
}
.vhb-input--date-picker-btn-wrapper {
  display: flex;
  flex-direction: row;
}
.vhb-input--date-picker-label,
.vhb-input--date-picker-btn {
  display: inline-block;
  display: flex;
  border-radius: $vhb-border-radius;
  border: 1px solid $vhb-input-border-color;
  align-items: center;
  justify-content: center;
  background-color: $vhb-button-default-background-color;
}
.vhb-input--date-picker-btn {
  &.is--disabled {
    color: $vhb-disabled-color;
    cursor: no-drop;
  }
  &:not(.is--disabled) {
    cursor: pointer;
    &:hover {
      background-color: lighten($vhb-button-default-background-color, 6%);
    }
    &:active {
      background-color: darken($vhb-button-default-background-color, 3%);
    }
  }
}
.vhb-input--date-picker-body {
  border-radius: $vhb-border-radius;
  border: 1px solid $vhb-table-popup-border-color;
  user-select: none;
  table {
    border: 0;
    width: 100%;
    border-spacing: 0;
    border-collapse: separate;
    text-align: center;
    table-layout: fixed
  }
  th,
  td {
    font-weight: normal;
  }
  th {
    box-shadow: inset 0 -1px 0 0 $vhb-table-popup-border-color;
  }
  td {
    &.is--prev,
    &.is--next {
      color: $vhb-disabled-color;
      .vhb-input--date-label,
      .vhb-input--date-festival {
        color: $vhb-disabled-color;
      }
    }
    &.is--now {
      box-shadow: inset 0 0 0 1px $vhb-table-popup-border-color;
      &:not(.is--selected) {
        &.is--current {
          color: $vhb-primary-color;
          .vhb-input--date-label,
          .vhb-input--date-festival {
            color: $vhb-primary-color;
          }
        }
      }
    }
    &.is--hover {
      background-color: $vhb-input-date-picker-hover-background-color;
    }
    &.is--selected {
      color: $vhb-input-date-picker-selected-color;
      background-color: $vhb-primary-color;
      .vhb-input--date-label,
      .vhb-input--date-festival {
        color: $vhb-input-date-picker-festival-selected-color;
      }
      .vhb-input--date-label {
        &.is-notice {
          &:before {
            background-color: $vhb-input-date-picker-notice-selected-background-color;
          }
        }
      }
    }
    &:not(.is--disabled) {
      cursor: pointer;
    }
    &.is--disabled {
      cursor: no-drop;
      color: $vhb-input-disabled-color;
      background-color: $vhb-input-disabled-background-color;
      .vhb-input--date-label,
      .vhb-input--date-festival {
        color: $vhb-input-disabled-color;
      }
    }
  }
}

.vhb-input--date-week-view {
  th {
    &:first-child {
      box-shadow: inset -1px -1px 0 0 $vhb-table-popup-border-color;
    }
  }
  td {
    &:first-child {
      box-shadow: inset -1px 0 0 0 $vhb-table-popup-border-color;
    }
  }
}

.vhb-input--date-label,
.vhb-input--date-festival {
  display: block;
  overflow: hidden;
}

.vhb-input--date-label {
  position: relative;
  &.is-notice {
    &:before {
      content: "";
      position: absolute;
      width: 4px;
      height: 4px;
      left: 0.8em;
      top: 0.1em;
      transform: translateX(-50%);
      border-radius: 100%;
      background-color: $vhb-input-date-notice-background-color;
    }
  }
}
.vhb-input--date-label--extra {
  position: absolute;
  right: 0.1em;
  top: -0.2em;
  font-size: 12px;
  line-height: 12px;
  transform: scale(0.7);
  color: $vhb-input-date-extra-color;
  &.is-important {
    color: $vhb-input-date-extra-important-color;
  }
}

.vhb-input--date-festival {
  color: $vhb-input-date-festival-color;
  height: 14px;
  line-height: 1;
  overflow: hidden;
  &.is-important {
    color: $vhb-input-date-festival-important-color;
  }
}
.vhb-input--date-festival--label {
  display: block;
  font-size: 12px;
  transform: scale(0.8);
}

@keyframes festivalOverlap2 {
  0%, 45%, 100% {
    transform: translateY(0);
  }
  50%, 95% {
    transform: translateY(-14px);
  }
}

@keyframes festivalOverlap3 {
  0%, 20%, 100% {
    transform: translateY(0);
  }
  25%, 45%, 75%, 95% {
    transform: translateY(-14px);
  }
  50%, 70% {
    transform: translateY(-28px);
  }
}

.vhb-input--date-festival--overlap {
  display: block;
  font-size: 12px;
  &.overlap--2 {
    animation: festivalOverlap2 6s infinite ease-in-out;
  }
  &.overlap--3 {
    animation: festivalOverlap3 9s infinite ease-in-out;
  }
  & > span {
    height: 14px;
    display: block;
    transform: scale(0.8);
  }
}

.vhb-input--time-picker-body {
  position: relative;
  display: flex;
  flex-direction: row;
  border: 1px solid $vhb-table-popup-border-color;
  flex-grow: 1;
  border-radius: $vhb-border-radius;
  user-select: none;
  & > ul {
    height: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
    &:before,
    &:after {
      content: " ";
      display: block;
    }
    &:hover {
      overflow-y: auto;
    }
    & > li {
      display: block;
      &:hover {
        background-color: $vhb-input-date-picker-hover-background-color;
        cursor: pointer;
      }
      &.is--selected {
        font-weight: 700;
        color: $vhb-primary-color;
      }
    }
  }
  .vhb-input--time-picker-minute-list {
    border-left: 1px solid $vhb-table-popup-border-color;
  }
  .vhb-input--time-picker-second-list {
    border-left: 1px solid $vhb-table-popup-border-color;
  }
}

.vhb-input {
  font-size: $vhb-font-size;
  height: $vhb-input-height-default;
  .vhb-input--inner {
    &[type="date"]::-webkit-inner-spin-button,
    &[type="month"]::-webkit-inner-spin-button,
    &[type="week"]::-webkit-inner-spin-button {
      margin-top: 6px;
    }
    &[type="date"]::-webkit-inner-spin-button,
    &[type="month"]::-webkit-inner-spin-button,
    &[type="week"]::-webkit-inner-spin-button,
    &[type="number"]::-webkit-inner-spin-button {
      height: 24px;
    }
  }
  &.size--medium {
    font-size: $vhb-font-size-medium;
    height: $vhb-input-height-medium;
    .vhb-input--inner {
      &[type="date"]::-webkit-inner-spin-button,
      &[type="month"]::-webkit-inner-spin-button,
      &[type="week"]::-webkit-inner-spin-button {
        margin-top: 4px;
      }
    }
  }
  &.size--small {
    font-size: $vhb-font-size-small;
    height: $vhb-input-height-small;
    .vhb-input--inner {
      &[type="date"]::-webkit-inner-spin-button,
      &[type="month"]::-webkit-inner-spin-button,
      &[type="week"]::-webkit-inner-spin-button {
        margin-top: 2px;
      }
    }
  }
  &.size--mini {
    font-size: $vhb-font-size-mini;
    height: $vhb-input-height-mini;
    .vhb-input--inner {
      &[type="date"]::-webkit-inner-spin-button,
      &[type="month"]::-webkit-inner-spin-button,
      &[type="week"]::-webkit-inner-spin-button {
        margin-top: 0;
      }
    }
  }
}

@mixin getPanelStyle ($sizeIndex) {
  $fontSizeList: $vhb-font-size, $vhb-font-size-medium, $vhb-font-size-small, $vhb-font-size-mini;
  $timeWeekRowHeightList: $vhb-input-date-time-week-row-height-default, $vhb-input-date-time-week-row-height-medium, $vhb-input-date-time-week-row-height-small, $vhb-input-date-time-week-row-height-mini;
  $monthYearRowHeightList: $vhb-input-date-month-year-row-height-default, $vhb-input-date-month-year-row-height-medium, $vhb-input-date-month-year-row-height-small, $vhb-input-date-month-year-row-height-mini;
  $quarterRowHeightList: $vhb-input-date-quarter-row-height-default, $vhb-input-date-quarter-row-height-medium, $vhb-input-date-quarter-row-height-small, $vhb-input-date-quarter-row-height-mini;
  $titleRowHeightList: $vhb-input-date-title-height-default, $vhb-input-date-title-height-medium, $vhb-input-date-title-height-small, $vhb-input-date-title-height-mini;
  
  font-size: nth($fontSizeList, $sizeIndex);
  .vhb-input--panel-wrapper {
    max-height: 400px - $sizeIndex * 20;
  }
  &.type--date,
  &.type--time,
  &.type--week,
  &.type--month,
  &.type--quarter,
  &.type--year {
    .vhb-input--panel-wrapper {
      padding: 12px - $sizeIndex;
    }
  }
  &.type--date,
  &.type--month,
  &.type--quarter,
  &.type--year {
    .vhb-input--panel-wrapper {
      $widthList: 366px, 336px, 312px, 288px;
      width: nth($widthList, $sizeIndex);
    }
  }
  &.type--week {
    .vhb-input--panel-wrapper {
      $widthList: 380px, 380px, 354px, 326px;
      width: nth($widthList, $sizeIndex);
    }
  }
  &.type--time {
    .vhb-input--panel-wrapper {
      $widthList: 170px, 168px, 154px, 146px;
      width: nth($widthList, $sizeIndex);
    }
  }
  &.type--datetime {
    .vhb-input--panel-left-wrapper {
      $widthList: 336px, 336px, 312px, 288px;
      width: nth($widthList, $sizeIndex);
    }
    .vhb-input--panel-left-wrapper,
    .vhb-input--panel-right-wrapper {
      padding: 12px - $sizeIndex;
    }
  }
  .vhb-input--time-picker-title {
    height: 31px - $sizeIndex;
    line-height: 31px - $sizeIndex;
    padding: 0 12px - $sizeIndex;
  }
  .vhb-input--date-picker-label,
  .vhb-input--date-picker-btn {
    height: 31px - $sizeIndex;
    line-height: 31px - $sizeIndex;
  }
  .vhb-input--date-picker-btn-wrapper {
    .vhb-input--date-picker-btn {
      width: 31px - $sizeIndex;
      margin-left: 9px - $sizeIndex;
    }
  }
  .vhb-input--date-picker-type-wrapper {
    .vhb-input--date-picker-label,
    .vhb-input--date-picker-btn {
      padding: 0 10px - $sizeIndex;
    }
  }
  .vhb-input--time-picker-header,
  .vhb-input--date-picker-header {
    $paddingBottomList: 8px, 7px, 6px, 5px;
    padding-bottom: nth($paddingBottomList, $sizeIndex);
  }
  .vhb-input--date-picker-body table,
  .vhb-input--time-picker-body {
    height: nth($timeWeekRowHeightList, $sizeIndex) * 6 + nth($titleRowHeightList, $sizeIndex);
  }
  .vhb-input--time-picker-body {
    $ulWidthList: 48px, 48px, 44px, 42px;
    & > ul {
      width: nth($ulWidthList, $sizeIndex);
      &:before,
      &:after {
        $heightList: 120px, 120px, 110px, 100px;
        height: nth($heightList, $sizeIndex);
      }
      & > li {
        height: 26px;
        padding-left: 10px - $sizeIndex;
      }
    }
    .vhb-input--time-picker-minute-list {
      left: nth($ulWidthList, $sizeIndex);
    }
    .vhb-input--time-picker-second-list {
      left: nth($ulWidthList, $sizeIndex) * 2;
    }
  }
  .vhb-input--date-day-view,
  .vhb-input--date-week-view {
    td {
      height: nth($timeWeekRowHeightList, $sizeIndex);
    }
  }
  .vhb-input--date-quarter-view {
    td {
      height: nth($quarterRowHeightList, $sizeIndex);
    }
  }
  .vhb-input--date-month-view,
  .vhb-input--date-year-view {
    td {
      height: nth($monthYearRowHeightList, $sizeIndex);
    }
  }
  .vhb-input--date-picker-body {
    th {
      height: nth($titleRowHeightList, $sizeIndex);
    }
  }
  .vhb-input--time-picker-confirm {
    height: 31px - $sizeIndex;
    padding: 0 10px - $sizeIndex;
  }
  .vhb-input--date-label {
    line-height: nth($fontSizeList, $sizeIndex) + 1;
  }
}

.vhb-input--panel {
  @include getPanelStyle(1);
  &.size--medium {
    @include getPanelStyle(2);
  }
  &.size--small {
    @include getPanelStyle(3);
  }
  &.size--mini {
    @include getPanelStyle(4);
  }
}
