// 附件预览组件
import React, { useContext } from 'react';
import { Tooltip } from 'antd';
import { DownloadOutlined, PaperClipOutlined, LockOutlined } from '@ant-design/icons';
import { useConfig } from "../_util/hooks";
import { FilePreview } from "../preview/index";
import Modal from "../modal";
import AudioPlayer from "./audio/index";
import VideoPlayer from "./video/index";
import { ConfigContext } from "../config-provider/context";
import "./index.less";
var FileLink = function FileLink(props) {
  var componentContext = useContext(ConfigContext);
  var uiLocale = componentContext.uiLocale;
  var name = props.name,
    url = props.url,
    transformId = props.transformId,
    canDownload = props.canDownload,
    playUrl = props.playUrl,
    _props$transformType = props.transformType,
    transformType = _props$transformType === void 0 ? '' : _props$transformType;

  // 加密|文件Icon
  var fileIcon = function fileIcon() {
    return /*#__PURE__*/React.createElement("span", {
      className: "fileIcon"
    }, canDownload ? /*#__PURE__*/React.createElement(PaperClipOutlined, null) : /*#__PURE__*/React.createElement(Tooltip, {
      title: uiLocale.Upload.lockTooltip
    }, /*#__PURE__*/React.createElement(LockOutlined, null)));
  };

  // 下载Icon
  var downloadIcon = function downloadIcon() {
    return url && /*#__PURE__*/React.createElement("a", {
      href: url,
      className: "link-icon",
      rel: "noreferrer",
      download: true
    }, /*#__PURE__*/React.createElement(DownloadOutlined, null));
  };

  // 渲染预览内容
  var renderContent = function renderContent() {
    // 文档预览
    if (transformType === 'KM' && transformId) return /*#__PURE__*/React.createElement(Document, props);

    // 音视频预览
    if (['YX_VIDEO', 'YX_AUDIO'].includes(transformType) && playUrl) return /*#__PURE__*/React.createElement(Player, props);
    return name;
  };
  return useConfig( /*#__PURE__*/React.createElement("div", {
    className: "m-file-link"
  }, fileIcon(), renderContent(), downloadIcon()));
};

// 文档预览
var Document = function Document(props) {
  var name = props.name,
    transformId = props.transformId,
    canDownload = props.canDownload,
    url = props.url;
  return /*#__PURE__*/React.createElement(Modal, {
    triggerDom: /*#__PURE__*/React.createElement("span", {
      className: "active"
    }, name),
    width: 1000,
    footer: null
  }, /*#__PURE__*/React.createElement(FilePreview, {
    file: {
      transformId: transformId,
      name: name,
      url: url
    },
    allowDownload: canDownload
  }));
};

// 音视频预览
var Player = function Player(props) {
  var name = props.name,
    transformType = props.transformType,
    playUrl = props.playUrl;
  if (!playUrl) return null;
  return /*#__PURE__*/React.createElement(Modal, {
    title: name,
    triggerDom: /*#__PURE__*/React.createElement("span", {
      className: "active"
    }, name),
    footer: null,
    width: 720
  }, transformType === 'YX_VIDEO' && /*#__PURE__*/React.createElement(VideoPlayer, {
    url: playUrl
  }), transformType === 'YX_AUDIO' && /*#__PURE__*/React.createElement(AudioPlayer, {
    url: playUrl
  }));
};
export default FileLink;