/*
  MODAL
  -----

  The humble modal hides off-canvas until summoned with an fa-open directive. Modals appear over an overlay that darkens the rest of the page, and have a maxmimum width. You can construct a grid inside a modal, or attach panels to it.

  Note that the modal overlay is hardcoded into the CSS, because whether or not you build your modal semantically, the overlay is always required and will always look the same.
*/
////
/// @group modal
////

// Modal
/// @type Color
$modal-background: #fff !default;
/// @type Number
$modal-border: 0 !default;
/// @type Number
$modal-radius: 0px !default;
/// @type Number
$modal-shadow: none !default;
/// @type Number
$modal-zindex: 1000 !default;
/// @type Map
$modal-sizes: (
  tiny: 300px,
  small: 500px,
  medium: 600px,
  large: 800px,
) !default;

/// @type String
$modal-overlay-class: 'modal-overlay' !default;
/// @type Color
$modal-overlay-background: rgba(#333, 0.7) !default;
///

%modal {
  position: relative;
  z-index: $modal-zindex + 1;
  background: $modal-background;
  flex: 0 0 auto;
  width: 100%;
  height: 100vh;
  max-height: 100%;
  overflow: hidden;
  padding: $global-padding;

  @include breakpoint(medium) {
    height: auto;
    max-width: map-get($modal-sizes, medium);
  }

  .grid-content, .grid-block {
    margin: 0;
  }

  .close-button, [fa-close] {
    z-index: $modal-zindex + 1;
  }
}

@mixin modal-dialog() {
  height: auto;
}
@mixin modal-layout(
  $width: map-get($modal-sizes, medium),
  $dialog: false
) {
  max-width: $width;
}
@mixin modal-style(
  $border: $modal-border,
  $radius: $modal-radius,
  $shadow: $modal-shadow
) {
  @if $border != 0 {
    border: $border;
  }
  @if $radius != 0px {
    border-radius: $radius;
  }
  @if $shadow != none {
    box-shadow: $shadow;
  }
}

@mixin modal(
  $width: map-get($modal-sizes, medium),
  $border: $modal-border,
  $radius: $modal-radius,
  $shadow: $modal-shadow
) {
  @extend %modal;
  @include modal-layout($width);
  @include modal-style($border, $radius, $shadow);
}

@include exports(modal) {
  .modal {
    @include modal;

    @each $size in map-keys($modal-sizes) {
      $width: map-get($modal-sizes, $size);
      @if $size != medium {
        .#{$size} > & { @include modal-layout($width); }
      }
    }

    .dialog > & {
      @include modal-dialog;
    }
    .collapse > & {
      padding: 0;
    }
  }

  .#{$modal-overlay-class} {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: $modal-zindex;
    display: none;
    background-color: $modal-overlay-background;

    // Horizontally and vertically center the modal
    align-items: center;
    justify-content: center;

    // Prevent z-index issue in Mobile Safari
    -webkit-transform: translate3d(0,0,0);

    &.is-active {
      display: flex;
    }
  }

  .confirm-modal, .prompt-modal {
    text-align: center;

    h1 {
      font-size: 2em;
      margin: 0 0 0.5rem 0;
    }
    p {
      margin: 0 0 0.5rem 0;
    }

    .button-row {
      overflow: visible;

      a {
        margin: 0;
      }
    }
  }
}
