/* Author: ひまわり(dtysky<dtysky@outlook.com>)
 * Github: https://github.com/dtysky
 * Create: 17/1/16
 */

@import "../../styles/config";

$container-width: 320px;

$date-picker-display-height: 58px;
$date-picker-center-padding: 32px;
$date-picker-days-row-height: 28px;

$date-picker-duration-time-day: 400ms;
$date-picker-duration-time-enter: 400ms;
$date-picker-duration-time-leave: 200ms;

@mixin translation-group($selector, $max-position: none, $enter-time: $date-picker-duration-time-enter, $leave-time: $date-picker-duration-time-leave) {
  #{$selector}-enter {
    opacity: 0;

    @if($max-position != none) {
      margin-top: $max-position;
    }
  }

  #{$selector}-enter-active {
    opacity: 1;

    @if($max-position != none) {
      margin-top: 0;
    }

    transition: all $enter-time ease-out;
  }

  #{$selector}-exit {
    opacity: 1;

    @if($max-position != none) {
      margin-top: 0;
    }
  }

  #{$selector}-exit-active {
    opacity: 0;

    @if($max-position != none) {
      margin-top: -$max-position;
    }

    transition: all $leave-time ease-out;
  }
}

.hana-date-picker {
  &-warp {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
  }

  &-container {
    &-container {
      position: fixed;
      z-index: $z-index-picker;
      margin-top: 4px;
      width: $container-width;
      padding: 18px 6px 6px 6px;
      border: 1px solid $date-picker-theme-front-color;
      border-radius: 4px;
      background: $date-picker-theme-back-color;
      overflow: hidden;
    }

    @include translation-group(&, none, 400ms, 400ms);
  }

  &-content {
    color: $date-picker-font-main-color;
  }

  &-display {
    height: $date-picker-display-height;

    &-container {
      @include auto-prefixed-flex;

      position: absolute;
      white-space: nowrap;
    }

    &-date {
      font-weight: 300;
      padding-left: 18px;
      width: 78px;
      font-size: $date-picker-display-height;
    }

    &-ymd {
      width: 160px;
      color: $date-picker-font-sub-color;
    }

    &-day {
      font-size: 14px;
      padding-top: 22px;
      padding-left: 8px;
    }

    &-year-month {
      @include auto-prefixed-flex;

      font-size: 12px;
      padding-top: 4px;
    }

    i {
      padding-left: 6px;
      padding-right: 6px;

      @extend %hanaicon;

      color: $date-picker-theme-front-color;
    }

    @each $index, $icon in enumerate($date-picker-month-icons) {
      &-icon-#{$index} {
        @include hana-icon($icon);
      }
    }

    @include translation-group(#{&}-next, 20px);
    @include translation-group(#{&}-pre, -20px);
  }

  &-select {
    width: 100%;
    text-align: center;
    cursor: pointer;
    &-option {
      text-align: center;
    }

    &-close {
      margin-top: 8px;
    }

    &-open {
      position: absolute;
      overflow: auto;
      height: 84px;
      top: -32px;
      background-color: $date-picker-theme-back-color;

      &::-webkit-scrollbar {
        width: 8px;
        background: none;
      }

      &::-webkit-scrollbar-thumb {
        background-color: $date-picker-font-sub-color;
      }
    }

    &-open &-option {
      font-size: 14px;
      padding: 4px 0;
      transition: background-color .3s ease-in-out;
      
      &:hover {
        background-color: rgba($date-picker-theme-front-color, .6);
      }
      
      &-current {
        background-color: rgba($date-picker-theme-front-color, .6);
      }
    }

    &-enter {
      opacity: 0;
    }
  
    &-enter-active {
      opacity: 1;
      transition: all $date-picker-duration-time-enter ease-out;
    }
  
    &-exit {
      opacity: 1;
    }
    
    &-exit-active {
      opacity: 0;
      transition: all $date-picker-duration-time-leave ease-out;
    }
  }

  &-year-month {
    @include auto-prefixed-flex;

    padding: $date-picker-center-padding 0;

    i {
      @extend %hanaicon;

      width: 10%;
      text-align: center;
      font-size: 16px;
      padding-top: 8px;
      color: $date-picker-font-sub-color;
    }

    &-pre, &-next {
      padding: 0 6px;
      cursor: pointer;
    }

    &-pre {
      @include hana-icon($date-picker-pre-icon);
    }

    &-next {
      @include hana-icon($date-picker-next-icon);
    }

    &-select {
      position: relative;
      width: 80%;

      &-container {
        @include auto-prefixed-flex;

        position: absolute;
        width: 100%;
      }

      @include translation-group(#{&}-next, 12px);
      @include translation-group(#{&}-pre, -12px);
    }

    &-v-line {
      margin: 10px 8px 8px 0;
      width: 2px;
      height: 32px - 20;
      background-color: #aaa;
    }

    &-year, &-month {
      position: relative;
      width: 45%;
    }
  }

  &-weekdays {
    @include auto-prefixed-flex;

    padding-left: 1%;
    color: $date-picker-theme-front-color;
    font-size: 12px;
    font-weight: 500;
  }

  &-weekday {
    width: 14%;
    text-align: center;
  }

  &-days {
    position: relative;
    height: $date-picker-days-row-height * 6;

    &-container {
      position: absolute;
      width: 100%;
      padding-top: 16px;
      font-size: 13px;
      text-align: center;
      font-weight: 400;
    }

    &-row {
      @include auto-prefixed-flex;

      padding-left: 1%;
      height: $date-picker-days-row-height;
      line-height: $date-picker-days-row-height;
    }

    &-day {
      width: 22px;
      height: 24px;
      margin: 0 calc(7% - 11px);
      cursor: pointer;
      border-bottom: 2px solid rgba(0, 0, 0, 0);
      transition: all $date-picker-duration-time-day ease-out;

      &:hover {
        color: $date-picker-theme-front-color;
        border-bottom-color: $date-picker-theme-front-color;
      }
    }

    &-day-pre {
      color: $date-picker-font-sub-color;
    }

    &-day-current {
      color: $date-picker-font-main-color;
    }

    &-day-next {
      color: $date-picker-font-sub-color;
    }

    &-day-active {
      color: $date-picker-theme-front-color;
      border-bottom-color: $date-picker-theme-front-color;
    }

    @include translation-group(#{&}-next, 16px);
    @include translation-group(#{&}-pre, -16px);
  }

  &-action-buttons {
    padding-top: 18px;
    width: 95%;
    text-align: right;
  }

  &-confirm-button, &-cancel-button, &-clear-button {
    border: none;
    background-color: transparent;
    color: #888;
    text-align: center;
    font-size: 14px;
    padding: 6px 12px;
    height: 28px;

    &:hover {
      color: #444;
      background-color: rgba(#ddd, 0.4);
    }
  }
}
