@import '../../variables';

$cal-week-view-vars: () !default;
$cal-week-view-vars: map-merge($cal-vars, $cal-week-view-vars);

@mixin cal-week-view-theme($overrides) {
  $theme: map-merge($cal-week-view-vars, $overrides);

  .cal-week-view {
    background-color: map-get($theme, bg-primary);

    .cal-day-headers {
      border-color: map-get($theme, border-color);
    }

    .cal-day-headers .cal-header {
      &:not(:last-child) {
        border-right-color: map-get($theme, border-color);
      }

      &:first-child {
        border-left-color: map-get($theme, border-color);
      }
    }

    .cal-day-headers .cal-header:hover,
    .cal-day-headers .cal-drag-over {
      background-color: map-get($theme, bg-active);
    }

    .cal-day-column {
      border-left-color: map-get($theme, border-color);
    }

    .cal-event {
      background-color: map-get($theme, event-color-secondary);
      border-color: map-get($theme, event-color-primary);
      color: map-get($theme, event-color-primary);
    }

    .cal-all-day-events {
      border-color: map-get($theme, border-color);
    }

    .cal-header.cal-today {
      background-color: map-get($theme, today-bg);
    }

    .cal-header.cal-weekend span {
      color: map-get($theme, weekend-color);
    }

    .cal-time-events {
      border-color: map-get($theme, border-color);

      .cal-day-columns {
        &:not(.cal-resize-active) {
          .cal-hour-segment:hover {
            background-color: map-get($theme, bg-active);
          }
        }
      }
    }

    .cal-hour-odd {
      background-color: map-get($theme, bg-secondary);
    }

    .cal-drag-over .cal-hour-segment {
      background-color: map-get($theme, bg-active);
    }

    .cal-hour:not(:last-child) .cal-hour-segment,
    .cal-hour:last-child :not(:last-child) .cal-hour-segment {
      border-bottom-color: map-get($theme, border-color);
    }
  }
}

.cal-week-view {
  .cal-day-headers {
    display: flex;
    padding-left: 70px;
    border: 1px solid;
  }

  .cal-day-headers .cal-header {
    flex: 1;
    text-align: center;
    padding: 5px;

    &:not(:last-child) {
      border-right: 1px solid;
    }

    &:first-child {
      border-left: 1px solid;
    }
  }

  .cal-day-headers span {
    font-weight: 400;
    opacity: 0.5;
  }

  .cal-day-column {
    flex-grow: 1;
    border-left: solid 1px;
  }

  .cal-event {
    font-size: 12px;
    border: 1px solid;
  }

  .cal-time-label-column {
    width: 70px;
    height: 100%;
  }

  .cal-all-day-events {
    border: solid 1px;
    border-top: 0;
    border-bottom-width: 3px;
    padding-top: 3px;
    position: relative;

    .cal-day-columns {
      height: 100%;
      width: 100%;
      display: flex;
      position: absolute;
      top: 0;
      z-index: 0;
    }

    .cal-events-row {
      position: relative;
      height: 31px;
      margin-left: 70px;
    }

    .cal-event-container {
      display: inline-block;
      position: absolute;

      &.resize-active {
        z-index: 1;
        pointer-events: none;
      }
    }

    .cal-event {
      padding: 0 5px;
      margin-left: 2px;
      margin-right: 2px;
      height: 28px;
      line-height: 28px;
    }

    .cal-starts-within-week .cal-event {
      border-top-left-radius: 5px;
      border-bottom-left-radius: 5px;
    }

    .cal-ends-within-week .cal-event {
      border-top-right-radius: 5px;
      border-bottom-right-radius: 5px;
    }

    .cal-time-label-column {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
    }

    .cal-resize-handle {
      width: 6px;
      height: 100%;
      cursor: col-resize;
      position: absolute;
      top: 0;

      &.cal-resize-handle-after-end {
        right: 0;
      }
    }
  }

  .cal-event,
  .cal-header {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .cal-drag-active {
    pointer-events: none;
    z-index: 1;

    & * {
      pointer-events: none;
    }
  }

  .cal-time-events {
    position: relative;
    border: solid 1px;
    border-top: 0;
    display: flex;

    .cal-day-columns {
      display: flex;
      flex-grow: 1;
    }

    .cal-day-column {
      position: relative;
    }

    .cal-event-container {
      position: absolute;
      z-index: 1;
    }

    .cal-event {
      width: calc(100% - 2px);
      height: calc(100% - 2px);
      margin: 1px;
      padding: 0 5px;
      line-height: 25px;
    }

    .cal-resize-handle {
      width: 100%;
      height: 4px;
      cursor: row-resize;
      position: absolute;

      &.cal-resize-handle-after-end {
        bottom: 0;
      }
    }
  }

  .cal-hour-segment {
    position: relative;

    &::after {
      content: '\00a0';
    }
  }

  .cal-event-container:not(.cal-draggable) {
    cursor: pointer;
  }

  .cal-draggable {
    cursor: move;
  }

  /* stylelint-disable-next-line selector-type-no-unknown */
  mwl-calendar-week-view-hour-segment, /* fix for https://github.com/mattlewis92/angular-calendar/issues/260*/
  .cal-hour-segment {
    display: block;
  }

  .cal-hour:not(:last-child) .cal-hour-segment,
  .cal-hour:last-child :not(:last-child) .cal-hour-segment {
    border-bottom: thin dashed;
  }

  .cal-time {
    font-weight: bold;
    padding-top: 5px;
    width: 70px;
    text-align: center;
  }

  .cal-hour-segment.cal-after-hour-start {
    .cal-time {
      display: none;
    }
  }

  .cal-starts-within-day .cal-event {
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
  }

  .cal-ends-within-day .cal-event {
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
  }
}

@include cal-week-view-theme($cal-week-view-vars);
