@import '../../styles/variables';
@import '../../styles/mixins';

$tipSize: 20px;
$cellSize: 38px;

.DatePicker {
  display: inline-block;

  input[type=date]::-webkit-inner-spin-button,
  input[type=date]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }

  input[type=number] {
    -moz-appearance:textfield;
  }

  &_top {
    .react-date-picker__calendar {
      bottom: $line-height + $tipSize;

      &:after,
      &:before {
        bottom: -$tipSize/2;
      }
    }
  }

  &_bottom {
    .react-date-picker__calendar {
      top: $line-height + $tipSize;

      &:after,
      &:before {
        top: -$tipSize/2;
      }
    }
  }

  .react-date-picker {
    position: relative;
    display: flex;

    &--disabled {
      .react-date-picker__button {
        cursor: not-allowed;
        background-color: $gray95;
        & > * {
          pointer-events: none;
        }
      }
    }

    &__button {
      @include input;
      display: inherit;
      padding: 0;
      align-items: stretch;
      justify-content: space-between;

      &:hover {
        background-color: $gray95;
      }

      &__input {
        display: inherit;
        padding-left: 10px;
        align-items: baseline;

        & > * {
          height: 100%;
        }

        &__input {
          display: inherit;
          margin: 0;
          padding: 0;
          text-align: center;
          border: 0;
          outline: none;
          background: transparent;

          &::-webkit-outer-spin-button,
          &::-webkit-inner-spin-button {
            margin: 0;
            -webkit-appearance: none;
          }
        }
      }
    }

    &__clear-button {
      padding: 0 10px;
      cursor: pointer;
      border: 0;
      outline: none;
      background: transparent;
      position: absolute;
      right: 25px;
      top: calc(50% - 8px);
    }

    &__calendar-button {
      padding: 0 10px;
      cursor: pointer;
      border: 0;
      outline: none;
      background: transparent;
      position: absolute;
      right: 5px;
      top: calc(50% - 8px);
    }

    //Calendar view
    &__calendar {
      position: absolute;
      z-index: layer('modal');
      transition: opacity 300ms ease;
      border-radius: 2px;
      background-color: $white;
      box-shadow: $base-shadow;

      .react-calendar {
        padding: 20px 13px 20px 20px;
        background: $white;

        .react-calendar__tile.react-calendar__tile--active {
          background: $badge-main-color;
        }

        .react-calendar__month-view__weekdays__weekday {
          width: $cellSize;
          max-width: $cellSize !important;
          height: $cellSize;
          text-align: center;
          text-transform: capitalize;
          pointer-events: none;
          color: $gray50;
          font-size: 12px;
          line-height: $cellSize;
        }

        .react-calendar__navigation {
          margin-bottom: $spacing * 4;
          padding-right: 7px;

          & > * {
            padding: 0;
            text-transform: capitalize;
            color: $black;
            border: 0;
            outline: none;
            background: transparent;
            font-size: 16px;
            font-weight: 700;
            line-height: 1;
          }

          .react-calendar__navigation__prev2-button,
          .react-calendar__navigation__next2-button {
            display: none;
          }

          .react-calendar__navigation__arrow {
            cursor: pointer;

            &[disabled] {
              cursor: not-allowed;
              opacity: .5;
            }
          }
        }
      }

      &:after,
      &:before {
        position: absolute;
        z-index: -1;
        left: 25px;
        width: $tipSize;
        height: $tipSize;
        content: '';
        transform: rotate(45deg);
        background-color: $white;
      }

      &:before {
        box-shadow: $base-shadow;
      }

      @media (min-width: $layout-tablet) {
        width: 306px;
      }

      &--closed {
        pointer-events: none;
        opacity: 0;
      }

      &--open {
        opacity: 1;
      }
    }
  }

  //Cell style
  &__cell {
    width: $cellSize;
    height: $cellSize;
    margin-top: -1px;
    margin-left: -1px;
    padding: 0;
    cursor: pointer;
    border: 1px solid $gray95;
    outline: none;
    background: white;

    &[disabled] {
      cursor: not-allowed;
      color: $gray70;
      background-color: $gray95 !important;
    }

    &.react-calendar__month-view__days__day--neighboringMonth {
      pointer-events: none;
      opacity: 0;
    }

    time {
      pointer-events: none;
    }

    &:hover {
      z-index: 1;
      border-color: darken($badge-main-color, 10%);
      background: #fffbd5;
    }

    &--active {
      background-color: $badge-main-color;
    }
  }

  @media screen and (max-width: $layout-tablet) {
    .react-date-picker__calendar {
      position: fixed;
      left: 0px;

      &:before {
        content: none;
      }

      &:after {
        content: none;
      }
    }
    .react-calendar__month-view {
      max-width: 400px;
      margin: 0 auto;
    }
  }
}
