@use 'sass:math';

.pwv-Dropdown {
  cursor: default;
  position: relative;
  > button {
    margin: 0;
    display: flex;
    align-items: center;
    border: none;
    background-color: transparent;
    font-size: 1em;
    height: 100%;
    width: 100%;
    color: inherit;

    @include toolbarItem;
    padding: 0 5px;

    &:focus {
      outline: none;
    }
    &:enabled {
      &:hover {
        @include toolbarItem__Hover;
      }
      &:active {
        @include toolbarItem__Active;
      }
      &:focus {
        @include toolbarItem__Focus;
      }
    }
    .pwv-Dropdown-text {
      display: block;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      padding: 0 4px 0 14px;
      .pwv-icon {
        width: 18px;
        svg {
          height: 18px;
        }
      }
    }
    .pwv-Dropdown-caret {
      padding-left: 8px;
      display: inline-block;
      .pwv-icon {
        width: 1.2rem;
        text-align: right;
        svg {
          height: 12px;
        }
      }
    }

    &:focus {
      outline: none;
    }
  }

  &--open {
    .pwv-DropdownPanel {
      display: block;
    }
  }

  &Item {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    white-space: nowrap;
    padding: 0 1rem;

    @include dropdownItem;

    &:hover {
      @include dropdownItem__Hover;
    }

    .pwv-icon {
      display: inline-block;
      margin-right: 0.25rem;
      width: $dropdownItem__IconSize * 1.5;
      svg {
        height: $dropdownItem__IconSize;
        fill: currentColor;
      }
    }
  }
}

.pwv-DropdownPanel {
  display: none;
  position: absolute;
  overflow-y: auto;
  top: 34px;
  min-width: 100%;
  box-shadow: var(--pwv-drop-shadow-2);
  z-index: 100;
  background-color: $dropdownPanel__BackgroundColor;

  &.pwv-DropdownPanel--scroll {
    min-width: calc(100% + 20px);
  }

  ul {
    list-style: none;
    padding: 0;
    margin: 0;
    li {
      white-space: nowrap;
      cursor: pointer;
    }
  }

  .pwv-Dropdown-item-text {
    white-space: nowrap;
  }
}

.pwv-DropdownSeparator {
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  height: math.div($dropdownItem__Height, 4);
  width: 100% !important;
  // padding: 0 math.div($dropdownItem__Height, 4);

  span {
    display: block;
    background-color: $toolbarItem__TextColor;
    opacity: 0.2;
    width: 100%;
    flex-grow: 1;
    height: 1px;
    box-sizing: border-box;
  }
}

.pwv-Dropdown--alignLeft {
  text-align: left;
  > button {
    justify-content: space-between;
  }
  .pwv-DropdownPanel {
    left: 0;
  }
}
.pwv-Dropdown--alignRight {
  text-align: right;
  > button {
    justify-content: flex-end;
  }
  .pwv-DropdownPanel {
    right: 0;
    text-align: right;
  }
  .pwv-DropdownItem {
    justify-content: flex-end;
  }
}

.pwv-Dropdown--alignCenter {
  text-align: center;
  > button {
    justify-content: center;
    // padding: 0;
  }
  .pwv-DropdownPanel {
    right: 0;
  }
}
