<template>
  <div class="security-apply-bar">
    <span>{{ $t('security.applyTip') }}</span>
    <div class="buttons">
      <div class="view-button" @click="showDialog(0)">{{ $t('security.exit') }}</div>
      <div class="view-button" @click="showDialog(1)">{{ $t('security.apply') }}</div>
    </div>
  </div>
</template>

<script setup>
import { useViewerStore } from '@/stores/modules/viewer'
import { useDocumentStore } from '@/stores/modules/document'
import core from '@/core'

const useViewer = useViewerStore()
const useDocument = useDocumentStore()

let redactionNumber = 0

const showDialog = (type) => {
  if (!redactionNumber) {
    useDocument.setToolState('')
    useViewer.setActiveToolMode('view')
    return
  }
  useViewer.setRedactionConfirmDialog(type)
}

const redactionChanged = (num) => {
  redactionNumber = num
}
core.addEvent('redactAnnotationChanged', redactionChanged)
</script>

<style lang="scss">
.security-apply-bar {
  position: relative;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 4;
  min-height: 48px;
  background: #DDE9FF;

  &.hidden {
    visibility: hidden;
    pointer-events: none;
    z-index: -1;
  }

  span {
    font-size: 14px;
    line-height: 16px;
    color: #001A4E;
  }

  .buttons {
    display: flex;
    align-items: center;
    margin-left: 8px;

    .view-button {
      padding: 8px 28px;
      height: 32px;
      border: 1px solid #1460F3;
      cursor: pointer;
      font-size: 14px;
      line-height: 16px;
      font-weight: 700;
      color: #1460F3;
      white-space: nowrap;

      &:hover {
        background: #1460F3;
        color: white;
      }

      &:first-child {
        margin-right: 8px;
      }
    }
  }
}

@media screen and (max-width: 500px) {
  .security-apply-bar {
    flex-direction: column;
    align-items: flex-end;

    > span {
      width: 100%;
    }

    .buttons {
      margin-left: 0;
      margin-top: 8px;
    }
  }
}
</style>

