@use 'sass:map';

@use '../mixins/mixins' as *;
@use '../mixins/var' as *;
@use '../common/var' as *;
@use '../common/transition' as *;

@include b(picker) {
  @include e(popper) {
    @include set-css-var-type('datepicker', 'border-color', $datepicker);
    @include picker-popper(
      getCssVar('bg-color', 'overlay'),
      1px solid getCssVar('datepicker', 'border-color'),
      getCssVar('box-shadow', 'light')
    );
  }
}

@include b(date-editor) {
  @include set-component-css-var('date-editor', $date-editor);
  @include set-component-css-var('input', $input);
  position: relative;
  display: inline-block;
  text-align: left;
  vertical-align: middle;

  &.#{$namespace}-input__wrapper {
    @include inset-input-border(
      var(
        #{getCssVarName('input-border-color')},
        map.get($input, 'border-color')
      )
    );

    &:hover {
      @include inset-input-border(#{getCssVar('input', 'hover-border-color')});
    }
  }

  &.#{$namespace}-input {
    height: getCssVar('component-size');
  }

  @each $size in (large, small) {
    &.#{$namespace}-input--#{$size} {
      height: getCssVar('component-size-#{$size}');
    }
  }

  @include m((monthrange)) {
    @include css-var-from-global(
      'date-editor-width',
      'date-editor-monthrange-width'
    );
  }

  @include m((daterange, timerange)) {
    @include css-var-from-global(
      'date-editor-width',
      'date-editor-daterange-width'
    );
  }

  @include m(datetimerange) {
    @include css-var-from-global(
      'date-editor-width',
      'date-editor-datetimerange-width'
    );
  }

  @include m(dates) {
    .#{$namespace}-input__wrapper {
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .close-icon {
    cursor: pointer;
  }

  .clear-icon {
    cursor: pointer;

    &:hover {
      color: getCssVar('text-color', 'secondary');
    }
  }

  .#{$namespace}-range__icon {
    height: inherit;
    line-height: inherit;
    font-size: 14px;
    color: getCssVar('text-color', 'placeholder');
  }

  .#{$namespace}-range-input {
    appearance: none;
    border: none;
    outline: none;
    display: inline-block;
    height: 100%;
    margin: 0;
    padding: 0;
    width: calc(50% - 26px);
    text-align: center;
    font-size: getCssVar('font-size', 'base');
    color: getCssVar('text-color', 'regular');
    background-color: transparent;

    &::placeholder {
      color: getCssVar('text-color', 'placeholder');
    }
  }

  .#{$namespace}-range-separator {
    display: inline-flex;
    align-content: center;
    justify-content: center;
    font-size: 14px;
    width: 24px;
    word-break: keep-all;
    color: getCssVar('text-color', 'primary');
  }

  .#{$namespace}-range__close-icon {
    font-size: 14px;
    color: getCssVar('text-color', 'placeholder');
    height: inherit;
    width: unset;
    cursor: pointer;

    &:hover {
      color: getCssVar('text-color', 'secondary');
    }

    svg {
      vertical-align: middle;
    }

    &--hidden {
      opacity: 0;
      visibility: hidden;
    }
  }
}

@include b(range-editor) {
  font-size: 0;
  & > * {
    vertical-align: middle;
  }

  &.#{$namespace}-input__wrapper {
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
  }

  .#{$namespace}-range-input {
    line-height: 1;
  }

  @include when(active) {
    @include inset-input-border(#{getCssVar('input', 'focus-border-color')});
    &:hover {
      @include inset-input-border(#{getCssVar('input', 'focus-border-color')});
    }
  }

  @each $size in (large, small) {
    @include m($size) {
      line-height: getCssVar('component-size', $size);
      height: getCssVar('component-size', $size);

      &.#{$namespace}-input__wrapper {
        height: getCssVar('component-size', $size);
      }

      .#{$namespace}-range-separator {
        line-height: map.get($input-line-height, $size);
        font-size: map.get($input-font-size, $size);
      }

      .#{$namespace}-range-input {
        font-size: map.get($input-font-size, $size);
      }
    }
  }

  @include when(disabled) {
    background-color: map.get($input-disabled, 'fill');
    border-color: map.get($input-disabled, 'border');
    color: map.get($input-disabled, 'text-color');
    cursor: not-allowed;

    &:hover,
    &:focus {
      border-color: map.get($input-disabled, 'border');
    }

    input {
      background-color: map.get($input-disabled, 'fill');
      color: map.get($input-disabled, 'text-color');
      cursor: not-allowed;
      &::placeholder {
        color: map.get($input-disabled, 'placeholder-color');
      }
    }

    .#{$namespace}-range-separator {
      color: map.get($input-disabled, 'text-color');
    }
  }
}
