//
// Copyright IBM Corp. 2016, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use '../button';
@use '../tooltip';
@use '../../config' as *;
@use '../../motion' as *;
@use '../../spacing' as *;
@use '../../theme' as *;
@use '../../type' as *;
@use '../../utilities/focus-outline' as *;
@use '../../utilities/convert';
@use '../../utilities/skeleton' as *;
@use '../../utilities/button-reset';
@use '../../utilities/component-reset';
@use '../../utilities/tooltip' as *;

/// @type Value
/// @access public
/// @group progress-indicator
$progress-indicator-bar-width: 1px inset transparent !default;

/// Progress indicator styles
/// @access public
/// @group progress-indicator
@mixin progress-indicator {
  .#{$prefix}--progress {
    @include component-reset.reset;

    display: flex;
    list-style: none;
  }

  .#{$prefix}--progress-step {
    position: relative;
    display: inline-flex;
    overflow: visible;
    flex-direction: row;
    inline-size: convert.to-rem(128px);
    min-inline-size: 7rem;

    .#{$prefix}--tooltip__label {
      display: block;
    }
  }

  .#{$prefix}--progress--space-equal .#{$prefix}--progress-step {
    flex-grow: 1;
    min-inline-size: 8rem;
  }

  .#{$prefix}--progress-line {
    position: absolute;
    border: $progress-indicator-bar-width;
    block-size: 2px;
    inline-size: convert.to-rem(128px);
    inset-inline-start: 0;
  }

  .#{$prefix}--progress--space-equal .#{$prefix}--progress-line {
    inline-size: 100%;
    min-inline-size: convert.to-rem(128px);
  }

  .#{$prefix}--progress-step svg {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    border-radius: 50%;
    block-size: $spacing-05;
    fill: $interactive;
    inline-size: $spacing-05;
    margin-block-start: convert.to-rem(10px);
    margin-inline-end: $spacing-03;
  }

  .#{$prefix}--progress--space-equal .#{$prefix}--progress-text {
    overflow: hidden;
    padding: $spacing-01;
    margin: -$spacing-01;
  }

  .#{$prefix}--progress-label {
    @include type-style('body-compact-01');

    display: block;
    overflow: hidden;
    margin: $spacing-03 0 0 0;
    color: $text-primary;
    line-height: 1.45;
    max-inline-size: convert.to-rem(88px);
    text-overflow: ellipsis;
    transition:
      box-shadow $duration-fast-02 motion(standard, productive),
      color $duration-fast-02 motion(standard, productive);
    white-space: nowrap;

    &::before {
      display: block;
      content: '';
    }
  }

  .#{$prefix}--progress-label:hover {
    box-shadow: 0 convert.to-rem(1px) $link-primary-hover;
    color: $link-primary-hover;
    cursor: pointer;
  }

  .#{$prefix}--progress--space-equal .#{$prefix}--progress-label {
    margin-inline-end: 0.75rem;
    max-inline-size: 100%;
  }

  .#{$prefix}--progress-step-button {
    &:focus {
      outline: none;
    }
    &:focus-visible .#{$prefix}--progress-label {
      color: $focus;
      outline: convert.to-rem(1px) solid $focus;
    }
  }

  .#{$prefix}--progress-step-button:not(
      .#{$prefix}--progress-step-button--unclickable
    )
    .#{$prefix}--progress-label:active {
    box-shadow: 0 convert.to-rem(1px) 0 0 $text-primary;
    color: $text-primary;
  }

  //OVERFLOW STYLING
  .#{$prefix}--progress-label-overflow:hover ~ .#{$prefix}--tooltip,
  .#{$prefix}--progress-label-overflow:focus ~ .#{$prefix}--tooltip {
    visibility: inherit;
  }

  .#{$prefix}--progress-step .#{$prefix}--tooltip .#{$prefix}--tooltip__caret {
    margin-inline-start: convert.to-rem(10px);
  }

  .#{$prefix}--tooltip__text {
    padding: 0;
    margin: 0;
    font-weight: normal;
  }

  //single line tooltip
  .#{$prefix}--progress-step .#{$prefix}--tooltip {
    @include type-style('body-01');

    display: block;
    padding: $spacing-03 $spacing-05;
    color: $text-inverse;
    inline-size: convert.to-rem(125px);
    margin-block-start: convert.to-rem(40px);
    margin-inline-start: convert.to-rem(22px);
    min-block-size: $spacing-06;

    min-inline-size: convert.to-rem(115px);
    visibility: hidden;
  }

  //multiline tooltip
  .#{$prefix}--progress-step .#{$prefix}--tooltip_multi {
    @include type-style('body-01');

    block-size: auto;
    color: $text-inverse;

    inline-size: convert.to-rem(150px);
  }

  //OPTIONAL HELPER TEXT STYLING
  .#{$prefix}--progress-optional {
    @include type-style('label-01');

    position: absolute;
    display: block;
    color: $text-secondary;
    inset-inline-start: 0;
    margin-block-start: convert.to-rem(28px);
    margin-inline-start: $spacing-06;
    text-align: start;
  }

  //CURRENT STYLING
  .#{$prefix}--progress-step--current {
    .#{$prefix}--progress-line {
      background-color: $interactive;
    }
  }

  //INCOMPLETE STYLING
  .#{$prefix}--progress-step--incomplete {
    svg {
      fill: $icon-primary;
    }

    .#{$prefix}--progress-line {
      background-color: $border-subtle;
    }
  }

  //COMPLETED STYLING
  .#{$prefix}--progress-step--complete {
    .#{$prefix}--progress-line {
      background-color: $interactive;
    }
  }

  //interactive button
  .#{$prefix}--progress-step-button {
    @include button-reset.reset;

    display: flex;
    text-align: start;
  }

  //unclickable button
  .#{$prefix}--progress-step-button--unclickable {
    cursor: default;
    outline: none;
  }

  .#{$prefix}--progress-step-button--unclickable
    .#{$prefix}--progress-label:hover {
    box-shadow: none;
    color: $text-primary;
    cursor: default;
  }

  .#{$prefix}--progress-step-button--unclickable
    .#{$prefix}--tooltip__label:hover {
    box-shadow: 0 convert.to-rem(1px) $link-primary;
    color: $link-primary;
    cursor: pointer;
  }

  //DISABLED STYLING
  .#{$prefix}--progress-step--disabled {
    cursor: not-allowed;
    pointer-events: none;

    svg {
      cursor: not-allowed;
      fill: $icon-disabled;
    }

    .#{$prefix}--progress-label,
    .#{$prefix}--progress-label:hover {
      box-shadow: none;
      color: $text-disabled;
      cursor: not-allowed;
    }

    .#{$prefix}--progress-line {
      cursor: not-allowed;
    }

    .#{$prefix}--progress-label-overflow:hover
      ~ .#{$prefix}--tooltip--definition
      .#{$prefix}--tooltip--definition__bottom {
      display: none;
    }
  }

  // ERROR STYLING
  .#{$prefix}--progress__warning > * {
    fill: $support-error;
  }

  // Skeleton State
  .#{$prefix}--progress.#{$prefix}--skeleton .#{$prefix}--progress-label {
    @include skeleton;

    block-size: convert.to-rem(14px);

    inline-size: convert.to-rem(40px);

    margin-block-start: 0.625rem;
  }

  .#{$prefix}--progress.#{$prefix}--progress--vertical.#{$prefix}--skeleton
    .#{$prefix}--progress-label {
    margin-block-start: 0.0625rem;
  }

  // Vertical Variant

  .#{$prefix}--progress--vertical {
    display: flex;
    flex-direction: column;
  }

  .#{$prefix}--progress--vertical,
  .#{$prefix}--progress-text {
    display: flex;
    flex-direction: column;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-step,
  .#{$prefix}--progress--vertical .#{$prefix}--progress-step-button {
    align-content: flex-start;
    inline-size: initial;
    min-block-size: 3.625rem;
    min-inline-size: initial;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-step svg,
  .#{$prefix}--progress--vertical .#{$prefix}--progress-step-button svg {
    display: inline-block;
    // 1px top margin based on visual review
    margin: convert.to-rem(1px) $spacing-03 0;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-label {
    display: inline-block;
    margin: 0;
    inline-size: initial;
    max-inline-size: convert.to-rem(160px);
    vertical-align: top;
    white-space: initial;
  }

  .#{$prefix}--progress--vertical
    .#{$prefix}--progress-step
    .#{$prefix}--tooltip {
    margin-block-start: 0.5rem;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-optional {
    position: static;
    margin: 0 0 auto;
    inline-size: 100%;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-line {
    position: absolute;
    block-size: 100%;
    inline-size: 1px;
    inset-block-start: 0;
    inset-inline-start: 0;
  }
}
