@use 'angular-material-css-vars' as mat-css-vars;
@use '../../../../styles/_globals.scss' as *;

.month-grid-container {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: auto repeat(var(--nr-of-weeks), 1fr);
  gap: 1px;
  height: calc(100vh - 120px);

  .cdk-drag-dragging {
    z-index: 1000;
    transform: rotate(2deg);
  }

  .cdk-drag-placeholder {
    opacity: 0.3;
  }
}

.weekday-header {
  text-align: center;
  font-weight: 600;
  padding: 6px;
  background: var(--bg);
  color: var(--text-color);
  border: 1px solid var(--grid-color);
  grid-row: 1;

  @include mq(xs, max) {
    padding: 3px;
    font-size: 11px;
  }

  &:nth-child(1) {
    grid-column: 1;
  } // Sun
  &:nth-child(2) {
    grid-column: 2;
  } // Mon
  &:nth-child(3) {
    grid-column: 3;
  } // Tue
  &:nth-child(4) {
    grid-column: 4;
  } // Wed
  &:nth-child(5) {
    grid-column: 5;
  } // Thu
  &:nth-child(6) {
    grid-column: 6;
  } // Fri
  &:nth-child(7) {
    grid-column: 7;
  } // Sat
}

.month-day-cell {
  background: var(--bg);
  border: 1px solid var(--grid-color);
  display: flex;
  flex-direction: column;
  min-height: 80px;
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow: hidden;

  :host[style*='--nr-of-weeks: 3'] & {
    min-height: 120px;
  }

  :host[style*='--nr-of-weeks: 4'] & {
    min-height: 100px;
  }

  :host[style*='--nr-of-weeks: 5'] & {
    min-height: 85px;
  }

  :host[style*='--nr-of-weeks: 6'] & {
    min-height: 70px;
  }

  @include mq(xs, max) {
    min-height: 50px;

    :host[style*='--nr-of-weeks: 3'] & {
      min-height: 80px;
    }

    :host[style*='--nr-of-weeks: 4'] & {
      min-height: 65px;
    }

    :host[style*='--nr-of-weeks: 5'] & {
      min-height: 55px;
    }

    :host[style*='--nr-of-weeks: 6'] & {
      min-height: 50px;
    }
  }

  &.other-month {
    opacity: 0.4;
  }

  &.today {
    .month-day-number {
      background: var(--c-primary);
      color: white;
      border-radius: 50%;
      width: 24px;
      height: 24px;
      display: flex;
      align-items: center;
      justify-content: center;

      @include mq(xs, max) {
        width: 20px;
        height: 20px;
        font-size: 12px;
      }
    }
  }

  // Hover effect
  &:hover {
    background: var(--bg-lighter);
  }

  // Drag over effect
  &.drag-over {
    background: mat-css-vars.mat-css-color-primary($opacity: 0.1);
    border-color: mat-css-vars.mat-css-color-primary();
  }
}

.month-day-header {
  padding: var(--s);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--grid-color);

  @include mq(xs, max) {
    padding: var(--s-half);
  }

  .month-day-number {
    font-weight: 600;
    font-size: 14px;

    @include mq(xs, max) {
      font-size: 12px;
    }
  }
}

.month-day-events {
  flex: 1;
  padding: var(--s-half);
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100% - 35px);
  width: 100%;
  box-sizing: border-box;

  @include mq(xs, max) {
    padding: var(--s-quarter);
    max-height: calc(100% - 25px);
  }

  :host[style*='--nr-of-weeks: 3'] & .month-event:nth-child(n + 8) {
    display: none;
  }

  :host[style*='--nr-of-weeks: 4'] & .month-event:nth-child(n + 6) {
    display: none;
  }

  :host[style*='--nr-of-weeks: 5'] & .month-event:nth-child(n + 4) {
    display: none;
  }

  :host[style*='--nr-of-weeks: 6'] & .month-event:nth-child(n + 3) {
    display: none;
  }

  @include mq(xs, max) {
    :host[style*='--nr-of-weeks: 3'] & .month-event:nth-child(n + 4) {
      display: none;
    }

    :host[style*='--nr-of-weeks: 4'] & .month-event:nth-child(n + 3) {
      display: none;
    }

    :host[style*='--nr-of-weeks: 5'] & .month-event:nth-child(n + 2) {
      display: none;
    }

    :host[style*='--nr-of-weeks: 6'] & .month-event:nth-child(n + 2) {
      display: none;
    }
  }

  .month-event:nth-child(n + 4) {
    display: none;

    @media (min-height: 800px) {
      display: block;
    }

    @media (min-height: 800px) and (max-width: 768px) {
      &:nth-child(n + 3) {
        display: none;
      }
    }
  }

  &::after {
    content: attr(data-more-events);
    display: none;
    font-size: 10px;
    color: rgba(0, 0, 0, 0.54);
    padding: var(--s-quarter);

    @include darkTheme() {
      color: rgba(255, 255, 255, 0.54);
    }
  }
}

.month-event {
  margin-bottom: 1px;

  .month-schedule-event {
    font-size: 11px;
    padding: var(--s-quarter) var(--s-half);
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    width: 100%;
    @include truncateText();
    box-sizing: border-box;

    @include mq(xs, max) {
      font-size: 10px;
      padding: 1px var(--s-quarter);
    }

    // Hover effect
    &:hover {
      opacity: 0.8;
      transform: scale(1.02);
      transition: var(--transition-standard);
    }
  }
}

@include mq(xs, max) {
  .month-grid-container {
    height: calc(100vh - 150px);
    gap: 0.5px;
  }

  .month-day-cell {
    min-height: 60px;
  }

  .month-day-events .month-event:nth-child(n + 3) {
    display: none;
  }

  ::ng-deep schedule-event .ico-wrapper {
    display: none;
  }
}
