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

@import 'carbon-components/scss/components/modal/modal';

:host(#{$prefix}-modal) {
  // `@extend .#{$prefix}--modal` seems to cause `&.is-visible` style to be brought into `:host(#{$prefix}-modal)` with ShadyCSS
  position: fixed;
  top: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  z-index: z('modal');
  display: flex;
  align-items: center;
  justify-content: center;
  content: '';
  background-color: $overlay;
  opacity: 0;
  visibility: hidden;
  transition: background-color $duration--slow-02 motion(exit, expressive),
    opacity $duration--moderate-02 motion(exit, expressive), z-index $duration--slow-02 motion(exit, expressive),
    visibility $duration--moderate-02 motion(exit, expressive);

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

  .#{$prefix}--modal-container {
    @include carbon--breakpoint(md) {
      ::slotted(#{$prefix}-modal-header),
      ::slotted(#{$prefix}-modal-body) {
        padding-right: 20%;
      }
    }
  }

  .#{$prefix}--modal-container--xs,
  .#{$prefix}--modal-container--sm,
  .#{$prefix}--modal-container--xl {
    ::slotted(#{$prefix}-modal-header) {
      padding-right: $spacing-09;
    }

    ::slotted(#{$prefix}-modal-body) {
      padding-right: $spacing-05;
    }
  }

  .#{$prefix}--modal-container--sm {
    @include carbon--breakpoint(xlg) {
      ::slotted(#{$prefix}-modal-header),
      ::slotted(#{$prefix}-modal-body) {
        padding-right: 20%;
      }
    }
  }

  .#{$prefix}--modal-container--lg {
    @include carbon--breakpoint(md) {
      ::slotted(#{$prefix}-modal-header),
      ::slotted(#{$prefix}-modal-body) {
        padding-right: 20%;
      }
    }
  }
}

:host(#{$prefix}-modal[open]) {
  @extend .#{$prefix}--modal, .is-visible;
}

:host(#{$prefix}-modal-header) {
  @extend .#{$prefix}--modal-header;
}

:host(#{$prefix}-modal-close-button) {
  outline: none;
}

:host(#{$prefix}-modal-heading),
:host(#{$prefix}-modal-label) {
  display: block;
}

:host(#{$prefix}-modal-heading) {
  @extend .#{$prefix}--modal-header__heading;
}

:host(#{$prefix}-modal-label) {
  @extend .#{$prefix}--modal-header__label;
}

:host(#{$prefix}-modal-body) {
  @extend .#{$prefix}--modal-content;
}

:host(#{$prefix}-modal-footer) {
  .#{$prefix}--modal-footer--three-button {
    ::slotted(#{$prefix}-btn),
    ::slotted(#{$prefix}-modal-footer-button) {
      flex: 0 1 25%;
    }
  }
}

:host(#{$prefix}-modal-footer) ::slotted(#{$prefix}-btn),
:host(#{$prefix}-modal-footer-button) {
  max-width: none;
  width: 50%;
  height: rem(64px);
  margin: 0;
}

:host(#{$prefix}-modal-footer-button) .#{$prefix}--btn {
  padding-top: rem(16px);
  padding-bottom: rem(32px);
  box-shadow: rem(-1px) 0 0 0 $button-separator;
}

:host(#{$prefix}-modal-footer-button:first-of-type) .#{$prefix}--btn {
  box-shadow: inherit;
}

:host(#{$prefix}-modal-footer-button) {
  &,
  &:first-of-type {
    .#{$prefix}--btn:focus {
      box-shadow: inset 0 0 0 $button-outline-width $focus, inset 0 0 0 $button-border-width $ui-background;
    }
  }
}
