@use 'sass:color';

@import 'bootstrap/functions'; //***
@import 'variables';

//***
$td-light: $dropdown-bg !default; //***
$td-widget-background: $td-light !default;
$td-font-color: $dropdown-color !default; //***
$td-timepicker-font-size: 1.2em !default;
$td-active-bg: #0d6efd !default;
$td-range-bg: color.scale($td-active-bg, $lightness: -40%);
$td-active-color: $td-light !default;
$td-active-border-color: $td-light;
$td-border-radius: 999px !default;
$td-btn-hover-bg: #e9ecef !default;
$td-disabled-color: #6c757d !default;
$td-alternate-color: rgba(0, 0, 0, .38) !default;
$td-secondary-border-color: #ccc !default;
$td-secondary-border-color-rgba: rgba(0, 0, 0, 0.2) !default;
$td-primary-border-color: $td-light !default;
$td-text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25) !default;
$td-dow-color: rgba(0, 0, 0, .50);

$td-dark: $dropdown-dark-bg !default; //***
$td-dark-widget-background: $td-dark !default;
$td-dark-font-color: $dropdown-dark-color !default; //***
$td-dark-active-bg: #4db2ff !default;
$td-dark-range-bg: color.scale($td-dark-active-bg, $lightness: -40%);
$td-dark-active-color: #fff !default;
$td-dark-active-border-color: $td-dark;
$td-dark-btn-hover-bg: rgb(35, 38, 39) !default;
$td-dark-disabled-color: #6c757d !default;
$td-dark-alternate-color: rgba(232, 230, 227, 0.38) !default;
$td-dark-secondary-border-color: #ccc !default;
$td-dark-secondary-border-color-rgba: rgba(232, 230, 227, 0.2) !default;
$td-dark-primary-border-color: $td-dark !default;
$td-dark-text-shadow: 0 -1px 0 rgba(232, 230, 227, 0.25) !default;
$td-dark-dow-color: rgba(232, 230, 227, .50);

