@use "../../../../styles/tokens/color";
@use "../../../../styles/tokens/space";
@use "../../../../styles/tools/visibility";
@use "../../../../styles/tools/convert";
@use "../../../Button/styles/mixins" as Button;

@layer components {
  .datepicker {
    max-width: convert.to-rem(300px);

    .text-input {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }
  }

  .daypickr {
    position: absolute;
    top: calc(100% - 2px);
    right: 0;
    z-index: 3;
  }

  .daypickr__toggle {
    margin-right: 0;
  }

  .daypickr__content {
    width: convert.to-rem(300px);
    padding: space.get("medium");
    border: 2px solid var(--color-border-contrast);
    background: var(--color-surface-primary);
    border-radius: convert.to-rem(5px);
  }

  .daypickr__calendar {
    width: 100%;
  }

  .daypickr__calendar-cell {
    border: 2px solid transparent;
  }

  .daypickr__header {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    margin-bottom: space.get("small");
  }

  .daypickr__select {
    padding: 2px convert.to-rem(16px) 2px 0;
    border: 2px solid transparent;
    border-radius: 0;
    background-color: transparent;
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 10L12 18L4 10L6 8L12 14L18 8L20 10Z'/%3E%3C/svg%3E%0A");
    background-position: right center;
    background-repeat: no-repeat;
    font-weight: bold;
    appearance: none;
    -webkit-appearance: none; // stylelint-disable-line property-no-vendor-prefix
    color: var(--color-text-default) !important;

    &--year {
      margin-right: space.get("small");
    }

    &:hover {
      border-color: var(--color-surface-moderate);
    }
  }

  .is-dark .daypickr__select {
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' fill='white' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 10L12 18L4 10L6 8L12 14L18 8L20 10Z'/%3E%3C/svg%3E%0A");
  }

  .daypickr__pagination {
    margin-right: convert.to-rem(-5px);
  }

  [class*="daypickr__button--pagination"] {
    position: relative;
    text-indent: -9999px;
    display: inline-block !important;
    margin: 0 !important;
  }

  .daypickr__button--pagination {
    &-next::before,
    &-prev::before {
      content: "";
      position: absolute;
      width: 100%;
      height: 100%;
      top: -50%;
      left: -50%;
      transform: translate(50%, 50%);
      background-position: center;
      background-repeat: no-repeat;
    }

    &-prev::before {
      background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M14 20L6 12L14 4L16 6L10 12L16 18L14 20Z'/%3E%3C/svg%3E%0A");
    }

    &-next::before {
      background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 20L18 12L10 4L8 6L14 12L8 18L10 20Z'/%3E%3C/svg%3E%0A");
    }
  }

  .is-dark .daypickr__button--pagination {
    &-prev::before {
      background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' fill='white' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M14 20L6 12L14 4L16 6L10 12L16 18L14 20Z'/%3E%3C/svg%3E%0A");
    }

    &-next::before {
      background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' fill='white' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 20L18 12L10 4L8 6L14 12L8 18L10 20Z'/%3E%3C/svg%3E%0A");
    }
  }

  .daypickr__calendar-header-cell {
    padding: space.get("small") 0;
    text-align: center;
  }

  .daypickr__day {
    position: relative;
    height: 32px;
    width: 100%;
    font-weight: bold;
    border: 2px solid transparent;

    &:hover {
      border-color: var(--color-surface-moderate);
    }

    &.isToday {
      color: var(--color-border-accent);

      &::after {
        content: "";
        position: absolute;
        width: 4px;
        height: 4px;
        background: var(--color-surface-tertiary);
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
      }
    }

    &.isSelected {
      background-color: var(--color-surface-tertiary);
      color: var(--color-text-default);

      &:hover {
        border-color: var(--color-border-accent);
      }

      &::after {
        background: var(--color-surface-contrast);
      }
    }

    &[aria-disabled="true"] {
      color: var(--color-text-disabled);
    }
  }

  .daypickr__button--close {
    position: absolute;
    opacity: 0;
    pointer-events: none;

    &:focus {
      position: relative;
      opacity: 1;
      pointer-events: initial;
    }
  }
}
