<template>
  <div v-if="content">
    <span @click.stop="clickHandler">
      <slot />
    </span>
    <q-dialog
      v-model="dialog"
      full-height
      full-width
      @show="generatePreview"
      @hide="clearModel"
    >
      <q-card class="PreviewDialog">
        <q-card-section
          class="PreviewDialog__Section PreviewDialog__Header"
          :class="{ PreviewDialog__Header_Hidden: isPrint }"
        >
          <div class="PreviewDialog__HeaderContent">
            {{ $t('base.preview.dialog.title') }}
            <q-btn
              flat
              round
              icon="pgs-print"
              size="12px"
              text-color="#1491CF"
              @click="startPrint"
            />
          </div>
          <q-btn
            flat
            round
            icon="pgs-close"
            size="sm"
            text-color="#1491CF"
            v-close-popup
          />
        </q-card-section>
        <q-card-section class="PreviewDialog__Section PreviewDialog__Content">
          <div ref="fileContainer" class="PreviewDialog__Ref"></div>
        </q-card-section>
        <q-inner-loading :showing="loading">
          <q-spinner-gears color="primary" size="50px" />
        </q-inner-loading>
      </q-card>
    </q-dialog>
  </div>
</template>

<script lang="ts" src="./index.ts" />

<style lang="scss" scoped>
.PreviewDialog {
  display: flex;
  flex-flow: column;
  box-shadow: none;
  &__Section {
    display: flex;
    flex-flow: row;
  }
  &__Header {
    padding-bottom: 0;
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 2rem;
    letter-spacing: 0.0125em;
    display: flex;
    justify-content: space-between;

    &_Hidden {
      display: none;
    }
  }
  &__Content {
    flex: 1 1 auto;
    position: relative;
  }
  &__Ref {
    width: 100%;
    height: 100%;
  }
  &__Container {
    position: absolute;
    overflow-y: scroll;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
  }
  &__Pre {
    margin: 0;
  }
}
</style>
