@import './var.less';

:root {
  --van-qr-scanner-background: @qr-scanner-background;
  --van-qr-scanner-text-color: @qr-scanner-text-color;
  --van-qr-scanner-frame-color: @qr-scanner-frame-color;
  --van-qr-scanner-frame-size: @qr-scanner-frame-size;
}

.van-qr-scanner {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-height: none;
  overflow: hidden;
  color: var(--van-qr-scanner-text-color);
  background: var(--van-qr-scanner-background);

  &__video,
  &__shade {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  &__video {
    object-fit: cover;
  }
  &__shade {
    background: linear-gradient(
      rgba(0, 0, 0, 0.6),
      transparent 30%,
      rgba(0, 0, 0, 0.7)
    );
  }

  &__header {
    position: relative;
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding-top: env(safe-area-inset-top, 0px);
  }

  &__title {
    padding: 0 52px;
    font-size: var(--van-font-size-lg);
    font-weight: var(--van-font-weight-bold);
    text-align: center;
  }

  &__close {
    position: absolute;
    bottom: 0;
    left: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 48px;
    padding: 0;
    color: inherit;
    background: transparent;
    border: 0;
    cursor: pointer;
  }

  &__viewfinder {
    position: relative;
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 16px;
  }

  &__frame {
    position: relative;
    flex: none;
    width: min(var(--van-qr-scanner-frame-size), 72vw, 40vh);
    height: min(var(--van-qr-scanner-frame-size), 72vw, 40vh);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;

    > i {
      position: absolute;
      width: 24px;
      height: 24px;
      border: 3px solid var(--van-qr-scanner-frame-color);

      &:nth-child(1) {
        top: -1px;
        left: -1px;
        border-right: 0;
        border-bottom: 0;
        border-top-left-radius: 12px;
      }
      &:nth-child(2) {
        top: -1px;
        right: -1px;
        border-bottom: 0;
        border-left: 0;
        border-top-right-radius: 12px;
      }
      &:nth-child(3) {
        bottom: -1px;
        right: -1px;
        border-top: 0;
        border-left: 0;
        border-bottom-right-radius: 12px;
      }
      &:nth-child(4) {
        bottom: -1px;
        left: -1px;
        border-top: 0;
        border-right: 0;
        border-bottom-left-radius: 12px;
      }
    }

    &--scanning::after {
      position: absolute;
      top: 12px;
      right: 12px;
      left: 12px;
      height: 2px;
      background: var(--van-qr-scanner-frame-color);
      box-shadow: 0 0 12px var(--van-qr-scanner-frame-color);
      content: '';
      animation: van-qr-scanner-line 2.2s ease-in-out infinite alternate;
    }
  }

  &__tip,
  &__message {
    margin: 20px 0 0;
    font-size: var(--van-font-size-md);
    line-height: 22px;
    text-align: center;
    overflow-wrap: anywhere;
  }

  &__status {
    position: relative;
    flex: none;
    min-height: 96px;
    padding: 0 24px 16px;
    text-align: center;

    .van-loading {
      color: inherit;
    }
    .van-loading__text {
      color: inherit;
    }
    .van-button {
      margin-top: 12px;
    }
  }

  &__message {
    margin: 0;
  }

  &__actions {
    position: relative;
    display: flex;
    flex: none;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px 24px;
    min-height: 88px;
    padding: 12px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  &__torch-hint {
    flex-basis: 100%;
    margin: 0;
    color: inherit;
    font-size: var(--van-font-size-sm);
    line-height: 20px;
    text-align: center;
    opacity: 0.7;
  }

  &__action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 72px;
    min-height: 64px;
    padding: 8px;
    color: inherit;
    font-size: var(--van-font-size-sm);
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;

    &--active {
      color: var(--van-qr-scanner-frame-color);
    }
    &:disabled {
      opacity: 0.5;
      cursor: default;
    }
  }

  &__close:active,
  &__action:not(:disabled):active {
    background: rgba(255, 255, 255, 0.1);
  }
  &__file-input {
    display: none;
  }
}

@keyframes van-qr-scanner-line {
  to {
    top: calc(100% - 12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .van-qr-scanner__frame--scanning::after {
    animation: none;
  }
}
