/*
 * Copyright (c) 2019-present Sonatype, Inc.
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License 2.0 which accompanies this
 * distribution and is available at https://www.eclipse.org/legal/epl-2.0/.
 */
@use "sass:math";

.nx-progress-bar {
  display: grid;
  grid-template-columns: 1fr;

  // In many of the layout modes, there will be two grid cells: one for the bar and one for the label.
  // However in some modes there is just the bar cell, and the location of the label cell (below or to the right)
  // varies. Therefore only the bar cell is actually in the template. The label cell, when needed, is generated
  // using grid auto-placement, controlled by the grid-auto-flow property
  grid-template-areas: 'bar';
  grid-auto-flow: row;

  gap: var(--nx-spacing-2x);
  justify-content: start;
  margin: var(--nx-spacing-6x) 0;
  width: min-content;

  &--inline-counter {
    grid-auto-flow: column;

    .nx-progress-bar__counter {
      margin: 0;
    }
  }

  &--inline {
    display: inline-grid;
    margin: 0 var(--nx-spacing-6x);
    vertical-align: middle;
  }

  &--success {
    color: var(--nx-color-progress-bar-text-success);

    .nx-progress-bar__counter {
      border-color: var(--nx-color-progress-bar-counter-border-success);
      background-color: var(--nx-color-background-success);
      color: var(--nx-color-progress-bar-counter-text-success);
    }
  }

  &--error {
    color: var(--nx-color-progress-bar-text-error);

    .nx-icon {
      color: var(--nx-color-progress-bar-icon-error);
    }

    .nx-progress-bar__counter {
      border-color: var(--nx-color-progress-bar-counter-border-error);
      background-color: var(--nx-color-background-error);
      color: var(--nx-color-progress-bar-counter-text-error);
    }
  }
}

.nx-progress-bar__counter {
  margin: 0 var(--nx-spacing-2x) 0 0;
}

.nx-progress-bar__counter-and-label {
  .nx-icon {
    margin: 0 0 0 var(--nx-spacing-2x);

    &:first-child {
      margin-left: 0;
    }
  }
}

.nx-progress-bar__label-text {
  margin-left: var(--nx-spacing-2x);

  &:first-child {
    margin-left: 0;
  }
}

.nx-progress-bar__step-container {
  display: flex;
  grid-area: bar;
  justify-content: space-evenly;
  width: 100%;
}

.nx-progress-bar__step {
  height: 100%;
  width: 2px;

  &--below-value {
    background-color: var(--nx-color-progress-background);
  }

  &--at-value {
    visibility: hidden;
  }

  &--above-value {
    background-color: var(--nx-color-progress-fill);
  }
}

$-normal-height: 25px;

.nx-progress-bar__progress {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  border: 0;
  grid-area: bar;
  height: $-normal-height;
  width: 100%;

  &,
  &::-webkit-progress-bar {
    background: var(--nx-color-progress-background);
    border-radius: math.div($-normal-height, 2);
    height: $-normal-height;
    overflow: hidden;
    width: 300px;
  }

  &::-moz-progress-bar {
    background: var(--nx-color-progress-fill);
  }

  &::-webkit-progress-value {
    background: var(--nx-color-progress-fill);
  }
}

.nx-progress-bar--small {
  .nx-progress-bar__progress,
  .nx-progress-bar__progress::-webkit-progress-bar {
    width: 100px;
  }
}

.nx-progress-bar--full {
  width: 100%;

  .nx-progress-bar__progress,
  .nx-progress-bar__progress::-webkit-progress-bar {
    min-width: 300px;
    width: 100%;
  }
}

.nx-progress-bar--inline {
  .nx-progress-bar__progress,
  .nx-progress-bar__progress::-webkit-progress-bar {
    $inline-height: 16px;
    height: $inline-height;
    border-radius: math.div($inline-height, 2);
    width: 150px;
  }
}
