//
// 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.
//

//-----------------------------
// Modals
//-----------------------------

@import '../../globals/scss/vars';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/layout';
@import '../../globals/scss/layer';
@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';
@import '../../globals/scss/css--reset';
@import '../../globals/scss/css--typography';
@import 'mixins';

@import '../button/button';

@mixin modal {
  .#{$prefix}--modal {
    @include reset;
    @include font-family;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: z('hidden');
    display: flex;
    align-items: center;
    justify-content: center;
    content: '';
    opacity: 0;
    background-color: rgba($ui-03, 0.5);
    transition: opacity 200ms, z-index 0s 200ms, visibility 0s 200ms;
    visibility: hidden;

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

  .#{$prefix}--modal--danger {
    @include modal--color($support-01);
  }

  .#{$prefix}--modal-container {
    @include reset;
    @include layer('pop-out');
    position: relative;
    display: flex;
    flex-direction: column;
    background-color: $ui-01;
    border-top: $modal-border-top;
    min-width: 100%;
    max-height: 100%;
    height: 100%;
    padding: $spacing-xl 3% 0rem 3%;

    @media (min-width: 600px) {
      height: auto;
      min-width: 500px;
      max-width: 75%;
      max-height: 90%;
      padding: $spacing-2xl $spacing-3xl 0 $spacing-3xl;
    }

    @media (min-width: 1024px) {
      max-width: 50%;
      max-height: 80%;
    }
  }

  .#{$prefix}--modal-header {
    margin-bottom: $spacing-lg;
  }

  .#{$prefix}--modal-header,
  .#{$prefix}--modal-footer {
    flex-shrink: 0;
  }

  .#{$prefix}--modal-header__label {
    @include reset;
    @include typescale('omega');
    @include letter-spacing;
    color: $text-01;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: $spacing-xs;
  }

  .#{$prefix}--modal-header__heading {
    @include reset;
    @include typescale('beta');
    font-weight: 300;
    color: $text-02;
  }

  .#{$prefix}--modal-content {
    overflow-y: auto;
    margin-bottom: $spacing-3xl;
    color: $text-01;
    font-weight: 400;

    > * {
      @include reset;
    }
  }

  .#{$prefix}--modal-footer {
    margin-top: auto;
    display: flex;
    justify-content: flex-end;
    background-color: $modal-footer-background-color;
    margin-left: rem(-24px);
    margin-right: rem(-24px);
    padding: $spacing-xl $spacing-xl;

    @media (min-width: 600px) {
      margin-left: rem(-48px);
      margin-right: rem(-48px);
      padding: $spacing-xl $spacing-3xl;
    }
  }

  .#{$prefix}--modal-close {
    position: absolute;
    top: rem(16px);
    right: rem(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 {
    fill: $ui-05;
  }
}

@mixin modal--x {
  .#{$prefix}--modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: z('hidden');
    display: flex;
    align-items: center;
    justify-content: center;
    content: '';
    opacity: 0;
    background-color: $overlay-01;
    transition: opacity $duration--moderate-01 motion(exit, expressive),
      z-index 0s $duration--moderate-01 motion(exit, expressive), visibility 0s $duration--moderate-01 motion(exit, expressive);
    visibility: hidden;

    &.is-visible {
      z-index: z('modal');
      opacity: 1;
      transition: opacity $duration--slow-01 motion(entrance, expressive);
      visibility: visible;
    }

    .#{$prefix}--text-input,
    .#{$prefix}--select-input {
      background-color: $field-02;
    }
  }

  .#{$prefix}--modal--danger {
    @include modal--color($support-01);
  }

  .#{$prefix}--modal-container {
    position: relative;
    display: flex;
    flex-direction: column;
    background-color: $ui-01;
    width: 100%;
    max-height: 100%;
    height: 100%;

    @include carbon--breakpoint(md) {
      height: auto;
      width: 50%;
      max-width: 768px;
      max-height: 90%;
    }

    @include carbon--breakpoint(lg) {
      max-height: 80%;
    }
  }

  .#{$prefix}--modal-header,
  .#{$prefix}--modal-content {
    width: 75%;
    padding-left: 1rem;
  }

  .#{$prefix}--modal-header,
  .#{$prefix}--modal-footer {
    flex-shrink: 0;
  }

  .#{$prefix}--modal-header {
    padding-top: 1rem;
    margin-bottom: $carbon--spacing-05;
  }

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

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

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

    color: $text-01;
  }

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

    overflow-y: auto;
    margin-bottom: $carbon--spacing-09;
    color: $text-01;
    font-weight: 400;
  }

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

  .#{$prefix}--modal-footer {
    display: flex;
    margin-top: auto;
    height: 4rem;
    background-color: $modal-footer-background-color;

    button.#{$prefix}--btn {
      max-width: none;
      width: 50%;
      height: 4rem;
      margin: 0;
      padding-top: 1rem;
      padding-bottom: 2rem;
    }
  }

  .#{$prefix}--modal-close {
    position: absolute;
    top: 0;
    right: 0;
    height: 3rem;
    width: 3rem;
    padding: rem(12px);
    border: 2px solid transparent;
    overflow: hidden;
    cursor: pointer;
    background-color: transparent;

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

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

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

@include exports('modal') {
  @if feature-flag-enabled('components-x') {
    @include modal--x;
  } @else {
    @include modal;
  }
}
