// Breadcrumbs: https://getbootstrap.com/docs/5.3/components/breadcrumb/#sass-variables
@use "../../../css/mixins" as m;
// Define shared variables
$expander-icon-color: $qld-light-link;

// Breadcrumb component styles
.breadcrumb {
  // Shared CSS custom properties
  --#{$prefix}breadcrumb-divider: var(--qgds-icon-chevron-right);
  --#{$prefix}breadcrumb-expander: var(--qgds-icon-more-horizontal);
  --#{$prefix}breadcrumb-item-active-color: var(--#{$prefix}dark-grey-muted);
  --#{$prefix}breadcrumb-divider-color: var(--#{$prefix}light-action-secondary);
  --#{$prefix}breadcrumb-expander-color: var(
    --#{$prefix}light-action-secondary
  );
  --#{$prefix}breadcrumb-item-padding-x: 0;
  --#{$prefix}breadcrumb-bg: transparent;
  --#{$prefix}breadcrumb-margin-bottom: 0;
  --#{$prefix}breadcrumb-padding-y: 2rem;
  --#{$prefix}breadcrumb-link-color: var(--#{$prefix}light-link);
  --#{$prefix}breadcrumb-link-text-decoration-color: var(
    --#{$prefix}light-link
  );
  --#{$prefix}breadcrumb-link-text-decoration-color-hover: var(
    --#{$prefix}light-link
  );
  display: inline-flex;
  width: auto;
  max-width: 100%;
  flex-wrap: nowrap;
  // Dark mode overrides
  .dark &,
  .dark-alt & {
    --#{$prefix}breadcrumb-item-active-color: var(
      --#{$prefix}color-default-color-dark-text-lighter
    );
    --#{$prefix}breadcrumb-divider-color: var(
      --#{$prefix}dark-action-secondary
    );
    --#{$prefix}breadcrumb-link-color: var(--#{$prefix}dark-link);
    --#{$prefix}breadcrumb-link-text-decoration-color: var(
      --#{$prefix}dark-link
    );
    --#{$prefix}breadcrumb-link-text-decoration-color-hover: var(
      --#{$prefix}dark-link
    );
    .breadcrumb-vertical > li > a {
      --#{$prefix}breadcrumb-link-color: var(--#{$prefix}light-link);
    }
  }

  .expanded {
    .breadcrumb-collapse-wrapper {
      max-height: 100%;
      --#{$prefix}dropdown-box-shadow:
        0px 1px 2px rgba(0, 0, 0, 0.3), 0px 2px 6px 2px rgba(0, 0, 0, 0.15); // level 2 shadow
      box-shadow: var(--#{$prefix}dropdown-box-shadow);
      pointer-events: all;
      transition: max-height 0.5s ease-in;
      z-index: 1;
    }
  }

  .breadcrumb-vertical > li {
    list-style: none;
    width: 100%;
    &:after {
      display: none;
    }

    a {
      text-decoration: none;
      padding: 0.75rem 1rem;
      display: block;
      width: 100%;
      color: $qld-text-grey;
      white-space: nowrap; /* Prevents text from wrapping to the next line */
      overflow: hidden; /* Hides any content that overflows the element's box */
      text-overflow: ellipsis;
      margin: 0;
      &:hover {
        text-decoration: underline;
        color: $qld-light-link;
        text-decoration-thickness: var(
          --#{$prefix}link-underline-thickness-hover
        );
        background-color: $core-default-color-neutral-lighter;
      }

      --qld-focus-color: var(--qld-light-focus);
      @include m.focusable($offsetOutline: -6px);
    }
  }
  .breadcrumb-collapse-wrapper {
    position: absolute;
    margin-top: 1rem;
    max-height: 0;
    overflow: hidden;
    pointer-events: none;
    width: 360px;
    border-radius: 4px;
    transition: max-height 0.5s ease-out;
  }
  .breadcrumb-vertical {
    padding: 0;
    background-color: $core-default-color-neutral-lightest;
    border-bottom: 4px solid $qld-brand-secondary;
  }
}

// Breadcrumb items
.breadcrumb-item {
  font-size: 0.875rem;
  line-height: 2rem;
  display: none;
  white-space: nowrap;

  &:not(:first-child) a {
    margin-left: 5px;
  }

  &:nth-last-child(2) {
    text-overflow: ellipsis;
    overflow-x: hidden;
    white-space: nowrap;

    //Handle outline offset when focused
    &:focus-within {
      overflow: initial;
    }
  }

  &:first-child {
    flex-shrink: 0;
  }

  a {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    &:focus {
      overflow: initial;
    }
  }
  // Override Bootstrap's default :before pseudo element
  &:before {
    display: none;
  }

  // Divider
  &:after {
    content: "";
    display: inline-block;
    width: 1rem;
    height: 1rem;
    mask-image: var(--#{$prefix}breadcrumb-divider);
    mask-size: 1rem 1rem;
    mask-repeat: no-repeat;
    mask-position: center center;
    background-color: var(--#{$prefix}breadcrumb-divider-color);
    position: relative;
    top: 4px;
  }

  &:last-child:after {
    display: none;
  }

  // Breadcrumb link
  a,
  a:visited,
  a:hover {
    color: var(--#{$prefix}breadcrumb-link-color);
    text-decoration-color: var(
      --#{$prefix}breadcrumb-link-text-decoration-color
    );
  }

  a {
    @include m.focusable($offsetOutline: 3px);
  }
}

.breadcrumb-toggle {
  @include m.unset-button-styles();
  flex-shrink: 0;

  > button {
    display: inline-block;
    width: 2rem;
    height: 2rem;
    line-height: 1.5rem;
    outline: none;
    border: 0;
    background-color: transparent;
    border-radius: 4px;
    padding: 0;
    vertical-align: middle;
    &:after {
      display: block;
      width: 100%;
      height: 100%;
      content: " ";
      mask-image: var(--#{$prefix}breadcrumb-expander);
      background-color: var(--#{$prefix}breadcrumb-link-color);
      mask-size: 1.5rem 1.5rem;
      mask-repeat: no-repeat;
      mask-position: center center;
    }

    &:hover,
    &:focus {
      background-color: rgba($core-default-color-neutral-black, 0.1);
    }

    @include m.focusable($offsetOutline: 3px);
  }
}

// Responsive styles
@include media-breakpoint-down(lg) {
  .breadcrumb {
    --#{$prefix}breadcrumb-padding-y: 1rem;
  }

  .breadcrumb-item {
    max-width: unset;
    &:nth-last-child(2) {
      display: flex;
      flex-direction: row-reverse;
      min-width: 0;
      // Rotate the back arrow 180 degrees, shift left to align chevron with text
      &:after {
        transform: rotate(180deg);
        transform-origin: center;
        margin-left: -0.25rem;
        top: 7px;
        min-width: 1.5rem;
      }
    }
  }
}

//Large and above
@include media-breakpoint-up(lg) {
  .breadcrumb-item {
    display: inline;
    font-size: 1rem;

    &.active {
      white-space: nowrap; /* Prevents text from wrapping to the next line */
      overflow: hidden; /* Hides any content that overflows the element's box */
      text-overflow: ellipsis;
      display: inline-block;
      flex-shrink: 999999;
      margin-left: 4px;
    }
  }
}
