/* stylelint-disable media-feature-name-no-unknown */
//* Date Picker
//================================================== *

.datepicker {
  width: $datepicker-default-width;
  padding-right: 30px;
  text-overflow: ellipsis;

  &.input-xs {
    width: $field-xs;
  }

  &.input-sm {
    width: $field-sm;
  }

  &.input-mm {
    width: $field-mm;
  }

  &.input-md {
    width: $field-md;
  }

  &.input-lg {
    width: $field-lg;
  }

  &.input-full {
    width: $field-full;
  }

  &.input-auto {
    width: auto;
  }

  &.datetime {
    padding-right: 30px;
    width: auto;
  }

  + .trigger,
  + .tooltip-description + .trigger {
    color: $triggerfield-calendar-icon-color;
    cursor: pointer;
    height: 24px;
    margin-left: -30px;
    margin-top: 5px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 24px;
    min-width: 24px;
    position: absolute;
    width: 24px;
    z-index: 1;

    .icon {
      color:  $datepicker-calendar-icon-color;
      height: 18px;
      position: relative;
      margin: 0;
      width: 18px;
      top: -1px;
    }

    &:hover {
      color: $trigger-hover-color;
    }

    &:active {
      color: $trigger-active-color;
    }
  }

  &.is-open {
    border-color: $input-color-focus-border;

    + .trigger {
      color: $ids-color-palette-white;
    }
  }

  + .trigger + .icon-error {
    margin-left: -50px;
  }

  + .audible + .trigger + .icon-error {
    margin-left: -50px;
  }

  &:disabled {
    border-color: $datepicker-disabled-border-color;

    + .trigger {
      color: $datepicker-disabled-icon-color;
      cursor: default;
    }
  }

  &[readonly]:not(.is-not-editable) {
    + .trigger {
      color: $datepicker-readonly-icon-color;
      cursor: default;

      &:hover {
        color: $datepicker-readonly-icon-color !important;
        cursor: default;
        background-color: transparent !important;

        &.icon,
        &.btn-icon {
          color: $datepicker-readonly-icon-color !important;
          background-color: transparent !important;
        }
      }

      &.btn-icon:hover:not([disabled]) .icon {
        color: $datepicker-readonly-icon-color !important;
      }
    }
  }

  &.is-not-editable {
    background-color: $input-color-initial-background;
    border: 1px solid $input-color-initial-border;
    color: $input-color;

    &:not([disabled]) + .trigger {
      color: $triggerfield-calendar-icon-color;
      cursor: pointer;
    }

    &:focus {
      @include focus-state();
    }

    &.error {
      border-color: $error-border-color;
    }
  }
}

.monthview-popup .monthview .monthview-header .calendar-toolbar {
  padding: 0;
  min-width: 344px;

  @media screen and (max-width: $breakpoint-big-phone) {
    min-width: 320px;

    .btn-monthyear-pane {
      margin: 0;
      padding: 4px 0 5px;
    }

    .toolbar-section.buttonset {
      padding-inline: 0;
    }
  }
}

// Popup Adjustments
.monthview-popup.popover {
  max-width: inherit;
  min-height: auto;
  margin-top: 1px;

  @media screen and (max-device-width: ($breakpoint-phone - 1)) {
    min-width: 260px;
  }

  @media screen and (max-height: ($breakpoint-big-phone + 50)) {
    overflow-y: auto;
  }

  // Supports landscape orientation for small iPhone (5, 5S, 5C and 5SE)
  @media only screen
    and (minwidth: $breakpoint-phone)
    and (max-device-width: ($breakpoint-big-phone + 88))
    and (-webkit-min-device-pixel-ratio: 2)
    and (orientation: landscape) {
    height: 250px;
    overflow-y: auto;
  }

  .monthview {
    min-width: 330px;
  }

  .monthview .monthview-table {
    max-width: 310px;
  }

  // Week picker adjustments
  &.is-range-week {
    .monthview td .day-text {
      transition: none;
    }

    tr:focus {
      border-radius: 50px;
      box-shadow: 0 0 0 1px $input-color-focus-border;
      outline: none;
    }
  }

  .tooltip-content {
    padding: 0;
  }

  .popup-footer {
    button {
      background-color: transparent;
      width: 50%;

      &.btn-primary:focus {
        box-shadow: 0 0 0 0 $body-color-primary-background, 0 0 0 0.12rem $button-color-primary-initial-background, $focus-box-shadow;
        z-index: 3;
      }

      &.is-cancel-month-pane {
        display: none;
      }

      &.is-select-month-pane {
        transition: width 0.1s ease-in-out;
        width: 100%;
        border-left: thin solid transparent;
      }
    }
  }

  .time-parts {
    padding: 10px;
  }
}

// Short fields
.field-short,
.form-layout-compact .field {
  .datepicker {
    padding-right: 24px;
    vertical-align: top;

    + .trigger,
    + .tooltip-description + .trigger {
      height: 20px;
      margin-left: -24px;
      margin-block-start: 1px;
      display: inline-flex;
      justify-content: center;
      min-height: 20px;
      min-width: 20px;
      width: 20px;

      .icon {
        height: 20px;
        width: 14px;
        top: 0;
      }
    }
  }
}

// RTL Styles
html[dir='rtl'] {
  .datepicker {
    padding: 0 12px 0 32px;

    + .trigger {
      margin-left: -23px;
      margin-right: -32px;
    }

    + .trigger + .icon-error {
      margin-left: inherit;
      margin-right: -50px;
    }

    + .audible + .trigger + .icon-error {
      margin-left: inherit;
      margin-right: -50px;
    }

    &.datetime {
      padding-left: 30px;
      padding-right: 10px;
    }
  }

  // Short fields
  .field-short,
  .form-layout-compact .field {
    .datepicker {
      padding-left: 27px;
      padding-right: 2px;

      + .trigger {
        margin-left: inherit;
        margin-right: -24px;
      }
    }
  }

  .monthview-popup .calendar-toolbar {
    button.next {
      margin-inline-start: -6px;
    }

    &.is-alternate .today {
      left: 0;
    }
  }

  .monthview-popup.popover .popup-footer {
    button {
      margin-left: 0;

      &:first-child:hover {
        border-left: none;
      }
    }
  }
}

// TODO
.ie-edge {
  .monthview .btn-monthyear-pane {
    margin-left: 8px;
  }
}

@include respond-to(tabletdown) {
  .monthview-popup.popover .monthview {
    min-width: 310px;

    @media only screen
      and (minwidth: $breakpoint-phone)
      and (max-device-width: ($breakpoint-big-phone + 88))
      and (-webkit-min-device-pixel-ratio: 2)
      and (orientation: portrait) {
      min-width: 280px;
    }
  }
}
