<template>
  <iframe :src="url" width="100%" height="800px"></iframe>
</template>

<script setup>
import { ref, watchEffect } from 'vue'
import { textbookPreview } from '@/apis/textbook'
import { resourcePreview } from '@/apis/catalogResource'
import { Base64 } from 'js-base64'

const props = defineProps({
  id: Number,
  type: String,
  fileSuffix: String
})

const preViewUrl = 'http://101.37.69.204:8012/onlinePreview'
const url = ref()
const previewFile = async () => {

  let fileRes
  if (props.type == 'textbook') {
    fileRes = await textbookPreview(props.id)
    url.value = `${preViewUrl}?url=${encodeURIComponent(Base64.encode(fileRes.data))}`
  }
  if (props.type == 'resource') {
    fileRes = await resourcePreview(props.id)
    url.value = `${preViewUrl}?url=${encodeURIComponent(Base64.encode(fileRes.data))}`
  }
  console.log(url.value);

}

watchEffect(() => {
  previewFile()
})
</script>

<style lang="scss" scoped></style>