<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="文件内容查看" :centered="true" width="80%" :useWrapper="true" :footer="null">
    <div style="background-color: #ececec; padding: 5px">
      <div :style="{ overflow: 'hidden', height: '85vh' }">
        <FileViewer ref="refFileViewer" :useStaticPrefixForDocx="useStaticPrefixForDocx" />
      </div>
    </div>
  </BasicModal>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import FileViewer from './FileViewer.vue';

  const props = withDefaults(defineProps<{
    useStaticPrefixForDocx?: boolean;
  }>(), {
    useStaticPrefixForDocx: false,
  });

  const refFileViewer = ref();

  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    const { showFooter, record } = data || {};
    const { filePath, fpath } = record || {};

    setModalProps({
      confirmLoading: false,
      showCancelBtn: !!showFooter,
      showOkBtn: !!showFooter,
    });

    if (filePath || fpath ) {
      refFileViewer.value.setDocFile(record);
    }
  });

  defineExpose({
    closeModal,
  });
</script>

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