@use "../../../../styles/tools/generate";
@use "../../../../styles/tokens/space";
@use "../../../../styles/tools/convert";
@use "../../../../styles/tokens/color";
@use "../../../../styles/tokens/base";

@layer components {
  .input-stepper {
    display: flex;
    flex-direction: row;
    align-items: center;
    &__field {
      width: convert.to-rem(40px);
      appearance: textfield;
      z-index: 0;
      border-radius: 0;
      padding: space.get("xsmall");
      text-align: center;
      border-left: 0;
      border-right: 0;

      &::-webkit-inner-spin-button,
      &::-webkit-outer-spin-button {
        appearance: none;
      }
      &:disabled {
        color: var(--color-text-disabled) !important;
        -webkit-text-fill-color: var(--color-text-disabled) !important;
        background-color: var(--color-fill-primary);
      }
    }
    &__number {
      display: block;
      font-weight: bold;
      appearance: textfield;
      width: convert.to-rem(40px);
      height: convert.to-rem(40px);
      z-index: 0;
      padding: space.get("xsmall") space.get("xsmall") convert.to-rem(8px)
        space.get("xsmall");
      text-align: center;
      border: 2px solid var(--color-border-strong);
      border-left: 0;
      border-right: 0;
      margin-bottom: 0;
      line-height: 1.5;
      background-color: var(--color-fill-primary);
    }
    &__button {
      position: relative;
      z-index: 0;
      height: 40px;
      width: 40px;
      border-top: 2px solid;
      border-bottom: 2px solid;
      border-color: var(--color-border-strong);

      &::before {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 100%;
        height: 100%;
      }
    }

    &__button--minus {
      border-left: 2px solid var(--color-border-strong);
      border-top-left-radius: convert.to-rem(5px);
      border-bottom-left-radius: convert.to-rem(5px);
      background-color: var(--color-fill-primary);

      &::before {
        background-color: var(--color-text-default);
        mask: url('data:image/svg+xml,<svg width="38" height="36" viewBox="0 0 38 36" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M11 17V19H25V17H11Z"/></svg>');
        mask-size: cover;
        mask-repeat: no-repeat;
        mask-position: center center;
        -webkit-mask: url('data:image/svg+xml,<svg width="38" height="36" viewBox="0 0 38 36" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M11 17V19H25V17H11Z"/></svg>');
        -webkit-mask-size: cover;
        -webkit-mask-repeat: no-repeat;
        -webkit-mask-position: center center;
      }
    }

    &__button--plus {
      border-right: 2px solid var(--color-border-strong);
      border-top-right-radius: convert.to-rem(5px);
      border-bottom-right-radius: convert.to-rem(5px);
      background-color: var(--color-fill-primary);

      &::before {
        background-color: var(--color-text-default);
        mask: url('data:image/svg+xml,<svg width="38" height="36" viewBox="0 0 38 36" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M19 11H21V17H27V19H21V25H19V19H13V17H19V11Z"/></svg>');
        mask-size: cover;
        mask-repeat: no-repeat;
        mask-position: center center;
        -webkit-mask: url('data:image/svg+xml,<svg width="38" height="36" viewBox="0 0 38 36" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M19 11H21V17H27V19H21V25H19V19H13V17H19V11Z"/></svg>');
        -webkit-mask-size: cover;
        -webkit-mask-repeat: no-repeat;
        -webkit-mask-position: center center;
      }
    }

    &__button:focus {
      z-index: 1;
    }

    &--invalid {
      .input-stepper__button,
      .input-stepper__number,
      .input-stepper__button--minus:active:not(:disabled),
      .input-stepper__button--plus:active:not(:disabled) {
        border-color: var(--color-border-negative);
      }

      @media (hover: hover) and (pointer: fine) {
        .input-stepper__button--minus:hover:not(:disabled),
        .input-stepper__button--plus:hover:not(:disabled) {
          border-color: var(--color-border-negative);
        }
      }
    }

    &__button--minus:disabled,
    &__button--plus:disabled {
      &::before {
        background-color: var(--color-border-strong);
      }
    }

    @media (hover: hover) and (pointer: fine) {
      &__button--minus:hover:not(:disabled),
      &__button--plus:hover:not(:disabled) {
        background-color: var(--color-fill-contrast);
        border-color: var(--color-fill-contrast);

        &::before {
          background-color: var(--color-fill-primary);
        }
      }
    }

    &__button--minus:active:not(:disabled),
    &__button--plus:active:not(:disabled) {
      background-color: var(--color-fill-tertiary);
      border-color: var(--color-border-accent);

      &::before {
        background-color: color.$white;
      }
    }
  }
}
