//
// Copyright © 2021 Anticrm Platform Contributors.
// 
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 
// See the License for the specific language governing permissions and
// limitations under the License.
//

/* Popups */
.selectPopup {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: fit-content;
  min-width: 10rem;
  max-width: 15rem;
  max-height: 22rem;
  background: var(--popup-bg-color);
  border-radius: .5rem;
  box-shadow: var(--popup-shadow);

  &.full-width {
    flex-grow: 1;
    background: none;
    border-radius: 0px;
    box-shadow: none;
    width: 100%;
    max-width: 100%;
  }
  
  &.maxHeight { height: 22rem; }
  &.autoHeight {
    max-height: calc(100vh - 2rem);
    height: auto;
  }
  &.width-40 {
    max-width: 40rem !important;
    width: 40rem !important;
  }
  &.max-width-40 {
    max-width: 40rem !important;
  }
  .header {
    border-bottom: 1px solid var(--popup-divider);

    &.no-border { border-bottom-color: transparent; }
    input {
      margin: 0;
      padding: .625rem .75rem;
      color: #d6d6d6;
      border: none;
      caret-color: var(--caret-color);
    }
    .clear-btn {
      display: flex;
      justify-content: center;
      align-items: center;
      width: .75rem;
      height: .75rem;
      border-radius: 50%;
  
      .icon {
        width: .625rem;
        height: .625rem;
      }
  
      &.show {
        color: var(--content-color);
        background-color: var(--button-border-color);
        cursor: pointer;
        &:hover {
          color: var(--accent-color);
          background-color: var(--button-border-hover);
        }
      }
    }
  }

  .scroll {
    flex-grow: 1;
    min-height: 0;
    height: max-content;
    overflow-x: hidden;
    overflow-y: auto;

    &::-webkit-scrollbar { width: 0; }
    .box {
      display: flex;
      flex-direction: column;
      height: 100%;
    }
  }

  .menu-item {
    flex-shrink: 0;
    justify-content: flex-start;
    padding: .25rem .75rem;
    min-height: 2rem;
    text-align: left;
    color: var(--caption-color);
    cursor: pointer;

    &.high { height: 3rem; }

    .icon, .color, .tag {
      flex-shrink: 0;
      margin-right: .75rem;
    }
    .icon {
      width: 1rem;
      height: 1rem;
      color: var(--content-color);
    }
    .color {
      width: .875rem;
      height: .875rem;
      border: 1px solid rgba(0, 0, 0, .1);
      border-radius: .25rem;
    }
    .tag {
      width: .5rem;
      height: .5rem;
      border-radius: 50%;
    }
    .label {
      flex-grow: 1;
      min-width: 0;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .check, .check-right {
      display: flex;
      align-items: center;
      margin-right: .75rem;
    }
    .check-right { margin: 0 0 0 2rem; }
    &:focus,
    &:hover {
      background-color: var(--popup-bg-hover);

      .icon { color: var(--accent-color); }
    }
    &.no-focus:focus { background-color: transparent; }
    &.no-focus:hover { background-color: var(--popup-bg-hover); }
  }
  .sticky-wrapper {
    display: flex;
    flex-direction: column;

    &:not(:first-child)  { margin-top: 1px; }
  }
  .menu-group {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 0;
    transition: height .5s ease;

    &__header {
      position: sticky;
      top: 0;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: .125rem .25rem;
      min-height: 1.5rem;
      font-weight: 500;
      font-size: .75rem;
      text-align: left;
      color: var(--accent-color);
      background-color: var(--button-bg-color);
      cursor: pointer;

      .icon {
        width: .25rem;
        transform-origin: 40% 50%;
        transform: rotate(0deg);
        transition: transform .15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
      }
      &.show .icon { transform: rotate(90deg); }
      &:hover { color: var(--caption-color); }
      &.show + .menu-group { height: auto; }
    }
  }
}

.antiPopup {
  display: flex;
  flex-direction: column;
  width: auto;
  min-height: 0;
  min-width: 0;
  max-width: 30rem;
  background: var(--popup-bg-color);
  border-radius: .25rem;
  box-shadow: var(--popup-shadow);
  user-select: none;

  .ap-space {
    flex-shrink: 0;
    height: .25rem;
  }
  .ap-scroll {
    flex-grow: 1;
    margin: 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    &::-webkit-scrollbar-track { margin: 0; }
    &::-webkit-scrollbar-thumb {
      background-color: var(--theme-bg-accent-color);
      &:hover { background-color: var(--theme-menu-divider); }
    }
  }
  .ap-box {
    display: flex;
    flex-direction: column;
    padding: 0;
    height: 100%;
  }
  .ap-menuItem {
    justify-content: flex-start;
    padding: 0 .5rem;
    height: 2rem;
    color: var(--caption-color);
    text-align: left;
    cursor: pointer;

    &.ap-woScroll { margin: 0 .5rem; }
    &.selected { background: var(--popup-bg-hover); }
    &.empty {
      display: flex;
      justify-content: center;
      font-style: italic;
      color: var(--theme-content-trans-color);
      cursor: default;

      &:hover {
        color: var(--theme-content-trans-color);
        background-color: transparent;
      }
    }
    &.withCheck { justify-content: space-between; }
    &.withIcon {
      margin: 0;
  
      .icon { color: var(--content-color); }
      &.hover .icon { color: var(--accent-color); }
    }  

    // &:hover { background-color: var(--popup-bg-hover); }
    &.hover {
      background-color: var(--popup-bg-hover);
      outline: none;
      // box-shadow: inset 0 0 1px 1px var(--primary-edit-border-color);
    }

    &.redlight {
      color: var(--highlight-red);
      &:hover { color: var(--highlight-red-hover); }
      &:active { color: var(--highlight-red-press); }
      &:focus { color: var(--highlight-red-press); }
    }

    &.separator {
      margin: 0.25rem 0;
      height: 1px;
      background-color: var(--popup-divider);
    }
  }
  .ap-check {
    margin-left: 1rem;
    width: 1rem;
    height: 1rem;
  }
  .ap-menuHeader {
    display: flex;
    // justify-content: center;
    align-items: center;
    padding: 0 .5rem;
    width: 100%;
    height: 3rem;
    color: var(--caption-color);
    text-align: left;
    cursor: pointer;

    &:hover {
      background-color: var(--popup-bg-hover);
      outline: none;
    }
  }

  &-withHeader {
    .ap-header {
      flex-shrink: 0;
      display: flex;
      flex-direction: column;
      margin: 0 .5rem;
      text-align: left;
  
      .ap-caption {
        margin: .5rem 0 0 .75rem;
        font-size: .75rem;
        font-weight: 600;
        text-transform: uppercase;
        color: var(--theme-content-dark-color);
      }    
    }
  }

  &-withTitle {
    .ap-title {
      flex-shrink: 0;
      margin: 1rem 1rem .25rem;
      font-weight: 500;
      color: var(--theme-caption-color);
    }
    .ap-header {
      margin: .25rem 1rem 0;
      .ap-caption {
        margin: .5rem 0 0 0;
      }
    }
  }  

  &-withCategory {
    .ap-category {
      flex-shrink: 0;
      overflow-x: auto;
      display: flex;
      margin: 1rem 1rem .25rem;

      .ap-categoryItem {
        margin: .25rem;
        color: var(--theme-content-trans-color);
        cursor: pointer;

        &.selected { 
          color: var(--theme-content-accent-color) !important; 
        }
        &:hover { 
          color: var(--theme-content-accent-color); 
        }
      }

      &::-webkit-scrollbar:horizontal { height: .125rem; }
      &::-webkit-scrollbar-thumb { background-color: var(--theme-button-bg-hovered); }
    }
    .ap-header {
      margin: .25rem 1rem 0;
      .ap-caption {
        margin: .5rem 0 0 0;
      }
    }
  }  

  .ap-footer {
    flex-shrink: 0;
    display: grid;
    grid-auto-flow: column;
    direction: rtl;
    grid-gap: 0.5rem;
    justify-content: flex-start;
    padding: 1rem 1.75rem 1.75rem 0.5rem;
    overflow: hidden;
  }
}

// Submenu
.antiPopup-submenu {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  justify-content: flex-start;
  padding: .25rem .75rem;
  min-width: 0;
  min-height: 2rem;
  text-align: left;
  color: var(--caption-color);
  cursor: pointer;

  .icon { color: var(--content-color); }
  &:focus .icon,
  &.withHover:hover .icon,
  &.withIconHover:hover .icon { color: var(--accent-color); }
  &.withHover:hover { background-color: var(--popup-bg-hover); }
}

.antiPopup .ap-menuItem.arrow,
.selectPopup .menu-item.arrow,
.antiPopup-submenu {
  position: relative;
  span {
    padding-right: 1rem;
  }
  &::after {
    content: '▶';
    position: absolute;
    top: 50%;
    right: 0.5rem;
    font-size: 0.375rem;
    color: var(--dark-color);
    transform: translateY(-50%);
  }
}

.notifyPopup, .helpAndSupportPopup {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: max-content;
  height: max-content;
  padding-bottom: 0.5rem;
  min-width: 42rem;
  max-width: 42rem;
  height: 22rem;
  min-height: 22rem;
  max-height: 22rem;
  background: var(--popup-bg-color);
  border-radius: 0.5rem;
  box-shadow: var(--popup-shadow);

  .header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding: 0 1rem;
    height: 3rem;
    border-bottom: 1px solid var(--popup-divider);
  }
}

.helpAndSupportPopup {
  min-height: 100%;
  min-width: 20rem;
}

// Remove highlights table rows and hide dots in popups
.popup .tr-body:hover, .popup-tooltip .tr-body:hover { background-color: transparent !important; }
.popup-tooltip .tr-body .menuRow { visibility: hidden !important; }