@import '../jnt-variables';
@import '../forms/button';
@import '../elements/icon';
@import '../jnt-hosts';
@import '../jnt-utils';
@import '../jnt-functions';

@mixin jnt-calendar($passed: (), $context: null, $strategy: 'changes') {
  $defs: (
    layout: fixed,
    day: (
      padding: null,
      selected: (
        background-color: $jnt-primary-light-color,
        color: $jnt-white-color
      )
    ),
    metrics: (
      width: null
    )
  );
  $vars: $passed;
  $declare: false;
  $wrapper: null;
  @if $jnt-ng-deep {
    $wrapper: '::ng-deep';
  }
  @if $passed == () or $strategy == 'merge' {
    $vars: recursive-map-merge($defs, $passed);
    $declare: true;
  }
  #{if($context, $context, $jnt-calendar-host)} {
    @if $declare {
      @include reset-default();
      display: block;
      box-sizing: border-box;
      background-color: $jnt-primary-background;
      &[data-disabled='true'] {
        cursor: default;
        pointer-events: none;
        #{$wrapper} table[child-of=jnt-calendar-host] {
          tbody[child-of=jnt-calendar-host] tr[child-of=jnt-calendar-host] td[child-of=jnt-calendar-host], th[child-of=jnt-calendar-host] {
            color: $jnt-control-disabled-label-color;
            background-color: $jnt-control-disabled-background;
          }
        }
      }
    }
  }
  #{$wrapper} #{$context} table[child-of=jnt-calendar-host] {
    table-layout: map-get($vars, layout);
    @if $declare {
      table-layout: auto;
      border-collapse: collapse;
      border-spacing: 0;
      width: 100%;
    }
    @if map-has-key($vars, metrics) and map-get(map-get($vars, metrics), width) {
      $metrics: map-get($vars, metrics);
      table-layout: fixed;
      [data-metrics][child-of=jnt-calendar-host] {
        width: map-get($metrics, width);
      }
    }
    [data-divider][child-of=jnt-calendar-host] {
      @if $declare {
        width: 2px;
      }
    }
    thead[child-of=jnt-calendar-host] {
      [data-arrow][child-of=jnt-calendar-host] {
        @if $declare {
          @include jnt-button((
            sizes: (
              small: (
                height: 28px,
                padding-without-text: 0 $jnt-gutter-tiny,
                icon: (
                  size: 16px
                )
              )
            )
          ), '&');
        }
      }
      [data-date][child-of=jnt-calendar-host] {
        @if $declare {
          @include jnt-button((
            font-weight: $jnt-font-weight-semi-bold,
            sizes: (
              small: (
                height: 28px,
                font-size: 14px,
                padding: 0 $jnt-gutter-tiny
              )
            )
          ), '&');
        }
      }
      [data-year][child-of=jnt-calendar-host] {
        @if $declare {
          color: $jnt-control-disabled-label-color;
        }
      }
      [data-days][child-of=jnt-calendar-host] {
        > th[child-of=jnt-calendar-host] {
          @if $declare {
            padding: $jnt-gutter-normal $jnt-gutter-tiny;
            color: $jnt-primary-text-light-color;
            font-weight: $jnt-font-weight-bold;
          }
        }
      }
      [data-metrics][child-of=jnt-calendar-host] {
        @if $declare {
          font-weight: $jnt-font-weight-semi-bold;
        }
      }
      th[child-of=jnt-calendar-host][data-metric][child-of=jnt-calendar-host] {
        @if $declare {
          font-weight: $jnt-font-weight-semi-bold;
        }
      }
    }
    tbody[child-of=jnt-calendar-host] {
      tr[child-of=jnt-calendar-host] {
        td[child-of=jnt-calendar-host] {
          @if $declare {
            &[data-day] {
              box-shadow: inset -1px 0px 0px $jnt-secondary-dark-color,
              inset 0px -1px 0px $jnt-secondary-dark-color;
              &:last-child {
                box-shadow: inset 0px -1px 0px $jnt-secondary-dark-color;
              }
            }
            &[data-metric] {
              box-shadow: inset -1px 0px 0px $jnt-white-color,
              inset 0px -1px 0px $jnt-white-color;
            }
          }
        }
        &:last-child {
          @if $declare {
            td[child-of=jnt-calendar-host] {
              &[data-day] {
                box-shadow: inset -1px 0px 0px $jnt-secondary-dark-color;
                &:last-child {
                  box-shadow: none;
                }
              }
              &[data-metric] {
                box-shadow: inset -1px 0px 0px $jnt-white-color;
              }
            }
          }
        }
        &[data-current-week='true'] {
          @if $declare {
            [data-day][child-of=jnt-calendar-host], [data-metric][child-of=jnt-calendar-host], [data-divider][child-of=jnt-calendar-host] {
              box-shadow: inset 0 2px 0 0 $jnt-primary-light-color,
              inset 0 -2px 0 0 $jnt-primary-light-color !important;
              &:first-child {
                border-top-left-radius: $jnt-corner-small;
                border-bottom-left-radius: $jnt-corner-small;
                box-shadow: inset 1px 1px 0 1px $jnt-primary-light-color,
                inset 1px -1px 0 1px $jnt-primary-light-color !important;
              }
              &:last-child {
                border-top-right-radius: $jnt-corner-small;
                border-bottom-right-radius: $jnt-corner-small;
                box-shadow: inset -2px -2px 0 0 $jnt-primary-light-color,
                inset 0 2px 0 0 $jnt-primary-light-color !important;
              }
            }
          }
        }
        td[child-of=jnt-calendar-host] {
          @if $declare {
            min-width: 38px;
            font-size: $jnt-font-size-small;
            box-sizing: border-box;
            user-select: none;
            padding: 0;
          }
          [data-default][child-of=jnt-calendar-host] {
            @if $declare {
              padding: $jnt-gutter-small $jnt-gutter-tiny;
            }
          }
          &[data-day] {
            @if $declare {
              cursor: pointer;
              &:nth-child(6),
              &:nth-child(7) {
                background-color: $jnt-secondary-dark-color;
              }
              &[data-selected-day='false'][data-today='false']:hover,
              &[data-selected-month='false']:hover,
              &[data-selected-year='false']:hover {
                background-color: $jnt-highlight-background;
                color: $jnt-primary-text-dark-color;
              }
              &:focus {
                box-shadow: inset $jnt-outline-shadow-small $jnt-primary-color;
                outline: 0;
              }
              &[data-current-month='false'] {
                [data-default][child-of=jnt-calendar-host] {
                  color: $jnt-primary-text-light-color;
                }
              }
              &[data-today='true'],
              &[data-day-extend][data-current-month='true'],
              &[data-year][data-current-year='true'] {
                background-color: $jnt-primary-light-color;
                color: $jnt-white-color;
              }
              &[data-day-extend] {
                height: 68px;
              }
            }
            @if map-has-key($vars, day) {
              $day: map-get($vars, day);
              padding: map-get($day, padding);
              &[data-selected-day='true'] {
                @if map-has-key($day, selected) {
                  $selected: map-get($day, selected);
                  background-color: map-get($selected, background-color);
                  color: map-get($selected, color);
                  [data-default][child-of=jnt-calendar-host] {
                    color: map-get($selected, color);
                  }
                }
              }
            }
          }
          &[data-metric] {
            @if $declare {
              background-color: $jnt-secondary-color;
            }
          }
        }
      }
    }
    td[child-of=jnt-calendar-host], th[child-of=jnt-calendar-host] {
      @if $declare {
        vertical-align: middle;
        text-align: center;
        position: relative;
      }
    }
  }
}
@if $jnt-debug {
  @debug 'calendar compiled';
}
