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

@import '../../globals/scss/vars';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/css--reset';
@import '../../globals/scss/typography';
@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';

@mixin progress-indicator {
  .#{$prefix}--progress {
    @include reset;
    @include font-family;
    display: flex;
    list-style: none;
  }

  .#{$prefix}--progress-step {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    flex: 1;
    min-width: 7rem;
    transition: $transition--base all $carbon--standard-easing;
    overflow: visible;

    &:first-child .#{$prefix}--progress-line {
      display: none;
    }
  }

  .#{$prefix}--progress-line {
    position: absolute;
    top: $progress-indicator-line-offset;
    right: 100%;
    height: 1px;
    width: calc(100% - 24px);
    border: $progress-indicator-bar-width;
  }

  .#{$prefix}--progress-step svg {
    position: relative;
    z-index: 1;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    margin-bottom: $spacing-xs;
    fill: $brand-01;
  }

  .#{$prefix}--progress-label {
    line-height: 1;
    width: 75%;
  }

  //interactive button
  .#{$prefix}--progress-step-button {
    display: inline-flex;
    flex-flow: column nowrap;
  }

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

  .#{$prefix}--progress-step--current {
    circle:first-child {
      stroke: $brand-01;
      stroke-width: $progress-indicator-stroke-width;
      fill: transparent;
    }

    .#{$prefix}--progress-label {
      @include font-smoothing;
      color: $brand-01;
      font-weight: 600;
    }
    .#{$prefix}--progress-line {
      background-color: $brand-01;
    }
  }

  .#{$prefix}--progress-step--incomplete {
    circle {
      stroke: $ui-04;
      stroke-width: $progress-indicator-stroke-width;
      fill: transparent;
    }

    .#{$prefix}--progress-label {
      color: $text-02;
    }

    .#{$prefix}--progress-line {
      background-color: $ui-04;
    }
  }

  .#{$prefix}--progress-step--complete {
    circle {
      stroke: $brand-01;
      stroke-width: $progress-indicator-stroke-width;
      fill: transparent;
    }

    polygon {
      fill: $brand-01;
    }

    .#{$prefix}--progress-label {
      @include font-smoothing;
      color: $brand-01;
      font-weight: 600;
    }
    .#{$prefix}--progress-line {
      background-color: $brand-01;
    }
  }

  // Skeleton State
  .#{$prefix}--progress.#{$prefix}--skeleton .#{$prefix}--progress-label {
    @include skeleton;
    height: rem(12px);
    width: rem(40px);
  }

  // Vertical variant
  .#{$prefix}--progress--vertical {
    display: block;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-step {
    display: list-item;
    min-height: 6rem;

    svg {
      display: inline-block;
    }
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-label {
    display: inline-block;
    width: auto;
    vertical-align: top;
    margin-top: 0.26rem;
    margin-left: 0.5rem;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-line {
    top: 22px;
    left: 0.69rem;
    height: calc(100% - 22px);
    width: 1px;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-step:first-child .#{$prefix}--progress-line {
    display: block;
  }
  .#{$prefix}--progress--vertical .#{$prefix}--progress-step:last-child .#{$prefix}--progress-line {
    display: none;
  }
}

@mixin progress-indicator--x {
  .#{$prefix}--progress {
    @include reset;
    display: flex;
    list-style: none;
  }

  .#{$prefix}--progress-step {
    position: relative;
    display: inline-flex;
    flex-direction: row;
    flex: 1;
    min-width: 7rem;
    width: rem(128px);
    transition: $duration--fast-02 all motion(standard, productive);
    overflow: visible;

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

  .#{$prefix}--progress-line {
    position: absolute;
    height: 1px;
    width: rem(128px);
    border: $progress-indicator-bar-width;
  }

  .#{$prefix}--progress-step svg {
    position: relative;
    z-index: 1;
    width: $carbon--spacing-05;
    height: $carbon--spacing-05;
    border-radius: 50%;
    margin: 9px $carbon--spacing-03 0 0;
    fill: $interactive-01;
  }

  .#{$prefix}--progress-label {
    line-height: 1.45;
    max-width: rem(88px);
    margin: $carbon--spacing-03 0 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    @include type-style('body-short-01');
    transition: box-shadow $transition--base $carbon--standard-easing;

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

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

  .#{$prefix}--progress-label:focus {
    outline: none;
    color: $link-01;
    box-shadow: 0 rem(3px) 0 0 $link-01;
    transition: box-shadow 0.05s $carbon--standard-easing;
  }

  .#{$prefix}--progress-label:active {
    color: $interactive-01;
    box-shadow: 0 rem(3px) 0 0 $interactive-01;
  }

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

  .#{$prefix}--progress-step .#{$prefix}--tooltip .#{$prefix}--tooltip__caret {
    margin-left: rem(10px);
  }

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

  //single line tooltip
  .#{$prefix}--progress-step .#{$prefix}--tooltip {
    min-width: rem(115px);
    width: rem(125px);
    min-height: $carbon--spacing-06;
    margin-left: rem(22px);
    margin-top: rem(40px);
    padding: $carbon--spacing-03 $carbon--spacing-05;
    display: block;
    visibility: hidden;
    @include type-style('body-long-01');
    color: $inverse-01;
  }

  //multiline tooltip
  .#{$prefix}--progress-step .#{$prefix}--tooltip_multi {
    width: rem(150px);
    height: auto;
    @include type-style('body-long-01');
    color: $inverse-01;
  }

  //OPTIONAL HELPER TEXT STYLING
  .#{$prefix}--progress-optional {
    position: absolute;
    margin-left: $carbon--spacing-06;
    margin-top: rem(28px);
    @include type-style('label-01');
    color: $text-01;
  }

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

  .#{$prefix}--progress-step--current svg {
    width: 14px;
    height: 14px;
    fill: $interactive-01;
    margin-top: rem(9.5px);
  }

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

    .#{$prefix}--progress-line {
      background-color: $ui-03;
    }
  }

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

  //interactive button
  .#{$prefix}--progress-step-button {
    display: flex;
  }

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

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

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

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

    .#{$prefix}--progress-label:focus,
    .#{$prefix}--progress-label:active {
      outline: none;
      box-shadow: none;
    }

    .#{$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 > path {
    fill: $support-01;
  }

  // Skeleton State
  .#{$prefix}--progress.#{$prefix}--skeleton .#{$prefix}--progress-label {
    @include skeleton;
    height: rem(12px);
    width: rem(40px);
  }

  .#{$prefix}--progress--vertical {
    display: block;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-step {
    display: list-item;
    min-height: 6rem;
    width: initial;
    min-width: initial;

    svg {
      display: inline-block;
      margin: 0.1rem 0.5rem;
    }
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-step--current svg {
    margin-left: 0.563rem;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-label {
    display: inline-block;
    width: initial;
    max-width: none;
    vertical-align: top;
    margin: 0;
  }

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

  .#{$prefix}--progress--vertical .#{$prefix}--progress-optional {
    margin-top: initial;
    position: initial;
    margin-left: 2.25rem;
  }

  .#{$prefix}--progress--vertical .#{$prefix}--progress-line {
    top: 0;
    left: 0;
    height: 100%;
    width: 1px;
  }
}

@include exports('progress-indicator') {
  @if feature-flag-enabled('components-x') {
    @include progress-indicator--x;
  } @else {
    @include progress-indicator;
  }
}
