@use "mixins/shadow";
@use "variables";

@use "sass:color";

// Calendars
.calendar {
  border: variables.$border-width solid variables.$border-color;
  border-radius: variables.$border-radius;
  display: block;
  min-width: 280px;

  .calendar-nav {
    align-items: center;
    background: variables.$bg-color;
    border-top-left-radius: variables.$border-radius;
    border-top-right-radius: variables.$border-radius;
    display: flex;
    font-size: variables.$font-size-lg;
    padding: variables.$layout-spacing;
  }

  .calendar-header,
  .calendar-body {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    padding: variables.$layout-spacing 0;

    .calendar-date {
      flex: 0 0 14.28%; // 7 calendar-items each row
      max-width: 14.28%;
    }
  }

  .calendar-header {
    background: variables.$bg-color;
    border-bottom: variables.$border-width solid variables.$border-color;
    color: variables.$gray-color;
    font-size: variables.$font-size-sm;
    text-align: center;
  }

  .calendar-body {
    color: variables.$gray-color-dark;
  }

  .calendar-date {
    border: 0;
    padding: variables.$unit-1;

    .date-item {
      appearance: none;
      background: transparent;
      border: variables.$border-width solid transparent;
      border-radius: 50%;
      color: variables.$gray-color-dark;
      cursor: pointer;
      font-size: variables.$font-size-sm;
      height: variables.$unit-7;
      line-height: variables.$unit-5;
      outline: none;
      padding: variables.$unit-h;
      position: relative;
      text-align: center;
      text-decoration: none;
      transition: background .2s, border .2s, box-shadow .2s, color .2s;
      vertical-align: middle;
      white-space: nowrap;
      width: variables.$unit-7;

      &.date-today {
        border-color: variables.$secondary-color-dark;
        color: variables.$primary-color;
      }

      &:focus {
        @include shadow.control-shadow();
      }

      &:focus,
      &:hover {
        background: variables.$secondary-color-light;
        border-color: variables.$secondary-color-dark;
        color: variables.$primary-color;
        text-decoration: none;
      }
      &:active,
      &.active {
        background: variables.$primary-color-dark;
        border-color: color.adjust(variables.$primary-color-dark, $lightness: -5%, $space: hsl);
        color: variables.$light-color;
      }

      // Calendar badge support
      &.badge {
        &::after {
          position: absolute;
          top: 3px;
          right: 3px;
          transform: translate(50%, -50%);
        }
      }
    }

    .date-item,
    .calendar-event {
      &:disabled,
      &.disabled {
        cursor: default;
        opacity: .25;
        pointer-events: none;
      }
    }

    &.prev-month,
    &.next-month {
      .date-item,
      .calendar-event {
        opacity: .25;
      }
    }
  }

  .calendar-range {
    position: relative;

    &::before {
      background: variables.$secondary-color;
      content: "";
      height: variables.$unit-7;
      left: 0;
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
    }
    &.range-start {
      &::before {
        left: 50%;
      }
    }
    &.range-end {
      &::before {
        right: 50%;
      }
    }

    &.range-start,
    &.range-end {
      .date-item {
        background: variables.$primary-color-dark;
        border-color: color.adjust(variables.$primary-color-dark, $lightness: -5%, $space: hsl);
        color: variables.$light-color;
      }
    }

    .date-item {
      color: variables.$primary-color;
    }
  }

  // Calendars size
  &.calendar-lg {
    .calendar-body {
      padding: 0;

      .calendar-date {
        border-bottom: variables.$border-width solid variables.$border-color;
        border-right: variables.$border-width solid variables.$border-color;
        display: flex;
        flex-direction: column;
        height: 5.5rem;
        padding: 0;

        &:nth-child(7n) {
          border-right: 0;
        }
        &:nth-last-child(-n+7) {
          border-bottom: 0;
        }
      }
    }

    .date-item {
      align-self: flex-end;
      height: variables.$unit-7;
      margin-right: variables.$layout-spacing-sm;
      margin-top: variables.$layout-spacing-sm;
    }

    .calendar-range {
      &::before {
        top: 19px;
      }
      &.range-start {
        &::before {
          left: auto;
          width: 19px;
        }
      }
      &.range-end {
        &::before {
          right: 19px;
        }
      }
    }

    .calendar-events {
      flex-grow: 1;
      line-height: 1;
      overflow-y: auto;
      padding: variables.$layout-spacing-sm;
    }

    .calendar-event {
      border-radius: variables.$border-radius;
      font-size: variables.$font-size-sm;
      display: block;
      margin: variables.$unit-h auto;
      overflow: hidden;
      padding: 3px 4px;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
