@import '../../../styles/core.scss';

@mixin collapseChildContent {
  > :first-child { margin-top:    0 !important }
  > :last-child  { margin-bottom: 0 !important }
}

.Modal {
  $root: #{&}; // root class reference
  $is-closed: ":not(#{$root}_open)";

  & {
    color: get(color 'slate');
    margin: ms(10) auto;
    opacity: 1;
    padding: 0;
    transform: none;
    transform-origin: 50%;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
    @include collapseChildContent;

    #{$is-closed}>& {
      opacity: 0;
      pointer-events: none;
      transform: scale(.98);
    }

    &:focus {
      outline: 0;
    }
  }

  &_scrollable {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - #{ms(10) * 2});
    overflow: auto;
  }

  &_sm,
  &_md,
  &_lg {
    width: 100%;
  }

  &_sm {
    max-width: 320px;

    @media (max-width: 360px) {
      margin: 20px;
      max-height: calc(100vh - 40px);
      width: calc(100vw - 40px);
    }
  }

  &_md {
    max-width: 480px;

    @media (max-width: 520px) {
      margin: 20px;
      max-height: calc(100vh - 40px);
      width: calc(100vw - 40px);
    }
  }

  &_lg {
    max-width: 680px;

    @media (max-width: 720px) {
      margin: 20px;
      max-height: calc(100vh - 40px);
      width: calc(100vw - 40px);
    }
  }

  &-Header,
  &-Body,
  &-Footer {
    padding: 20px;
  }

  &-Header,
  &-Footer {
    flex: 0 0 auto;
  }

  &-Header {
    border-bottom: 1px solid get(color 'ivory');

    // reset title
    :global(.Title) {
      margin-top: 0;
    }

    &-Close {
      background: none;
      border: 0;
      color: get(color 'chalk');
      cursor: pointer;
      font-size: 16px;
      padding: 5px;

      &:hover,
      &:focus {
        color: get(color 'shale');
      }

      &:active {
        color: get(color 'red');
      }

      &:focus {
        outline: 0;
      }
    }
  }

  &-Body {
    flex: 1 1 auto;
    overflow-y: auto;
  }

  &-Footer {
    border-top: 1px solid get(color 'ivory');
  }

  @at-root :global(#{&}Wrapper) {
    background: rgba(#fff, 0.5);
    box-sizing: border-box;
    height: 100vh;
    left: 0;
    opacity: 1;
    overflow-x: hidden;
    overflow-y: auto;
    position: fixed;
    top: 0;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    width: 100vw;
    z-index: 10003; // toolbar is 10002, banners are 10001

    &#{$is-closed} {
      opacity: 0;
      pointer-events: none;
    }

    &_noDismiss:active .Modal:not(:active) {
      animation: shake 0.15s 2 cubic-bezier(0.16, 1, 0.3, 1);

      @keyframes shake {
        0% {
          transform: translateX(2px);
        }
        50% {
          transform: translateX(-2px);
        }
        100% {
          transform: none;
        }
      }
    }

    &_verticalCenter {
      align-items: center;
      display: flex;
    }
  }
}
