@use 'sass:math';

$ods-progress-bar-border-radius: var(--ods-semantic-size-radius-container);
$ods-progress-bar-inderterminate-percent-width: 30%;

@mixin ods-progress-bar() {
  --ods-progress-bar-border-radius: #{$ods-progress-bar-border-radius};

  appearance: none;
  position: relative;
  border: none;
  border-radius: var(--ods-progress-bar-border-radius);
  background-color: var(--ods-semantic-color-surface-track);
  width: 100%;
  height: 8px;

  &::-webkit-progress-bar {
    border-radius: var(--ods-progress-bar-border-radius);
    background-color: var(--ods-semantic-color-surface-track);
  }

  &::-webkit-progress-value {
    border-radius: var(--ods-progress-bar-border-radius);
    background-color: var(--ods-semantic-color-surface-control-solid);
  }

  &::-moz-progress-bar {
    border-radius: var(--ods-progress-bar-border-radius);
    background-color: var(--ods-semantic-color-surface-control-solid);
  }

  &:indeterminate {
    // Firefox
    &::-moz-progress-bar {
      animation: progress-indeterminate 1.5s infinite var(--ods-semantic-motion-easing);
      width: $ods-progress-bar-inderterminate-percent-width;
    }

    // Safari
    &::-webkit-progress-value {
      animation: progress-indeterminate 1.5s infinite var(--ods-semantic-motion-easing);
      width: $ods-progress-bar-inderterminate-percent-width;
    }

    // Chromium
    &::after {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      animation: progress-indeterminate 1.5s infinite var(--ods-semantic-motion-easing);
      border-radius: var(--ods-progress-bar-border-radius);
      background-color: var(--ods-semantic-color-surface-control-solid);
      width: $ods-progress-bar-inderterminate-percent-width;
      content: '';
    }
  }

  @keyframes progress-indeterminate {
    0%,
    5% {
      transform: translateX(0);
    }

    45%,
    55% {
      transform: translateX(math.percentage(math.div(100 - $ods-progress-bar-inderterminate-percent-width, $ods-progress-bar-inderterminate-percent-width)));
    }

    95%,
    100% {
      transform: translateX(0);
    }
  }
}
