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

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

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

  &--sm {
    .ui-time-picker__container {
      min-height: $semantic-sizing-input-height-sm;
    }

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

    .ui-time-picker__label {
      font-size: $semantic-typography-font-size-sm;
      margin-bottom: $semantic-spacing-component-xs;
    }
  }

  &--md {
    .ui-time-picker__container {
      min-height: $semantic-sizing-input-height-md;
    }

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

    .ui-time-picker__label {
      font-size: $semantic-typography-font-size-md;
      margin-bottom: $semantic-spacing-component-sm;
    }
  }

  &--lg {
    .ui-time-picker__container {
      min-height: $semantic-sizing-input-height-lg;
    }

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

    .ui-time-picker__label {
      font-size: $semantic-typography-font-size-lg;
      margin-bottom: $semantic-spacing-component-sm;
    }
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  &--open {
    .ui-time-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-time-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-time-picker--disabled &) {
      border-color: $semantic-color-border-secondary;
    }

    &--has-clear {
      .ui-time-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;
    }
  }

  // ==========================================================================
  // TIME PICKER 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: 320px;
  }

  &__time-display {
    margin-bottom: $semantic-spacing-component-md;
  }

  &__time-sections {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: $semantic-spacing-component-sm;
  }

  &__time-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: $semantic-spacing-component-xs;
  }

  &__time-btn {
    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-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;
    }
  }

  &__time-input {
    width: 60px;
    padding: $semantic-spacing-component-xs $semantic-spacing-component-sm;
    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: 1.125rem;
    font-weight: $semantic-typography-font-weight-medium;
    text-align: center;
    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;
    }
  }

  &__time-label {
    font-size: $semantic-typography-font-size-xs;
    color: $semantic-color-text-secondary;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  &__separator {
    font-size: $semantic-typography-font-size-xl;
    font-weight: $semantic-typography-font-weight-bold;
    color: $semantic-color-text-primary;
    margin: 0 $semantic-spacing-component-xs;
    align-self: center;
    margin-top: -20px; // Adjust to center with inputs
  }

  &__ampm-section {
    display: flex;
    flex-direction: column;
    gap: $semantic-spacing-component-xs;
    margin-left: $semantic-spacing-component-md;
  }

  &__ampm-btn {
    padding: $semantic-spacing-component-xs $semantic-spacing-component-sm;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    border-radius: $semantic-border-radius-sm;
    background: $semantic-color-surface-primary;
    color: $semantic-color-text-secondary;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: $semantic-typography-font-weight-medium;
    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;
    }

    &--active {
      background: $semantic-color-primary;
      color: $semantic-color-on-primary;
      border-color: $semantic-color-primary;

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

  // ==========================================================================
  // PRESET TIMES
  // ==========================================================================

  &__presets {
    border-top: $semantic-border-width-1 solid $semantic-color-border-subtle;
    padding-top: $semantic-spacing-component-md;
    margin-bottom: $semantic-spacing-component-md;
  }

  &__presets-title {
    font-size: $semantic-typography-font-size-sm;
    font-weight: $semantic-typography-font-weight-medium;
    color: $semantic-color-text-secondary;
    margin-bottom: $semantic-spacing-component-sm;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  &__presets-list {
    display: flex;
    flex-wrap: wrap;
    gap: $semantic-spacing-component-xs;
  }

  &__preset-btn {
    padding: $semantic-spacing-component-xs $semantic-spacing-component-sm;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    border-radius: $semantic-border-radius-sm;
    background: $semantic-color-surface-primary;
    color: $semantic-color-text-secondary;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease-in-out;

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

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

  // ==========================================================================
  // ACTIONS
  // ==========================================================================

  &__actions {
    display: flex;
    justify-content: flex-end;
    gap: $semantic-spacing-component-sm;
    border-top: $semantic-border-width-1 solid $semantic-color-border-subtle;
    padding-top: $semantic-spacing-component-md;
  }

  &__action-btn {
    padding: $semantic-spacing-component-sm $semantic-spacing-component-md;
    border-radius: $semantic-border-radius-md;
    font-size: 0.875rem;
    font-weight: $semantic-typography-font-weight-medium;
    cursor: pointer;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease-in-out;
    min-width: 80px;

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

    &--primary {
      background: $semantic-color-primary;
      color: $semantic-color-on-primary;
      border: $semantic-border-width-1 solid $semantic-color-primary;

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

      &:active {
        background: $semantic-color-primary-pressed;
        border-color: $semantic-color-primary-pressed;
      }
    }

    &--secondary {
      background: transparent;
      color: $semantic-color-text-secondary;
      border: $semantic-border-width-1 solid $semantic-color-border-primary;

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

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

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

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

    &__time-sections {
      flex-direction: column;
      gap: $semantic-spacing-component-md;
    }

    &__separator {
      display: none;
    }

    &__ampm-section {
      flex-direction: row;
      margin-left: 0;
    }
  }
}