// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


// The opacity changes are only transitional. Once the `modalFadeOut` animation
// reaches the end, the Mithril component that renders .modal-backdrop
// (and .modal-dialog) is fully destroyed and removed from the DOM.
// We use keyframes+animation, rather than transition, because the former allow
// hooking the onanimationend events to synchronize the Mithril removal with
// the end of the CSS animation.
@keyframes modalFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-backdrop {
  position: absolute;
  z-index: 99;
  background-color: rgba(0, 0, 0, 0.6);
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  backdrop-filter: blur(2px);
  animation: modalFadeIn 0.25s var(--anim-easing);
  animation-fill-mode: both;

  &.modal-fadeout {
    animation: modalFadeOut 0.25s var(--anim-easing);
    animation-fill-mode: both;
  }
}

.modal-dialog {
  position: absolute;
  z-index: 100;
  border: 1px solid #333;
  background-color: #fff;
  margin: auto;
  min-width: 25vw;
  min-height: 10vh;
  padding: 30px;
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 4px;
  overflow-y: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: Roboto, sans-serif;
  font-weight: 300;

  &.modal-dialog-valign-top {
    top: 1rem;
    transform: translate(-50%, 0);
  }

  >header {
    display: flex;
    justify-content: space-between;
    align-items: center;

    h2 {
      margin-top: 0;
      margin-bottom: 0;
      font-family: 'Raleway', sans-serif;
      font-weight: 600;
      font-size: 1.25rem;
      line-height: 1.25;
      color: #262f3c;
      box-sizing: border-box;
    }

    button {
      background: transparent;
      border: 0;
    }
  }  // header

  main {
    font-size: 1rem;
    margin-top: 2rem;
    margin-bottom: 2rem;
    line-height: 1.5;
    color: rgba(0,0,0,.8);

    .small-font {
      font-size: 0.9rem;
    }
  }

  footer {
    display: flex;
    justify-content: space-around;
  }  // footer

  .modal-btn {
    font-size: .875rem;
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: .5rem;
    padding-bottom: .5rem;
    background-color: #e6e6e6;
    color: rgba(0,0,0,.8);
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    text-transform: none;
    overflow: visible;
    margin: 5px;
    transform: translateZ(0);
    transition: border-color .25s var(--anim-easing),
                background-color .25s var(--anim-easing);

    &:focus { border-color: #03A9F4;}
    &:hover { background-color: #ececec; }
  }

  .modal-btn-primary {
    background-color: hsl(215deg, 22%, 19%);
    color: #fff;
    &:hover { background-color: hsl(215deg, 22%, 35%) }
  }
}

.help {
  table {
    margin-bottom: 15px;
    td {
      min-width: 250px;
    }
    td:first-child {
      font-family: var(--monospace-font);
    }
  }
  h2 {
    font: inherit;
    font-weight: bold;
  }
}

.modal-pre {
  white-space: pre-line;
  font-size: 13px;
}

.modal-logs, .modal-bash {
  white-space: pre-wrap;
  border: 1px solid #999;
  background: #eee;
  font-size: 10px;
  font-family: var(--monospace-font);
  margin-top: 10px;
  margin-bottom: 10px;
  min-height: 50px;
  max-height: 40vh;
  overflow: auto;
}

.modal-bash {
  margin: 0;
  padding: 5px 0;
  overflow: auto;
  min-height: 0;
}

.modal-textarea {
  display: block;
  margin-top: 10px;
  margin-bottom: 10px;
  width: 100%;
}

.modal-small {
  font-size: 0.75rem;
}
