//
// 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 "mixins" as *;
@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";
@use "../../utilities/focus-outline" as *;
@use "../../utilities/high-contrast-mode" as *;
@use "../../utilities/z-index" as *;
@use "../../utilities/layer" as *;

@use "../button";

/// Modal styles
/// @access public
/// @group modal

// Modal
$modal-border-top: $background-brand 4px solid !default;
$modal-border-radius: 6px;
$modal-footer-background-color: $layer-primary !default; //TODO use $layer token

@mixin modal {
  .#{$prefix}--modal {
    @include component-reset.reset;
    @include font-family("sans");
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: z("hidden");
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    content: "";
    opacity: 0;
    //background-color: rgba(var(--ui-07), 0.5);
    background-color: rgba(#0b1923, 0.8); // using current token of $overlay
    transition: opacity 200ms, z-index 0s 200ms, visibility 0s 200ms;
    visibility: hidden;

    /*&.#{$prefix}--modal--tall {
      align-items: flex;
    }*/

    &.is-visible {
      z-index: z("modal");
      opacity: 1;
      transition: opacity 200ms;
      visibility: visible;
    }
  }

  .#{$prefix}--modal__wrapper {
    display: inline;
  }

  .#{$prefix}--modal-inner {
    max-height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
  }

  .#{$prefix}--modal-container {
    @include reset;
    @include layer("pop-out");
    //box-shadow: 0 20px 30px -10px $box-shadow;
    position: relative;
    margin: auto;
    display: flex;
    flex-direction: column;
    background-color: $background-main;
    overflow: hidden;
    &:before {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 4px;
      content: "";
      background: $action-default-fill-primary-default;
    }
    //border-top: $modal-border-top;
    // border-radius: $modal-border-radius;
    min-width: 100%;
    //max-height: 100%;
    height: 100%;
    padding: $spacing-08 $spacing-05 0rem $spacing-05;

    @include breakpoint("md") {
      height: auto;
      min-width: 500px;
      max-width: 75%;

      .#{$prefix}--modal--wide & {
        max-width: 100%;
        width: 100%;
        min-width: 768px;
      }

      padding: $spacing-08 $spacing-09 0 $spacing-09;
    }

    @media (min-width: 1024px) {
      max-width: 55%;
      //max-height: 100%;

      .#{$prefix}--modal--wide & {
        max-width: 90%;
      }
    }

    @media (min-width: 1600px) {
      max-width: 50%;
      //max-height: 100%;

      .#{$prefix}--modal--wide & {
        max-width: 80%;
      }
    }
  }

  .#{$prefix}--modal-header {
    margin-bottom: $spacing-06;
    display: flex;
    justify-content: space-between;
  }

  .#{$prefix}--modal-header__label {
    @include reset;
    @include type-style("label");
    color: $text-body-secondary;
    font-weight: 400;
    margin-bottom: $spacing-03;
    font-size: 0.87rem;
  }

  .#{$prefix}--modal-header__heading {
    @include reset;
    @include type-style("productive-heading-04");
    font-weight: 600;
    color: $text-body-default;
  }

  .#{$prefix}--modal-content {
    //overflow-y: auto;
    margin-bottom: $spacing-08;
    color: $text-body-default;

    > * {
      @include reset;
    }
  }

  .#{$prefix}--modal-footer {
    margin-top: auto;
    text-align: right;
    background-color: $modal-footer-background-color;
    margin-left: -$spacing-05; // calcRem(-24px);
    margin-right: -$spacing-05; // calcRem(-24px);
    padding: $spacing-05 $spacing-05;
    border-radius: 0 0 $modal-border-radius $modal-border-radius;
    .#{$prefix}--link + .#{$prefix}--btn {
      margin-left: $spacing-05;
    }

    @include breakpoint("md") {
      margin-left: calcRem(-48px);
      margin-right: calcRem(-48px);
      padding: $spacing-07 $spacing-09;
    }
  }

  .#{$prefix}--modal-close {
    position: absolute;
    top: calcRem(16px);
    right: calcRem(16px);
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    background-color: transparent;
    border: none;
    padding: 0.25rem 0.25rem 0.125rem;

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

  .#{$prefix}--modal-close__icon {
    transition: 200ms;
    // fill: var(--ui-05); // TODO change $field-border
    width: calcRem(12px);
    height: calcRem(12px);
    color: $text-body-default;
  }

  .#{$prefix}--modal--background-image {
    background-size: cover;
  }
}
