import { Image } from "antd";
import classNames from "clsx";
import React from "react";
import { PlaceholderContent } from "./PlaceholderContent";
var getPreviewErrorMessage = function getPreviewErrorMessage(category, locale) {
    var messages = {
        image: (locale === null || locale === void 0 ? void 0 : locale['workspace.file.cannotGetImagePreview']) || '无法获取图片预览',
        video: (locale === null || locale === void 0 ? void 0 : locale['workspace.file.cannotGetVideoPreview']) || '无法获取视频预览',
        audio: (locale === null || locale === void 0 ? void 0 : locale['workspace.file.cannotGetAudioPreview']) || '无法获取音频预览',
        pdf: (locale === null || locale === void 0 ? void 0 : locale['workspace.file.cannotGetPdfPreview']) || '无法获取PDF预览'
    };
    return messages[category];
};
/**
 * 媒体预览（图片 / 视频 / 音频 / PDF）
 *
 * - video / audio 默认禁用下载控件（`controlsList="nodownload"`）
 * - 视频补一条空 captions 轨道以满足 a11y
 */ export var MediaPreview = function MediaPreview(param) {
    var category = param.category, file = param.file, previewUrl = param.previewUrl, prefixCls = param.prefixCls, hashId = param.hashId, locale = param.locale;
    if (!previewUrl) {
        return /*#__PURE__*/ React.createElement(PlaceholderContent, {
            locale: locale,
            prefixCls: prefixCls,
            hashId: hashId
        }, /*#__PURE__*/ React.createElement("p", null, getPreviewErrorMessage(category, locale)));
    }
    if (category === 'image') {
        return /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-image"), hashId)
        }, /*#__PURE__*/ React.createElement(Image, {
            src: previewUrl,
            alt: file.name
        }));
    }
    if (category === 'video') {
        return /*#__PURE__*/ React.createElement("video", {
            className: classNames("".concat(prefixCls, "-video"), hashId),
            src: previewUrl,
            controls: true,
            controlsList: "nodownload",
            preload: "metadata"
        }, /*#__PURE__*/ React.createElement("track", {
            kind: "captions"
        }), (locale === null || locale === void 0 ? void 0 : locale['workspace.file.videoNotSupported']) || '您的浏览器不支持视频播放');
    }
    if (category === 'audio') {
        return /*#__PURE__*/ React.createElement("audio", {
            className: classNames("".concat(prefixCls, "-audio"), hashId),
            src: previewUrl,
            controls: true,
            controlsList: "nodownload",
            preload: "metadata"
        }, (locale === null || locale === void 0 ? void 0 : locale['workspace.file.audioNotSupported']) || '您的浏览器不支持音频播放');
    }
    // pdf
    return /*#__PURE__*/ React.createElement("embed", {
        className: classNames("".concat(prefixCls, "-pdf"), hashId),
        src: previewUrl,
        type: "application/pdf",
        width: "100%",
        height: "100%"
    });
};
