import { defineComponent, computed, resolveComponent, createElementBlock, openBlock, createElementVNode, renderSlot, normalizeStyle, Fragment, createBlock } from 'vue';
import { isImageUrl, isVideoUrl, isPDF, isText, isWord, isExcel, isPPT, isZip, isPSD } from '../../../../utils/src/is.mjs';
import { fileComponentProps } from './fileComponent.mjs';

const _hoisted_1 = { class: "gm-flex gm-h-full gm-w-full gm-flex-col gm-items-center gm-justify-center" };
const _hoisted_2 = ["src"];
const _hoisted_3 = ["src", "controls", "controlslist", "oncontextmenu"];
const _hoisted_4 = ["src"];
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "GmFileComponent"
  },
  __name: "FileComponent",
  props: fileComponentProps,
  setup(__props) {
    const props = __props;
    const iconStyle = computed(() => {
      return {
        width: `${props.size}px`,
        height: `${props.size}px`
      };
    });
    const fileStyle = computed(() => {
      return {
        width: props.fileWidth,
        height: props.fileHeight,
        ...props.fileStyle
      };
    });
    const fileURL = computed(() => {
      return props.file[props.url];
    });
    const verifyFile = computed(() => {
      return props.file[props.field];
    });
    const isImageFile = computed(() => isImageUrl(fileURL.value) || isImageUrl(verifyFile.value));
    const isVideoFile = computed(() => isVideoUrl(fileURL.value) || isVideoUrl(verifyFile.value));
    const showIframe = computed(() => {
      return isPDF(fileURL.value) || isPDF(verifyFile.value) || isText(fileURL.value) || isText(verifyFile.value);
    });
    const iconList = {
      excel: "https://sucai.giikin.cn/workflow/material-refer-1739947054012-1213-335.svg",
      pdf: "https://sucai.giikin.cn/workflow/material-refer-1739947288698-5462-586.svg",
      word: "https://sucai.giikin.cn/workflow/material-refer-1739947288698-1540-625.svg",
      txt: "https://sucai.giikin.cn/workflow/material-refer-1739947288698-1700-90.svg",
      zip: "https://sucai.giikin.cn/workflow/material-refer-1739947288698-2639-507.svg",
      psd: "https://sucai.giikin.cn/workflow/material-refer-1739947288698-5026-760.svg",
      ppt: "https://sucai.giikin.cn/workflow/material-refer-1739947288698-2867-970.svg",
      unknown: "https://sucai.giikin.cn/workflow/material-refer-1739947288698-1448-736.svg"
    };
    const iconURL = computed(() => {
      const typeCheckers = [
        { check: () => isPDF(fileURL.value) || isPDF(verifyFile.value), icon: iconList.pdf },
        { check: () => isWord(fileURL.value) || isWord(verifyFile.value), icon: iconList.word },
        { check: () => isExcel(fileURL.value) || isExcel(verifyFile.value), icon: iconList.excel },
        { check: () => isText(fileURL.value) || isText(verifyFile.value), icon: iconList.txt },
        { check: () => isPPT(fileURL.value) || isPPT(verifyFile.value), icon: iconList.ppt },
        { check: () => isZip(fileURL.value) || isZip(verifyFile.value), icon: iconList.zip },
        { check: () => isPSD(fileURL.value) || isPSD(verifyFile.value), icon: iconList.psd }
      ];
      const matchedType = typeCheckers.find(({ check }) => check());
      return matchedType?.icon || iconList.unknown;
    });
    const handleClick = () => {
      if (!props.onClick) return;
      props.onClick(props.file);
    };
    return (_ctx, _cache) => {
      const _component_el_image = resolveComponent("el-image");
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode(
          "div",
          {
            class: "gm-flex gm-items-center gm-justify-center",
            style: normalizeStyle(fileStyle.value),
            onClick: handleClick
          },
          [
            isImageFile.value ? (openBlock(), createElementBlock("img", {
              key: 0,
              src: fileURL.value,
              fit: "contain",
              style: { "max-width": "100%", "max-height": "100%" }
            }, null, 8, _hoisted_2)) : isVideoFile.value ? (openBlock(), createElementBlock("video", {
              key: 1,
              src: fileURL.value,
              controls: _ctx.controls,
              controlslist: _ctx.controlslist,
              oncontextmenu: () => _ctx.oncontextmenu,
              style: { "max-width": "100%", "max-height": "100%" }
            }, null, 8, _hoisted_3)) : (openBlock(), createElementBlock(
              Fragment,
              { key: 2 },
              [
                _ctx.showIcon || !showIframe.value ? (openBlock(), createBlock(_component_el_image, {
                  key: 0,
                  style: normalizeStyle(iconStyle.value),
                  src: iconURL.value
                }, null, 8, ["style", "src"])) : (openBlock(), createElementBlock("iframe", {
                  key: 1,
                  src: fileURL.value,
                  width: "850px",
                  height: "100%",
                  frameborder: "0"
                }, null, 8, _hoisted_4))
              ],
              64
              /* STABLE_FRAGMENT */
            ))
          ],
          4
          /* STYLE */
        ),
        renderSlot(_ctx.$slots, "default", { file: _ctx.file })
      ]);
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=FileComponent.vue2.mjs.map
