/*
 * Copyright (c) 2019-present Sonatype, Inc.
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License 2.0 which accompanies this
 * distribution and is available at https://www.eclipse.org/legal/epl-2.0/.
 */
@use '../../scss-shared/nx-container-helpers';
@use '../../scss-shared/nx-text-helpers';
@use '../../scss-shared/nx-mask-helpers';

.nx-modal {
  // the "padding" around the interior of nx-modal. In order to get borders and scrollbars to appear
  // in the desired locations, this can't actually be implemented as padding on .nx-modal, but must instead be
  // a mix of padding and margin on the .nx-modal, .nx-modal-header, .nx-modal-content, and .nx-footer elements
  --nx-modal-padding: var(--nx-spacing-6x);

  border-radius: var(--nx-border-radius);
  box-sizing: border-box;
  background-color: var(--nx-color-component-background);
  color: var(--nx-color-text);
  margin: 100px 0;
  padding: var(--nx-modal-padding);
  width: 800px;

  @include nx-container-helpers.container-vertical;

  &, > .nx-form {
    display: flex;
    flex-basis: auto;
    flex-direction: column;
    flex-shrink: 1;
    overflow: hidden;
  }

  > .nx-form {
    // nx-form should take up the entire modal area so the children layout consistently
    margin: calc(0px - var(--nx-modal-padding));
    padding: var(--nx-modal-padding);
  }

  .nx-footer {
    margin: 0;
  }
}

.nx-modal--narrow {
  width: 600px;
}

.nx-modal--wide {
  width: 1000px;
}

.nx-modal-header {
  border-bottom: var(--nx-border-default);
  padding-bottom: var(--nx-spacing-6x);

  .nx-h2 {
    @include nx-text-helpers.truncate-ellipsis;
    max-width: unset;
  }

  @include nx-container-helpers.container-vertical;
}

.nx-modal-backdrop {
  @include nx-mask-helpers.background-mask(var(--nx-z-index-modal-backdrop));

  // undo styles that chrome applies to <dialog> elements
  border: initial;
  max-width: initial;
  max-height: initial;
  width: initial;
  height: initial;
  margin: initial;
  padding: initial;

  // prevent brief flash of scrollbar as tooltips disappear
  overflow: hidden;

  &::backdrop {
    // chrome tries to add its own subtle mask here which doubles up with our own
    display: none;
  }
}

.nx-modal-content {
  flex-shrink: 1;
  flex-basis: auto;

  // we want the content area scrollbar to be at the right edge of the modal, so use negative margin
  // to bump the content area over the right padding and then give that padding to the content area itself.
  // Also do the same on the left so that overflowing visual effects (like checkbox focus borders) don't get cut off
  margin-right: calc(0px - var(--nx-modal-padding));
  margin-left: calc(0px - var(--nx-modal-padding));
  padding: var(--nx-spacing-6x) var(--nx-modal-padding) var(--nx-spacing-8x) var(--nx-modal-padding);
  overflow-y: auto;

  @include nx-container-helpers.container-vertical;
}

.nx-modal-content--tabs {
  display: flex;
  padding-bottom: 0;

  .nx-tabs {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    width: 100%;
  }

  .nx-tab-list {
    margin-top: 1px;
    margin-left: 1px;
    margin-right: 1px;
  }

  .nx-tab-panel {
    flex-shrink: 1;
    overflow-y: auto;
    margin-bottom: var(--nx-spacing-6x);
  }
}
