/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
@import "../icons/variables";
@import "../inputs/variables";
@import "../style/typography";
@import "../style/themecolors";
@import "../style/variables";
@import "../text/block";
@import "../text/leading";
@import "../z-index";
@import "../scrollbar";

// cspell:ignore titlebar outoffocus nwse

.core-dialog {
  @include uicore-font-family;

  display: none;
  position: fixed;

  @include uicore-z-index(dialog);

  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  overflow: auto;
  background: rgba(0, 0, 0, 0.4);

  &.core-dialog-opened {
    display: block;
  }

  &.core-dialog-hidden {
    width: 0;
    height: 0;
  }

  .core-dialog-container {
    position: fixed;

    &.core-dialog-top-left {
      top: 0;
      left: 0;
    }

    &.core-dialog-top {
      top: 0;
      left: 0;
      right: 0;
    }

    &.core-dialog-top-right {
      top: 0;
      right: 0;
    }

    &.core-dialog-left {
      left: 0;
      top: 50%;
      transform: translateY(-50%);
    }

    &.core-dialog-center {
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    &.core-dialog-right {
      right: 0;
      top: 50%;
      transform: translateY(-50%);
    }

    &.core-dialog-bottom-left {
      bottom: 0;
      left: 0;
    }

    &.core-dialog-bottom {
      bottom: 0;
      left: 0;
      right: 0;
    }

    &.core-dialog-bottom-right {
      bottom: 0;
      right: 0;
    }

    margin: auto;
    width: 60%;
    display: flex;
    flex-direction: column;
    height: fit-content;

    .core-dialog-area {
      position: relative;
      display: flex;
      flex-grow: 1;
      flex-direction: column;
      border: 1px solid $buic-background-dialog-stroke;
      border-radius: $uicore-border-radius;
      background-color: $buic-background-dialog;
      color: $buic-text-color;
      padding: 0;

      > .core-dialog-head {
        flex-shrink: 0;
        align-items: center;
        background-color: $buic-background-titlebar; /* $buic-background-titlebar-outoffocus; */
        color: $buic-text-color;
        display: flex;
        padding: 4px;

        /* padding: $uicore-unbordered-padding; */
        &.core-dialog-movable {
          cursor: move;
        }

        > .core-dialog-title {
          flex: 1 1;

          @include uicore-text-leading;

          margin: 0;
          margin-left: 4px;
        }

        > .core-dialog-close {
          cursor: pointer;
          height: $uicore-font-size-title;
          width: $uicore-font-size-title;
          line-height: $uicore-font-size-title;
          flex: 0 0 $uicore-icons-medium;
          text-align: center;
          color: $buic-text-color-muted;
          border: none;
          background-color: transparent;

          &:hover,
          &:focus {
            color: $buic-foreground-activehover;
          }
          &:focus {
            outline: 1px solid $buic-foreground-focus;
          }
        }
      }

      > .core-dialog-content {
        overflow: auto;
        flex: 1 1;

        @include uicore-text-block;

        padding: $uicore-unbordered-padding;
        margin: 0;

        @include uicore-touch-scrolling;
        @include uicore-scrollbar();

        &.core-dialog-content-no-inset {
          padding: 0;
        }
      }

      > .core-dialog-footer {
        flex-shrink: 0;
        padding: 0 $uicore-unbordered-padding $uicore-unbordered-padding
          $uicore-unbordered-padding;

        > .core-dialog-buttons {
          display: flex;
          justify-content: flex-end;

          > * {
            min-width: 80px;

            &:not(:first-child) {
              margin-left: $uicore-inputs-margin;
            }
          }
        }
      }

      /*
      &:focus-within {
        .core-dialog-head {
          background-color: $buic-background-titlebar;
        }
      }
      */
    }

    $dialog-resize-bar-width: 8px;

    .core-dialog-drag {
      position: absolute;
      z-index: auto;
      padding: 0px;

      &:not(.core-dialog-drag-enabled) {
        display: none;
      }

      &.core-dialog-drag-right {
        right: -$dialog-resize-bar-width * 0.5;
        width: $dialog-resize-bar-width;
        height: 100%;
        cursor: ew-resize;
      }

      &.core-dialog-drag-bottom-mid {
        bottom: -$dialog-resize-bar-width * 0.5;
        height: $dialog-resize-bar-width;
        width: 100%;
        cursor: ns-resize;
      }

      &.core-dialog-drag-bottom-right {
        right: -$dialog-resize-bar-width * 0.5;
        bottom: -$dialog-resize-bar-width * 0.5;
        height: $dialog-resize-bar-width;
        width: $dialog-resize-bar-width;
        cursor: nwse-resize;
      }
    }
  }
}