:root {
  --td-light: #{$td-light};
  --td-widget-background: #{$td-widget-background};
  --td-font-color: #{$td-font-color};
  --td-timepicker-font-size: #{$td-timepicker-font-size};
  --td-active-bg: #{$td-active-bg};
  --td-range-bg: #{$td-range-bg};
  --td-active-color: #{$td-active-color};
  --td-active-border-color: #{$td-active-border-color};
  --td-border-radius: #{$td-border-radius};
  --td-btn-hover-bg: #{$td-btn-hover-bg};
  --td-disabled-color: #{$td-disabled-color};
  --td-alternate-color: #{$td-alternate-color};
  --td-secondary-border-color: #{$td-secondary-border-color};
  --td-secondary-border-color-rgba: #{$td-secondary-border-color-rgba};
  --td-primary-border-color: #{$td-primary-border-color};
  --td-text-shadow: #{$td-text-shadow};
  --td-dow-color: #{$td-dow-color};

  --td-dark: #{$td-dark};
  --td-dark-widget-background: #{$td-dark-widget-background};
  --td-dark-font-color: #{$td-dark-font-color};
  --td-dark-active-bg: #{$td-dark-active-bg};
  --td-dark-range-bg: #{$td-dark-range-bg};
  --td-dark-active-color: #{$td-dark-active-color};
  --td-dark-active-border-color: #{$td-dark-active-border-color};
  --td-dark-btn-hover-bg: #{$td-dark-btn-hover-bg};
  --td-dark-disabled-color: #{$td-dark-disabled-color};
  --td-dark-alternate-color: #{$td-dark-alternate-color};
  --td-dark-secondary-border-color: #{$td-dark-secondary-border-color};
  --td-dark-secondary-border-color-rgba: #{$td-dark-secondary-border-color-rgba};
  --td-dark-primary-border-color: #{$td-dark-primary-border-color};
  --td-dark-text-shadow: #{$td-dark-text-shadow};
  --td-dark-dow-color: #{$td-dark-dow-color};

  --td-popover-border-color: #{$popover-border-color}; //***
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important; // Fix for https://github.com/twbs/bootstrap/issues/25686
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.tempus-dominus-widget {
  list-style: none;
  margin: 0; //*** No margin for popper
  padding: 4px;
  min-width: 19rem; //***
  border-radius: 4px;
  display: none;
  background-color: var(--td-widget-background);
  border: 1px solid var(--td-popover-border-color); //***
  z-index: 9999;
  box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.2), 0 4px 5px 0 rgba(0, 0, 0, 0.14),
    0 1px 10px 0 rgba(0, 0, 0, 0.12);

  &.calendarWeeks {
    width: 21rem;

    & .date-container-days {
      grid-auto-columns: 12.5%;
      grid-template-areas: 'a a a a a a a a';
    }
  }

  [data-action] {
    cursor: pointer;

    &::after {
      @extend .visually-hidden;
      content: attr(title);
    }

    &.disabled,
    &.disabled:hover {
      background: none;
      cursor: not-allowed;
    }
  }

  //popper
  .arrow {
    display: none;
  }

  //end popper

  &.show {
    display: block;
    &.date-container {
      min-height: 315px;
    }

    &.time-container {
      min-height: 217px;
    }
  }

  .td-collapse {
    &:not(.show) {
      display: none;
    }
  }

  .td-collapsing {
    height: 0;
    overflow: hidden;
    transition: height 0.35s ease;
  }

  &.timepicker-sbs {
    @media (min-width: 576px) {
      width: 38em;
    }

    @media (min-width: 768px) {
      width: 38em;
    }

    @media (min-width: 992px) {
      width: 38em;
    }

    .td-row {
      display: flex;

      .td-half {
        flex: 0 0 auto;
        width: 50%;
      }
    }
  }

  div[data-action]:active {
    box-shadow: none;
  }

  .timepicker-hour,
  .timepicker-minute,
  .timepicker-second {
    width: 54px;
    font-weight: bold;
    font-size: $td-timepicker-font-size;
    margin: 0;
  }

  button[data-action] {
    padding: 6px;
  }

  .toggleMeridiem {
    text-align: center;
    height: 38px;
  }

  .calendar-header {
    display: grid;
    grid-template-areas: 'a a a';
    margin-bottom: 10px;
    font-weight: bold;

    & .next {
      text-align: center; //***
      padding-right: 10px;
    }

    & .previous {
      text-align: center; //***
      padding-left: 10px;
    }

    & .picker-switch {
      text-align: center;
    }
  }

  .toolbar {
    display: grid;
    grid-auto-flow: column;
    grid-auto-rows: 40px;

    & div {
      border-radius: var(--td-border-radius);
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      display: flex;
    }
  }

  .date-container-days {
    display: grid;
    grid-template-areas: 'a a a a a a a';
    grid-auto-rows: 40px;
    grid-auto-columns: calc(100% / 7);

    .range-in {
      @extend .active;
      background-color: var(--td-range-bg) !important;
      border: none;
      border-radius: 0 !important;
      box-shadow: -5px 0 0 var(--td-range-bg), 5px 0 0 var(--td-range-bg);
    }

    .range-end {
      @extend .active;
      border-radius: 0 50px 50px 0 !important;
    }

    .range-start {
      @extend .active;
      border-radius: 50px 0 0 50px !important;
    }

    & .dow {
      align-items: center;
      justify-content: center;
      text-align: center;
    }

    & .cw {
      width: 90%;
      height: 90%;
      align-items: center;
      justify-content: center;
      display: flex;
      font-size: 0.8em;
      line-height: 20px;
      cursor: default;
    }
  }

  .date-container-decades,
  .date-container-years,
  .date-container-months {
    display: grid;
    grid-template-areas: 'a a a';
    grid-auto-rows: calc(calc(19rem - 2 * 4px) / 7);
  }

  .time-container-hour,
  .time-container-minute,
  .time-container-second {
    display: grid;
    grid-template-areas: 'a a a a';
    grid-auto-rows: calc(calc(19rem - 2 * 4px) / 7);
  }

  .time-container-clock {
    display: grid;
    grid-auto-rows: calc(calc(19rem - 2 * 4px) / 7);

    & .no-highlight {
      width: 90%;
      height: 90%;
      align-items: center;
      justify-content: center;
      display: flex;
    }
  }

  .date-container-decades,
  .date-container-years,
  .date-container-months,
  .date-container-days,
  .time-container-clock,
  .time-container-hour,
  .time-container-minute,
  .time-container-second {
    div:not(.no-highlight) {
      width: 90%;
      height: 90%;
      border-radius: var(--td-border-radius);
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      display: flex;

      &.disabled,
      &.disabled:hover {
        background: none;
        cursor: not-allowed;
      }

      &.today {
        position: relative;

        &:before {
          content: '';
          display: inline-block;
          border: solid transparent;
          border-width: 0 0 7px 7px;
          position: absolute;
          bottom: 6px;
          right: 6px;
        }
      }
    }
  }

  .time-container {
    margin-bottom: 0.5rem;
  }

  button {
    display: inline-block;
    font-weight: 400;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out,
      border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  }

  &.tempus-dominus-widget-readonly {
    table td.day,
    table td.hour,
    table td.minute,
    table td.second,
    table td [data-action='incrementHours'],
    table td [data-action='incrementMinutes'],
    table td [data-action='incrementSeconds'],
    table td [data-action='decrementHours'],
    table td [data-action='decrementMinutes'],
    table td [data-action='decrementSeconds'],
    table td [data-action='showHours'],
    table td [data-action='showMinutes'],
    table td [data-action='showSeconds'],
    table td [data-action='togglePeriod'] {
      pointer-events: none;
      cursor: default;

      &:hover {
        background: none;
      }
    }
  }

  &.light {
    color: var(--td-font-color);
    background-color: var(--td-widget-background);

    [data-action] {
      &.disabled,
      &.disabled:hover {
        color: var(--td-disabled-color);
      }
    }

    .toolbar {
      & div {
        &:hover {
          background: var(--td-btn-hover-bg);
        }
      }
    }

    .date-container-days {
      & .dow {
        color: var(--td-dow-color);
      }

      & .cw {
        color: var(--td-alternate-color);
      }
    }

    .date-container-decades,
    .date-container-years,
    .date-container-months,
    .date-container-days,
    .time-container-clock,
    .time-container-hour,
    .time-container-minute,
    .time-container-second {
      div:not(.no-highlight) {
        &:hover {
          background: var(--td-btn-hover-bg);
        }

        &.active {
          background-color: var(--td-active-bg);
          color: var(--td-active-color) !important; //***
          text-shadow: var(--td-text-shadow);

          &.old,
          &.new {
            color: var(--td-active-color) !important; //***
          }
        }

        &.active.today:before {
          border-bottom-color: var(--td-active-border-color);
        }

        &.old,
        &.new {
          color: var(--td-alternate-color);
        }

        &.disabled,
        &.disabled:hover {
          color: var(--td-disabled-color);
        }

        &.today {
          &:before {
            border-bottom-color: var(--td-active-bg);
            border-top-color: var(--td-secondary-border-color-rgba);
          }
        }
      }
}

    button {
      color: var(--td-active-color);
      background-color: var(--td-active-bg);
      border-color: var(--td-active-bg);
    }
  }

  &.dark {
    color: var(--td-dark-font-color);
    background-color: var(--td-dark-widget-background);

    [data-action] {
      &.disabled,
      &.disabled:hover {
        color: var(--td-dark-disabled-color);
      }
    }

    .toolbar {
      & div {
        &:hover {
          background: var(--td-dark-btn-hover-bg);
        }
      }
    }

    .date-container-days {
      & .dow {
        color: var(--td-dark-dow-color);
      }

      .range-in {
        background-color: var(--td-dark-range-bg) !important;
        box-shadow: -5px 0 0 var(--td-dark-range-bg),
          5px 0 0 var(--td-dark-range-bg);
      }

      & .cw {
        color: var(--td-dark-alternate-color);
      }
    }

    .date-container-decades,
    .date-container-years,
    .date-container-months,
    .date-container-days,
    .time-container-clock,
    .time-container-hour,
    .time-container-minute,
    .time-container-second {
      div:not(.no-highlight) {
       &:hover {
          background: var(--td-dark-btn-hover-bg);
        }

        &.active {
          background-color: var(--td-dark-active-bg);
          color: var(--td-dark-active-color);
          text-shadow: var(--td-dark-text-shadow);

          &.old,
          &.new {
            color: var(--td-dark-active-color);
          }
        }

        &.active.today:before {
          border-bottom-color: var(--td-dark-active-border-color);
        }

        &.old,
        &.new {
          color: var(--td-dark-alternate-color);
        }

        &.disabled,
        &.disabled:hover {
          color: var(--td-dark-disabled-color);
        }

        &.today {
          &:before {
            border-bottom-color: var(--td-dark-active-bg);
            border-top-color: var(--td-dark-secondary-border-color-rgba);
          }
        }
      }
    }

    button {
      color: var(--td-dark-active-color);
      background-color: var(--td-dark-active-bg);
      border-color: var(--td-dark-active-bg);
    }
  }
}