/**
 *
 * @ai-apps/angular v2.152.0 | _modal.scss
 *
 * Copyright 2014, 2023 IBM
 *
 * Licensed under the Apache 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
 *
 *   http://www.apache.org/licenses/LICENSE-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.
 */


//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use '../../breakpoint' as *;
@use '../../config' as *;
@use '../../motion' as *;
@use '../../spacing' as *;
@use '../../theme' as *;
@use '../../type' as *;
@use '../../utilities/convert' as *;
@use '../../utilities/component-reset' as *;
@use '../../utilities/focus-outline' as *;
@use '../../utilities/high-contrast-mode' as *;
@use '../../utilities/z-index' as *;

@use '../button';

/// Modal styles
/// @access public
/// @group modal
@mixin modal {
  .#{$prefix}--modal {
    position: fixed;
    z-index: z('modal');
    top: 0;
    left: 0;
    display: flex;
    width: 100vw;
    height: 100vh;
    align-items: center;
    justify-content: center;
    background-color: $overlay;
    content: '';
    opacity: 0;
    transition: opacity $duration-moderate-02 motion(exit, expressive),
      visibility 0ms linear $duration-moderate-02;
    visibility: hidden;

    &.is-visible {
      opacity: 1;
      transition: opacity $duration-moderate-02 motion(entrance, expressive),
        visibility 0ms linear;
      visibility: inherit;
    }

    // V11: Question for design: do we have an updated tokens for fields that exist on `layer`?
    .#{$prefix}--pagination,
    .#{$prefix}--pagination__control-buttons,
    .#{$prefix}--text-input,
    .#{$prefix}--text-area,
    .#{$prefix}--search-input,
    .#{$prefix}--select-input,
    .#{$prefix}--dropdown,
    .#{$prefix}--dropdown-list,
    .#{$prefix}--number input[type='number'],
    .#{$prefix}--date-picker__input {
      background-color: $field-02;
    }
  }

  .#{$prefix}--modal.is-visible .#{$prefix}--modal-container {
    transform: translate3d(0, 0, 0);
    transition: transform $duration-moderate-02 motion(entrance, expressive);
  }

  .#{$prefix}--modal-container {
    position: fixed;
    top: 0;
    display: grid;
    overflow: hidden;
    width: 100%;
    height: 100%;
    max-height: 100%;
    background-color: $layer;
    grid-template-columns: 100%;
    grid-template-rows: auto 1fr auto;
    // make modal edge visible on high contrast themes (#3880)
    outline: 3px solid transparent;
    outline-offset: -3px;
    transform: translate3d(0, -24px, 0);
    transform-origin: top center;
    transition: transform $duration-moderate-02 motion(exit, expressive);

    @include breakpoint(md) {
      position: static;
      width: 84%;
      height: auto;
      max-height: 90%;

      .#{$prefix}--modal-header,
      .#{$prefix}--modal-content,
      .#{$prefix}--modal-content__regular-content {
        padding-right: 20%;
      }

      .#{$prefix}--modal-content--with-form {
        // Override for `.#{$prefix}--modal-content`
        padding-right: $spacing-05;
      }
    }

    @include breakpoint(lg) {
      width: 60%;
      max-height: 84%;
    }

    @include breakpoint(xlg) {
      width: 48%;
    }
  }

  .#{$prefix}--modal-header,
  .#{$prefix}--modal-content {
    padding-left: $spacing-05;
  }

  .#{$prefix}--modal-header,
  .#{$prefix}--modal-content,
  .#{$prefix}--modal-content__regular-content {
    padding-right: $spacing-05;
  }

  .#{$prefix}--modal-content--with-form {
    padding-right: $spacing-05;
  }

  .#{$prefix}--modal-container--xs {
    .#{$prefix}--modal-header {
      padding-right: $spacing-09;
    }

    .#{$prefix}--modal-content,
    .#{$prefix}--modal-content__regular-content,
    .#{$prefix}--modal-content--with-form {
      padding-right: $spacing-05;
    }

    @include breakpoint(md) {
      width: 48%;
    }

    @include breakpoint(lg) {
      width: 32%;
      max-height: 48%;
    }

    @include breakpoint(xlg) {
      width: 24%;
    }
  }

  .#{$prefix}--modal-container--sm {
    .#{$prefix}--modal-header {
      padding-right: $spacing-09;
    }

    .#{$prefix}--modal-content,
    .#{$prefix}--modal-content__regular-content,
    .#{$prefix}--modal-content--with-form {
      padding-right: $spacing-05;
    }

    @include breakpoint(md) {
      width: 60%;
    }

    @include breakpoint(lg) {
      width: 42%;
      max-height: 72%;
    }

    @include breakpoint(xlg) {
      width: 36%;

      .#{$prefix}--modal-header,
      .#{$prefix}--modal-content,
      .#{$prefix}--modal-content__regular-content {
        padding-right: 20%;
      }

      .#{$prefix}--modal-content--with-form {
        // Override for `.#{$prefix}--modal-content`
        padding-right: $spacing-05;
      }
    }
  }

  .#{$prefix}--modal-container--lg {
    .#{$prefix}--modal-header {
      padding-right: $spacing-09;
    }

    .#{$prefix}--modal-content,
    .#{$prefix}--modal-content__regular-content,
    .#{$prefix}--modal-content--with-form {
      padding-right: $spacing-05;
    }

    @include breakpoint(md) {
      width: 96%;

      .#{$prefix}--modal-header,
      .#{$prefix}--modal-content,
      .#{$prefix}--modal-content__regular-content {
        padding-right: 20%;
      }

      .#{$prefix}--modal-content--with-form {
        // Override for `.#{$prefix}--modal-content`
        padding-right: $spacing-05;
      }
    }

    @include breakpoint(lg) {
      width: 84%;
      max-height: 96%;
    }

    @include breakpoint(xlg) {
      width: 72%;
    }
  }

  .#{$prefix}--modal-header {
    padding-top: $spacing-05;
    padding-right: $spacing-09;
    margin-bottom: $spacing-03;
    grid-column: 1/-1;
    grid-row: 1/1;
  }

  .#{$prefix}--modal-header__label {
    @include type-style('label-01');

    margin-bottom: $spacing-02;
    color: $text-secondary;
  }

  .#{$prefix}--modal-header__heading {
    @include type-style('productive-heading-03');

    color: $text-primary;
  }

  .#{$prefix}--modal-content {
    @include type-style('body-long-01');

    position: relative;
    // Required to accommodate focus outline's negative offset:
    padding-top: $spacing-03;
    margin-bottom: $spacing-09;
    color: $text-primary;
    font-weight: 400;
    grid-column: 1/-1;
    grid-row: 2/-2;
    overflow-y: auto;

    &:focus {
      @include focus-outline('outline');
    }
  }

  .#{$prefix}--modal-content > p {
    @include type-style('body-long-01');
  }

  // Required so overflow-indicator disappears at end of content
  .#{$prefix}--modal-scroll-content > *:last-child {
    padding-bottom: $spacing-07;
  }

  .#{$prefix}--modal-content--overflow-indicator {
    position: absolute;
    bottom: $spacing-09;
    left: 0;
    width: 100%;
    height: rem(32px);
    background-image: linear-gradient(to bottom, transparent, $layer);
    content: '';
    grid-column: 1/-1;
    grid-row: 2/-2;
    pointer-events: none;
  }

  // Safari-only media query
  // won't appear correctly with CSS custom properties
  // see: code snippet and tabs overflow indicators
  @media not all and (min-resolution: 0.001dpcm) {
    @supports (-webkit-appearance: none) and (stroke-color: transparent) {
      .#{$prefix}--modal-content--overflow-indicator {
        background-image: linear-gradient(to bottom, rgba($layer, 0), $layer);
      }
    }
  }

  .#{$prefix}--modal-content:focus
    ~ .#{$prefix}--modal-content--overflow-indicator {
    width: calc(100% - 4px);
    margin: 0 2px 2px;
  }

  @media screen and (-ms-high-contrast: active) {
    .#{$prefix}--modal-scroll-content > *:last-child {
      padding-bottom: 0;
    }

    .#{$prefix}--modal-content--overflow-indicator {
      display: none;
    }
  }

  .#{$prefix}--modal-footer {
    display: flex;
    height: rem(64px);
    justify-content: flex-end;
    margin-top: auto;
    grid-column: 1/-1;
    grid-row: -1/-1;
  }

  .#{$prefix}--modal-footer .#{$prefix}--btn {
    max-width: none;
    height: rem(64px);
    flex: 0 1 50%;
    padding-top: $spacing-05;
    padding-bottom: $spacing-07;
    margin: 0;
  }

  .#{$prefix}--modal-footer--three-button .#{$prefix}--btn {
    flex: 0 1 25%;
    align-items: flex-start;
  }

  .#{$prefix}--modal-close {
    position: absolute;
    z-index: 2;
    top: 0;
    right: 0;
    overflow: hidden;
    width: 3rem;
    height: 3rem;
    padding: rem(12px);
    border: 2px solid transparent;
    background-color: transparent;
    cursor: pointer;
    transition: background-color $duration-fast-02 motion(standard, productive);

    &:hover {
      background-color: $layer-hover;
    }

    &:focus {
      border-color: $focus;
      outline: none;
    }
  }

  .#{$prefix}--modal-close::-moz-focus-inner {
    border: 0;
  }

  .#{$prefix}--modal-close__icon {
    width: rem(20px);
    height: rem(20px);
    fill: $icon-primary;
  }

  .#{$prefix}--body--with-modal-open {
    overflow: hidden;
  }

  .#{$prefix}--body--with-modal-open .#{$prefix}--tooltip,
  .#{$prefix}--body--with-modal-open .#{$prefix}--overflow-menu-options {
    z-index: z('modal');
  }

  // Windows HCM fix
  /* stylelint-disable */
  .#{$prefix}--modal-close__icon {
    @include high-contrast-mode('icon-fill');
  }

  .#{$prefix}--modal-close:focus {
    @include high-contrast-mode('focus');
  }
  /* stylelint-enable */
}
