@import (reference) '../../styles/variables.less';

.@{prefix}-previewer {
  @error-bar-height: 30px;

  margin: 24px 0 32px;
  border: 1px solid @c-border-light;
  border-radius: 4px;
  background-color: inherit;

  @{dark-selector} & {
    border-color: @c-border-less-dark;
  }

  [data-dumi-demo-grid] & {
    margin: 0 0 16px;

    &:first-child {
      margin-top: 24px;
    }

    &:last-child {
      margin-bottom: 32px;
    }
  }

  &-demo {
    border-top-left-radius: 2px;
    border-top-right-radius: 2px;
    padding: 40px 24px;

    > iframe {
      display: block;
      width: 100%;
      height: 300px;
      border: 0;
    }

    // demo render controls
    &[data-iframe] {
      position: relative;
      padding: 0;
      border-top: 24px solid @c-border-light;
      box-sizing: border-box;

      @{dark-selector} & {
        border-top-color: @c-border-less-dark;
      }

      &::after {
        @btn-gap: 8px;
        @btn-width: 12px;

        content: '';
        position: absolute;
        top: -19px;
        left: @btn-gap;
        display: inline-block;
        width: @btn-width;
        height: @btn-width;
        border-radius: 50%;
        background-color: #fd6458;
        box-shadow: (@btn-width + @btn-gap) 0 0 #ffbf2b,
          (@btn-width + @btn-gap) * 2 0 0 #24cc3d;
      }
    }

    &[data-transform] {
      transform: translate(0, 0);
    }

    &[data-compact] {
      padding: 0;
    }

    // error status
    &[data-error][data-compact] {
      min-height: @error-bar-height;

      + .@{prefix}-previewer-demo-error {
        border-top-left-radius: 3px;
        border-top-right-radius: 3px;
      }
    }

    // loading status
    &[data-loading] {
      position: relative;

      &::before {
        @size: 28px;

        position: absolute;
        top: 50%;
        left: 50%;
        content: '';
        display: block;
        height: @size;
        max-height: 90%;
        aspect-ratio: 1;
        border-radius: 50%;
        border: (@size / 10) solid;
        border-color: @c-primary transparent;
        box-sizing: border-box;
        animation: dumi-previewer-loading 1s infinite;
        transform: translate(-50%, -50%);

        @{dark-selector} & {
          border-color: @c-primary-dark transparent;
        }

        @keyframes dumi-previewer-loading {
          to {
            transform: translate(-50%, -50%) rotate(0.5turn);
          }
        }
      }

      > * {
        opacity: 0.3 !important;
      }
    }
  }

  &-demo-error {
    @color: darken(desaturate(@c-error, 20%), 1%);

    position: relative;
    margin-top: -@error-bar-height;
    height: @error-bar-height;
    padding: 0 24px;
    line-height: @error-bar-height;
    color: @color;
    font-size: 13px;
    white-space: nowrap;
    text-overflow: ellipsis;
    background: lighten(@c-error, 51%);
    box-sizing: border-box;
    overflow: hidden;

    @{dark-selector} & {
      @color: lighten(desaturate(@c-error, 20%), 5%);

      color: @color;
      background: darken(@c-error-dark, 22%);

      > svg {
        fill: @color;
      }
    }

    > svg {
      width: 14px;
      padding-right: 4px;
      fill: @c-error;
      vertical-align: -0.14em;
    }
  }

  &-meta {
    border-top: 1px solid @c-border-light;

    @{dark-selector} & {
      border-top-color: @c-border-less-dark;
    }
  }

  &-desc {
    position: relative;

    > .markdown {
      padding: 14px 24px;
      border-bottom: 1px dashed @c-border-light;

      @{dark-selector} & {
        border-bottom-color: @c-border-less-dark;
      }
    }

    > h5 {
      position: absolute;
      top: -7px;
      left: 20px;
      margin: 0;
      padding: 0 4px;
      display: inline-block;
      font-size: 14px;
      line-height: 1;
      font-weight: bold;
      background: linear-gradient(
          to top,
          rgba(255, 255, 255, 100%),
          rgba(255, 255, 255, 100%) 50%,
          rgba(255, 255, 255, 0%)
        )
        100%;

      @{dark-selector} & {
        background: linear-gradient(
            to top,
            rgba(0, 0, 0, 95%),
            rgba(0, 0, 0, 95%) 50%,
            rgba(0, 0, 0, 0%)
          )
          100%;
      }

      > a {
        color: @c-text;

        @{dark-selector} & {
          color: @c-text-dark;
        }

        &:not(:hover) {
          text-decoration: none;
        }

        > strong {
          float: inline-start;
          padding-inline-end: 8px;
          color: @c-warning;
          font-size: 12px;
          line-height: 15px;

          @{dark-selector} & {
            color: @c-warning-dark;
          }
        }
      }
    }
  }
  // active
  &[data-active] {
    box-shadow: 0 0 0 4px fade(@c-primary, 10%);
    border-color: lighten(@c-primary, 20%);

    @{dark-selector} & {
      box-shadow: 0 0 0 4px fade(@c-primary-dark, 10%);
      border-color: darken(@c-primary-dark, 20%);
    }
  }

  // debug mode
  &[data-debug] {
    border-color: lighten(@c-warning, 20%);

    @{dark-selector} & {
      border-color: darken(@c-warning-dark, 20%);
    }

    &[data-active] {
      box-shadow: 0 0 0 4px fade(@c-warning, 10%);

      @{dark-selector} & {
        box-shadow: 0 0 0 4px fade(@c-warning-dark, 10%);
      }
    }
  }
}
