@use 'ui-design-system/src/styles/semantic/index' as *;

.ui-date-picker {
  display: flex;
  flex-direction: column;
  width: 100%;
  position: relative;

  // ==========================================================================
  // SIZE VARIANTS
  // ==========================================================================

  &--sm {
    .ui-date-picker__container {
      min-height: 36px;
    }

    .ui-date-picker__field {
      font-size: 0.875rem;
      padding: $semantic-spacing-component-xs $semantic-spacing-component-sm;
    }

    .ui-date-picker__label {
      font-size: 0.8125rem;
      margin-bottom: $semantic-spacing-component-xs;
    }
  }

  &--md {
    .ui-date-picker__container {
      min-height: 48px;
    }

    .ui-date-picker__field {
      font-size: 1rem;
      padding: $semantic-spacing-component-sm $semantic-spacing-component-md;
    }

    .ui-date-picker__label {
      font-size: 0.875rem;
      margin-bottom: $semantic-spacing-component-sm;
    }
  }

  &--lg {
    .ui-date-picker__container {
      min-height: 56px;
    }

    .ui-date-picker__field {
      font-size: 1.125rem;
      padding: $semantic-spacing-component-md $semantic-spacing-component-lg;
    }

    .ui-date-picker__label {
      font-size: 1rem;
      margin-bottom: $semantic-spacing-component-sm;
    }
  }

  // ==========================================================================
  // VARIANT STYLES
  // ==========================================================================

  &--outlined {
    .ui-date-picker__container {
      border: $semantic-border-width-2 solid $semantic-color-border-primary;
      border-radius: $semantic-border-radius-md;
      background-color: $semantic-color-surface-primary;
    }

    .ui-date-picker__field {
      border: none;
      background: transparent;
    }
  }

  &--filled {
    .ui-date-picker__container {
      background-color: $semantic-color-surface-secondary;
      border: $semantic-border-width-2 solid transparent;
      border-radius: $semantic-border-radius-md;
      border-bottom: 3px solid $semantic-color-border-primary;
    }

    .ui-date-picker__field {
      border: none;
      background: transparent;
    }
  }

  &--underlined {
    .ui-date-picker__container {
      background: transparent;
      border: none;
      border-bottom: $semantic-border-width-2 solid $semantic-color-border-primary;
      border-radius: 0;
    }

    .ui-date-picker__field {
      border: none;
      background: transparent;
    }
  }

  // ==========================================================================
  // STATE VARIANTS
  // ==========================================================================

  &--error {
    .ui-date-picker__container {
      border-color: $semantic-color-error;
    }

    .ui-date-picker__label {
      color: $semantic-color-error;
    }
  }

  &--success {
    .ui-date-picker__container {
      border-color: $semantic-color-success;
    }
  }

  &--warning {
    .ui-date-picker__container {
      border-color: $semantic-color-warning;
    }
  }

  &--disabled {
    opacity: 0.6;
    pointer-events: none;

    .ui-date-picker__container {
      background: $semantic-color-surface-secondary;
      cursor: not-allowed;
    }
  }

  &--open {
    .ui-date-picker__container {
      border-color: $semantic-color-primary;
      box-shadow: $semantic-shadow-input-focus;
    }
  }

  // ==========================================================================
  // COMPONENT ELEMENTS
  // ==========================================================================

  &__label {
    font-weight: $semantic-typography-font-weight-medium;
    color: $semantic-color-text-primary;
    line-height: $semantic-typography-line-height-tight;

    &--required {
      .ui-date-picker__required-indicator {
        color: $semantic-color-error;
        margin-left: $semantic-spacing-component-xs;
      }
    }
  }

  &__container {
    display: flex;
    align-items: center;
    position: relative;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease-in-out;
    cursor: pointer;

    &:hover:not(.ui-date-picker--disabled &) {
      border-color: $semantic-color-border-secondary;
    }

    &--has-clear {
      .ui-date-picker__field {
        padding-right: $semantic-spacing-component-xl;
      }
    }
  }

  &__prefix-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: $semantic-spacing-component-sm;
    color: $semantic-color-text-tertiary;
    pointer-events: none;
  }

  &__field {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: $semantic-color-text-primary;
    cursor: pointer;
    font-family: inherit;

    &::placeholder {
      color: $semantic-color-text-tertiary;
    }

    &:focus {
      outline: none;
    }
  }

  &__clear-btn {
    position: absolute;
    right: $semantic-spacing-component-sm;
    display: flex;
    align-items: center;
    justify-content: center;
    width: $semantic-sizing-icon-button;
    height: $semantic-sizing-icon-button;
    border: none;
    background: transparent;
    color: $semantic-color-text-tertiary;
    cursor: pointer;
    border-radius: $semantic-border-radius-sm;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease-in-out;

    &:hover {
      background: $semantic-color-surface-secondary;
      color: $semantic-color-text-secondary;
    }

    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
  }

  &__helper-text {
    font-size: $semantic-typography-font-size-sm;
    margin-top: $semantic-spacing-component-xs;
    line-height: $semantic-typography-line-height-normal;

    &--error {
      color: $semantic-color-error;
    }

    &--success {
      color: $semantic-color-success;
    }

    &--warning {
      color: $semantic-color-warning;
    }

    &--default {
      color: $semantic-color-text-secondary;
    }
  }

  // ==========================================================================
  // CALENDAR DROPDOWN
  // ==========================================================================

  &__dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    margin-top: $semantic-spacing-component-xs;
    background: $semantic-color-surface-primary;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    border-radius: $semantic-border-radius-lg;
    box-shadow: $semantic-shadow-dropdown;
    padding: $semantic-spacing-component-md;
    min-width: 280px;
  }

  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: $semantic-spacing-component-md;
  }

  &__nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: $semantic-sizing-icon-navigation;
    height: $semantic-sizing-icon-navigation;
    border: none;
    background: transparent;
    color: $semantic-color-text-secondary;
    cursor: pointer;
    border-radius: $semantic-border-radius-sm;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease-in-out;

    &:hover {
      background: $semantic-color-surface-secondary;
      color: $semantic-color-text-primary;
    }

    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
  }

  &__month-year {
    flex: 1;
    text-align: center;
  }

  &__month-btn {
    border: none;
    background: transparent;
    color: $semantic-color-text-primary;
    font-size: 1rem;
    font-weight: $semantic-typography-font-weight-medium;
    cursor: pointer;
    padding: $semantic-spacing-component-xs $semantic-spacing-component-sm;
    border-radius: $semantic-border-radius-sm;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease-in-out;

    &:hover {
      background: $semantic-color-surface-secondary;
    }

    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
  }

  &__calendar {
    width: 100%;
  }

  &__day-headers {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: $semantic-spacing-component-xs;
    margin-bottom: $semantic-spacing-component-sm;
  }

  &__day-header {
    text-align: center;
    font-size: $semantic-typography-font-size-sm;
    font-weight: $semantic-typography-font-weight-medium;
    color: $semantic-color-text-secondary;
    padding: $semantic-spacing-component-xs;
  }

  &__days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: $semantic-spacing-component-xs;
  }

  &__day {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: $semantic-color-text-primary;
    cursor: pointer;
    border-radius: $semantic-border-radius-sm;
    font-size: 0.875rem;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease-in-out;

    &:hover:not(&--disabled) {
      background: $semantic-color-surface-secondary;
    }

    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }

    &--today {
      background: $semantic-color-primary-container;
      color: $semantic-color-primary;
      font-weight: $semantic-typography-font-weight-medium;
    }

    &--selected {
      background: $semantic-color-primary;
      color: $semantic-color-on-primary;
      font-weight: $semantic-typography-font-weight-medium;

      &:hover {
        background: $semantic-color-primary-focus;
      }
    }

    &--other-month {
      color: $semantic-color-text-tertiary;
    }

    &--disabled {
      color: $semantic-color-text-disabled;
      cursor: not-allowed;
      opacity: 0.5;
    }
  }

  // ==========================================================================
  // MONTH/YEAR PICKER
  // ==========================================================================

  &__month-year-picker {
    display: flex;
    flex-direction: column;
    gap: $semantic-spacing-component-md;
  }

  &__months {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: $semantic-spacing-component-xs;
  }

  &__month-option {
    padding: $semantic-spacing-component-sm;
    border: none;
    background: transparent;
    color: $semantic-color-text-primary;
    cursor: pointer;
    border-radius: $semantic-border-radius-sm;
    font-size: 0.875rem;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease-in-out;

    &:hover {
      background: $semantic-color-surface-secondary;
    }

    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }

    &--selected {
      background: $semantic-color-primary;
      color: $semantic-color-on-primary;
      font-weight: $semantic-typography-font-weight-medium;

      &:hover {
        background: $semantic-color-primary-focus;
      }
    }
  }

  &__year-input {
    display: flex;
    justify-content: center;
  }

  &__year-field {
    padding: $semantic-spacing-component-sm $semantic-spacing-component-md;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    border-radius: $semantic-border-radius-md;
    background: $semantic-color-surface-primary;
    color: $semantic-color-text-primary;
    font-size: 1rem;
    text-align: center;
    width: 80px;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease-in-out;

    &:focus {
      outline: none;
      border-color: $semantic-color-primary;
      box-shadow: $semantic-shadow-input-focus;
    }

    &::-webkit-outer-spin-button,
    &::-webkit-inner-spin-button {
      -webkit-appearance: none;
      margin: 0;
    }

    &[type=number] {
      -moz-appearance: textfield;
    }
  }

  // ==========================================================================
  // RESPONSIVE DESIGN
  // ==========================================================================

  @media (max-width: 768px) {
    &__dropdown {
      position: fixed;
      top: 50%;
      left: 50%;
      right: auto;
      transform: translate(-50%, -50%);
      width: 90vw;
      max-width: 320px;
    }
  }
}