@import '../style/functions.scss';
@import '../style/theme.scss';
@import '../style/mixins.scss';

$calendar-prefix: 'dk-calendar';

.#{$calendar-prefix} {
  @include reset-component();
  position: relative;
  display: inline-block;

  input {
    outline: 0;
    font-size: $font-size-base;
    color: $calendar-color;

    &::placeholder {
      color: $input-placeholder-color;
      opacity: 1;
    }
  }

  &-range,
  &-input {
    min-width: $calendar-width;
    padding: $input-padding-y $input-padding-x;
    padding-right: 30px;
    border: 1px solid $calendar-border-color;
    border-radius: $border-radius;
    transition: $calendar-transition;

    &:focus {
      background-color: $calendar-focus-bg;
      border-color: $calendar-focus-border-color;
      box-shadow: $calendar-focus-box-shadow;
    }

    &:hover {
      border-color: $calendar-hover-border-color;
    }
  }

  &-range {
    > span {
      padding: 0 $input-padding-x / 2;
    }

    > input {
      text-align: center;
      border: none;
    }

    &-active {
      background-color: $calendar-focus-bg;
      border-color: $calendar-focus-border-color;
      box-shadow: $calendar-focus-box-shadow;
    }
  }

  &-icon {
    position: absolute;
    width: $calendar-icon-size;
    height: $calendar-icon-size;
    right: 12px;
    top: 50%;
    margin-top: -$calendar-icon-size / 2;
    font-size: $calendar-icon-size;
    color: $calendar-icon-color;
    user-select: none;
    z-index: 1;
  }

  &-select {
    display: flex;
    flex: 1;
    justify-content: center;
    cursor: pointer;

    > span {
      display: inline-block;
      font-weight: bold;
      padding: 0 3px;

      &:hover {
        color: $calendar-active-bg;
      }
    }
  }

  &-week {
    width: 100%;

    > span {
      display: inline-block;
      width: $calendar-item-size;
      height: $calendar-item-size;
      line-height: $calendar-item-size;
      font-weight: bold;
      font-size: 90%;
    }
  }

  &-list {
    position: relative;
    width: 100%;
    margin-top: 12px;
    z-index: 10;
  }

  &-header {
    width: 100%;
    border-bottom: 1px solid $calendar-border-color;
  }

  &-config {
    display: flex;
    height: $calendar-item-size - 4px;
    padding: 4px 8px;
    align-items: center;

    &-icon {
      cursor: pointer;
      font-size: 14px;

      &:hover {
        color: $calendar-active-bg;
      }
    }
  }

  &-prev-month {
    margin-left: 3px;
  }

  &-next-month {
    margin-right: 3px;
  }

  &-day {
    width: $calendar-picker-width;
    text-align: center;

    &-item {
      display: inline-block;
      width: $calendar-item-size;
      height: $calendar-item-size;
      padding: 3px;
      margin: 3px 0;

      > span {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100%;
        border: 1px solid transparent;
        border-radius: 50%;
        cursor: pointer;
        color: $calendar-color;
        transition: $calendar-hover-transition;

        &:hover {
          background: $calendar-item-hover-bg;
          border-color: $calendar-border-color;
        }
      }
    }

    &-item-other {
      > span {
        color: $calendar-other-color;
      }
    }

    &-item-active {
      > span,
      > span:hover {
        background: $calendar-active-bg;
        border-color: $calendar-active-border-color;
        color: #fff;
      }
    }

    &-item-hover-start {
      border-top-left-radius: 50%;
      border-bottom-left-radius: 50%;
    }

    &-item-hover-end {
      border-top-right-radius: 50%;
      border-bottom-right-radius: 50%;
    }

    &-item-hover {
      background: $calendar-item-hover-bg;
      cursor: pointer;

      > span,
      > span:hover {
        background: transparent;
        border-color: transparent;
      }
    }

    &-item-hover-active {
      background: $calendar-item-hover-bg;

      &.#{$calendar-prefix}-day-item-hover-start,
      &.#{$calendar-prefix}-day-item-hover-end {

        > span,
        > span:hover {
          background: $calendar-active-border-color;
          border-radius: 50%;
          color: #fff;
        }
      }
    }

    &-item-disabled {
      cursor: not-allowed;
      background: #f5f5f5;
      opacity: 0.35;

      > span {
        color: $calendar-other-color;
        // opacity: 0.35;

        &:hover {
          background: #f5f5f5;
          border-color: transparent;
        }
      }

      &.#{$calendar-prefix}-day-item-hover-start,
      &.#{$calendar-prefix}-day-item-hover-end {
        border-radius: 0;

        > span,
        > span:hover {
          color: $calendar-other-color;
          background: #f5f5f5;
          border-radius: 0;
        }
      }
    }

    &-datetime {
      position: relative;
      width: 100%;
      padding-top: 12px;
      border-top: 1px solid $calendar-border-color;
      text-align: center;

      &-timer {
        position: absolute;
        left: 50%;
        bottom: 100%;
        transform: translate(-50%);
        background: $white;
        box-shadow: $calendar-time-shadow;
        z-index: 0;
        visibility: hidden;
      }

      &:hover &-timer {
        visibility: visible;
        z-index: 10;
      }
    }
  }

  &-time {
    width: auto;

    &-container {
      display: flex;
      flex-direction: row;
      height: $calendar-time-item-height * 6;
    }

    &-scroll {
      width: $calendar-time-item-width;
      height: 100%;
      border-right: 1px solid $border-color;
      flex-direction: column;
      overflow: hidden;

      &:last-child {
        border-right: 0;
      }
    }

    &-list {
      padding: 0;

      // &:before,
      &:after {
        content: '';
        display: block;
        height: $calendar-time-item-height * 5;
      }
    }

    &-item {
      display: block;
      text-align: center;
      line-height: $calendar-time-item-height;
      transition: $calendar-hover-transition;
      cursor: pointer;

      &:hover {
        background: $light;
      }

      &-active {
        background: $calendar-time-active-bg;
        font-weight: 700;
        transition: none;

        &:hover {
          background: $calendar-time-active-bg;
        }
      }
    }

    &-footer {
      width: 100%;
      height: 36px;
      border-top: 1px solid $calendar-border-color;
      align-items: center;
      display: flex;
      flex-direction: row;
      justify-content: flex-end;

      >div {
        line-height: 28px;
        padding: 0 5px;
        cursor: pointer;
        font-size: 12px;
      }
    }

    &-confirm {
      margin: 0 5px;
      color: $calendar-active-bg;
      font-weight: bold;
    }
  }

  &-ym {
    width: $calendar-picker-width;

    &-item {
      display: inline-block;
      width: 1 / 3 * 100%;
      margin-top: 12px;
      padding: 0 8px;

      > span {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: $calendar-ym-item-height;
        border-radius: 3px;
        cursor: pointer;
        color: $calendar-color;

        &:hover {
          background: $light;
        }
      }
    }

    &-item-other {
      > span {
        color: $calendar-other-color;
      }
    }

    &-item-active {
      > span,
      > span:hover {
        background: $calendar-active-bg;
        color: #fff;
      }
    }
  }
}

.#{$calendar-prefix}-panel {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 5px;
  padding: $calendar-panel-padding;
  box-shadow: $calendar-panel-shadow;
  background-color: $white;
  border-radius: $border-radius;
  transition: $calendar-panel-transition;
  transform-origin: center top;
  z-index: $zindex-calendar;

  &-time {
    padding: 0;
  }

  span {
    user-select: none;
  }

  &-enter {
    opacity: 0;
    transform: scaleY(0);
  }

  &-enter-active {
    opacity: 1;
    transform: scaleY(1);
  }

  &-exit {
    opacity: 1;
    transform: scaleY(1);
  }

  &-exit-active {
    opacity: 0;
    transform: scaleY(0);
  }
}

.#{$calendar-prefix}-panel-range {
  display: flex;
  flex-direction: row;

  > div:first-child {
    margin-right: 18px;
  }
}

.#{$calendar-prefix}-disabled {
  background: $calendar-disabled-bg;
  opacity: $calendar-disabled-opacity;
  pointer-events: none;

  .#{$calendar-prefix}-range,
  input {
    border-color: $calendar-disabled-border-color;
    background: $calendar-disabled-bg;
  }
}