// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) KALEIDOS INC Sucursal en España SL

@use "refactor/common-refactor.scss" as deprecated;
@use "ds/z-index.scss" as *;

.context-menu {
  position: relative;
  visibility: hidden;
  opacity: deprecated.$op-0;
  z-index: var(--z-index-dropdown);

  &.is-open {
    position: relative;
    display: block;
    opacity: deprecated.$op-10;
    visibility: visible;
  }

  &.fixed {
    position: fixed;
  }

  .context-menu-items {
    @include deprecated.menu-shadow;

    position: absolute;
    top: deprecated.$s-12;
    left: calc(-1 * deprecated.$s-6);
    max-height: deprecated.$s-480;
    min-width: deprecated.$s-96;
    margin: deprecated.$s-0;
    padding: deprecated.$s-4;
    border-radius: deprecated.$br-8;
    border: deprecated.$s-2 solid var(--panel-border-color);
    background-color: var(--menu-background-color);
    overflow: auto;

    & .separator {
      border-top: solid deprecated.$s-1 var(--color-background-quaternary);
    }

    &.min-width {
      min-width: deprecated.$s-192;
    }

    .context-menu-item {
      display: flex;

      .context-menu-action {
        @include deprecated.body-small-typography;

        display: flex;
        align-items: center;
        justify-content: flex-start;
        height: deprecated.$s-28;
        width: 100%;
        padding: deprecated.$s-6;
        border-radius: deprecated.$br-8;
        white-space: nowrap;
        color: var(--menu-foreground-color);

        &.submenu {
          display: flex;
          align-items: center;
          justify-content: space-between;

          .submenu-icon {
            margin-left: 0.5rem;

            svg {
              @extend %button-icon-small;

              stroke: var(--menu-foreground-color);
            }
          }
        }

        &.submenu-back {
          display: flex;
          align-items: center;
          font-weight: deprecated.$fw700;
          background: none;
          border: none;
          cursor: pointer;

          .submenu-icon-back svg {
            @extend %button-icon-small;

            stroke: var(--menu-foreground-color);
            transform: rotate(180deg);
          }
        }
      }

      &:hover .context-menu-action {
        background-color: var(--menu-background-color-hover);
        text-decoration: none;
        color: var(--menu-foreground-color);

        &.submenu .submenu-icon svg {
          stroke: var(--menu-foreground-color);
        }

        &.submenu-back .submenu-icon-back svg {
          stroke: var(--menu-foreground-color);
        }
      }

      .context-menu-action-disabled,
      &:hover .context-menu-action-disabled {
        color: var(--color-foreground-secondary);
      }

      &:focus {
        outline: none;
      }

      &:focus-visible {
        outline: none;

        .context-menu-action {
          border: 1px solid var(--menu-border-color-focus);
          background-color: var(--menu-background-color-focus);
          text-decoration: none;
          color: var(--menu-foreground-color-focus);

          &.submenu .submenu-icon svg {
            stroke: var(--menu-foreground-color-focus);
          }

          &.submenu-back .submenu-icon-back svg {
            stroke: var(--menu-foreground-color-focus);
          }
        }
      }

      &.selected {
        .context-menu-action {
          justify-content: space-between;
          color: var(--menu-foreground-color-focus);
        }

        .selected-icon {
          @extend %button-tag;

          border-radius: deprecated.$br-8;
          height: 100%;

          svg {
            @extend %button-icon-small;

            stroke: var(--menu-foreground-color-focus);
          }
        }
      }
    }

    .is-selected .context-menu-action {
      padding-left: deprecated.$s-28;
      background-image: url("/images/icons/tick.svg");
      background-repeat: no-repeat;
      background-position: 5% 48%;
      background-size: deprecated.$s-12;
      font-weight: deprecated.$fw700;
    }
  }

  &.is-selectable {
    .context-menu-action {
      padding-left: 1.5rem;
    }
  }
}
