// Toolbars
//================================================== */

@import '../colorpicker/colorpicker';
@import '../fontpicker/fontpicker';
@import '../popupmenu/popupmenu';

$toolbar-buttonset-height: 48px;

.toolbar {
  .more {
    display: none;
  }
}

.toolbar.do-resize {
  .toolbar-searchfield-wrapper {
    margin-top: 1px;

    @media (max-width: $breakpoint-phone-to-tablet) {
      overflow: hidden;
    }

    &.has-close-icon-button {
      @media (max-width: $breakpoint-phone-to-tablet) {
        overflow: hidden;
      }
    }

    .searchfield-category-button {
      .icon {
        transform: translateY(0);
      }
    }
  }
}

// See also Colors.scss
.toolbar,
.formatter-toolbar {
  position: relative;
  text-align: left;
  -webkit-touch-callout: none;

  &.has-title {
    text-align: right;
  }

  &.right-aligned {
    text-align: right;
  }

  // Acts as a spacer that causes the toolbar items to vertically align.
  &::before {
    @include vertical-alignment-spacer;

    width: 0;
  }

  > * {
    display: inline-block;
    vertical-align: middle;
  }

  [class^='btn'] {
    margin: 0;
  }

  .buttonset {
    @include no-select();

    height: $toolbar-buttonset-height;
    overflow: hidden;
    padding-left: 1px;  //for the focus state
    width: 100%; // Overridden by sizing calculation.

    > * {
      margin: 3px 5px 3px 0;
      vertical-align: top;

      &:last-child {
        margin-right: 1px;
      }

      &.is-overflowed {
        display: none;
      }
    }

    > [class^='btn'] {
      min-width: 34px;

      &:not(.has-text) {
        padding: unset;
      }
    }

    > .separator {
      background-color: $formatter-toolbar-separator-color;
      display: inline-block;
      height: 20px;
      margin: 3px 16px 0;
      position: relative;
      top: 6px;
      width: 1px;
    }

    // Hide separators that come after "overflowed" elements
    .is-overflowed {
      + .separator,
      + .popupmenu,
      + .popupmenu-wrapper + .separator {
        display: none;
      }
    }
  }

  .title {
    @include enable-select();

    height: $toolbar-buttonset-height;
    overflow: hidden;
    position: relative;
    text-align: left;
    text-overflow: ellipsis;
    top: 0;
    white-space: nowrap;
    width: 45%; // Overridden by sizing calculation.

    // Acts as a spacer that causes the toolbar items to vertically align.
    &::before {
      @include vertical-alignment-spacer;
    }

    &:has(.page-title, .section-title) {
      &::before {
        display: none;
      }
    }

    .page-title,
    .section-title {
      display: block;
      overflow: hidden;
      padding: 0;
      margin: 0;
      line-height: 1.2;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .page-title {
      font-size: $ids-size-font-base;
      font-weight: $ids-number-font-weight-bold;
      margin-block: 2px;
    }

    .section-title {
      font-size: $ids-size-font-sm;
      color: $font-color-lowcontrast;
      margin-block: 2px;
    }

    + .buttonset {
      text-align: right;
      width: calc(55% - 1px); // -1px for the spacer in the ::after pseudo on the toolbar elem.
    }
  }

  // Container for More Button
  .more {
    @include no-select();

    text-align: right;

    > * {
      margin-right: 1px;
    }

    .btn-actions.is-open .icon {
      color: $button-color-tertiary-initial-font;
    }
  }

  &.do-resize {
    .buttonset {
      width: auto;

      @media only screen and (max-width: $breakpoint-phone-to-tablet) {
        width: auto !important;
        height: 42px;
      }

      &:has(.searchfield-wrapper){
        @media screen and (max-width: $breakpoint-phone-to-tablet) {
          display: inline-flex;
        }
      }
    }

    &:not(.contextual-toolbar) {
      .title,
      .title-detail {
        left: 1px;
        position: absolute;
        top: 2px;
        width: auto;
      }
    }

    &.has-more-button {
      &:not(.has-title) .buttonset {
        width: calc(100% - 38px);

        @media (max-width: ($breakpoint-phone-to-tablet + 1)) {
          width: calc(100% - 38px) !important;
        }
      }

      .title {
        + .buttonset {
          width: auto;
        }
      }
    }

    &.standalone {
      .title {
        left: 11px;
      }
    }
  }

  &.has-more-button {
    .buttonset {
      width: calc(100% - 38px);

      > *:last-child {
        margin-right: 5px; // Add back the 5px since we need to visually separate the More button from the others.
      }
    }

    &.has-title {
      .buttonset {
        width: calc(55% - 38px);
      }
    }

    .more {
      display: inline-block !important;
    }
  }

  // Force no display of the "More Actions" button
  &.no-actions-button {
    &.has-more-button {
      .more {
        display: none !important;
      }

      .buttonset {
        width: calc(100% - 1px);
      }

      &.has-title {
        .buttonset {
          width: calc(55% - 1px);
        }
      }
    }
  }

  // Standalone Toolbar simply has a background and border that surrounds its boundaries
  &.standalone {
    background-color: $toolbar-standalone-bg-color;
    border-bottom: 1px solid $toolbar-standalone-border-color;
    padding: 0 1rem;

    [class^='btn'] {
      &[disabled],
      &[disabled]:hover {
        color: $toolbar-standalone-disabled-color;

        .icon {
          color: $toolbar-standalone-disabled-color;
        }
      }
    }
  }
}

// Styles for regular toolbar only
.toolbar {
  font-size: 0;
  margin-bottom: 5px;

  &:not(.formatter-toolbar):not(.contextual-toolbar) {
    height: 42px;

    &:has(.section-title) {
      height: 52px;
    }

    &:not(:has(.more)) .buttonset {
      display: inline-flex;
      align-items: center;
      justify-content: flex-end;
      gap: 8px;
    }
  }
  

  .title,
  .title-detail {
    @include antialiased();
    @include font-size(16);

    color: $font-color-extrahighcontrast;

    + .buttonset {
      text-align: right;
    }
  }
}

// For Standalone popup menu label
.btn-menu,
.btn-actions {
  &.is-open {
    color: $toolbar-standalone-popup-label-color;

    .icon {
      color: $toolbar-standalone-popup-label-color;
    }
  }
}

// Used in Editor, some card menus, etc.
.popupmenu.toolbar-options {
  li {
    > a {
      padding: 0 30px;
    }

    > .icon,
    > b {
      margin-left: 10px;
      width: 28px;
    }

    &.is-selected {
      background-color: $popupmenu-hover-color;
      color: $font-color-highcontrast;
    }
  }

  &.has-icons {
    li {
      > a {
        padding: 0 30px 0 45px;
      }
    }
  }
}

// Styles for contextual toolbar
.contextual-toolbar {
  background-color: $contextual-toolbar-bg-color;
  margin: 0;
  overflow: hidden !important;

  // Updated changes from listview button and font sizes
  // Override Toolbar styles
  &.toolbar {
    height: 42px;
    margin-bottom: 0;
    padding: 0 20px;

    .title {
      color: $contextual-toolbar-color;
      font-size: $ids-size-font-base;
      height: 42px;

      + .buttonset {
        text-align: right;
        width: calc(55% - 1px);
      }
    }

    .buttonset {
      height: 42px;
    }

    // EPC: NOTE: Do NOT add different margins and heights to buttons inside of contextual toolbars.
    // Toolbar Overflow Calculation needs buttons to be "shorter" than the buttonset.
    [class^='btn'] {
      border-radius: 8px;
      color: $contextual-toolbar-button-color;
      min-width: 0;
      padding: 0 10px;
      margin-top: 4px;

      &.btn-icon {
        padding: 0 8px;
      }

      .icon {
        color: $contextual-toolbar-button-color;
      }

      &.btn-actions {
        margin-top: 0;
      }

      &:focus {
        box-shadow: 0 0 0 2px transparent, 0 0 0 1px $contextual-toolbar-color;

        &:not(.hide-focus) {
          color: $contextual-toolbar-color;
        }
      }

      &:hover {
        color: $contextual-toolbar-button-hover-color !important;
        background-color: rgba(0, 0, 0, .3) !important;

        .icon {
          color: $contextual-toolbar-button-hover-color !important;
        }
      }

      &.is-selected {
        color: $contextual-toolbar-color;

        .icon {
          color: $contextual-toolbar-color;
        }

        &:focus:not(.hide-focus) {
          color: $contextual-toolbar-color;

          .icon {
            color: $contextual-toolbar-color;
          }
        }
      }

      .ripple {
        background-color: $contextual-toolbar-color;
      }

      &[disabled] {
        color: $contextual-toolbar-color;
        opacity: $button-disabled-opacity;
        cursor: default;

        .icon {
          color: $contextual-toolbar-button-disabled-color;
        }

        &:hover {
          background-color: transparent;
          border-color: transparent;
          opacity: 0.5;
        }
      }
    }

    .btn-actions .icon {
      position: relative;
      left: -3px;
    }
  }

  &.is-hidden {
    display: none;
    height: 0;
  }
}

@include respond-to(phone) {
  .toolbar {
    .btn,
    .btn-tertiary {
      padding: 0 6px;
    }
  }
}

@media (max-width: ($breakpoint-phone-to-tablet - 1)) {
  .toolbar {
    // Show text with icon buttons by using this class.
    // Text will still become invisible on small breakpoint (but still visible to screen readers).
    // See respond-to(tabletdown) below.
    [class^='btn']:not(.has-notification-badge) {
      min-width: 34px;
      width: auto;
      cursor: pointer;

      > .icon + span {
        @include audible();

        &:not(.audible) {
          padding-left: 0;
        }

        + .icon {
          margin-left: 0;
        }
      }
    }

    .btn-split-menu {
      &.btn {
        margin-right: 10px;
      }
    }
  }
}

html[class*='theme-classic-'] {
  .toolbar.standalone .buttonset {
      height: 40px;
  }
}

// RTL Styles
html[dir='rtl'] {
  .toolbar,
  .formatter-toolbar {
    text-align: right;

    &.has-title {
      text-align: left;
    }

    &.right-aligned {
      text-align: left;
    }

    .title,
    .title-detail {
      text-align: right;

      + .buttonset {
        text-align: left;
      }
    }

    &.has-more-button {
      .buttonset > *:last-child {
        margin-left: 5px;
        margin-right: 0;
      }
    }

    &.do-resize {
      .title,
      .title-detail {
        left: auto;
        right: 0;
      }

      &.standalone {
        .title {
          left: auto;
          right: 10px;
        }
      }
    }

    &:not(.standalone) .searchfield-wrapper.toolbar-searchfield-wrapper:not(.has-categories):not(.is-open) {
      input {
        padding-left: 31px;
      }

      .icon:not(.icon-dropdown) {
        inset-inline-end: 9px;
      }

      &.has-text {
        input {
          padding-left: 19px;
        }
      }
    }
  }
}

@media print {
  .toolbar {
    &.has-more-button {
      .more {
        display: none !important;
      }
    }
  }
}
