import options from '@/utils/dict/options'
import { Base64 } from 'js-base64'
import PreviewImageDialog from '@/components/ImagePreview/PreviewImageDialog.vue'

export default {
  name: 'PreviewFile',
  props: {},
  methods: {
    previewFile(file = { fileType: null, fileUrl: null, fileFullName: null }) {
      const { fileType, fileUrl, fileFullName } = file
      if (fileUrl) {
        if (fileType === options.fileTypeMap.png.value) {
          this.$refs.previewImageDialogRef.handleOpen(fileUrl)
        } else {
          this.$router.push({ name: 'FilePreview', params: { fileUrl: `${encodeURIComponent(Base64.encode(fileUrl))}`, title: fileFullName }})
        }
      }
    }
  },
  render() {
    return <PreviewImageDialog ref='previewImageDialogRef' />
  }
}
