function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
import { AudioOutlined, FileImageOutlined, FileTextFilled, VideoCameraOutlined } from "@ant-design/icons";
import { Popover, Tooltip } from "antd";
import React, { useContext, useMemo } from "react";
import { compileTemplate, I18nContext } from "../../I18n";
import { isMobileDevice } from "./utils";
var CONTENT_STYLE = {
    fontSize: 16,
    lineHeight: '1.5em',
    maxWidth: 275
};
export var SupportedFileFormats = {
    image: {
        icon: /*#__PURE__*/ React.createElement(FileImageOutlined, null),
        type: 'image',
        extensions: [
            'jpg',
            'jpeg',
            'png',
            'gif',
            'bmp',
            'webp',
            'svg'
        ]
    },
    document: {
        icon: /*#__PURE__*/ React.createElement(FileTextFilled, null),
        type: 'document',
        extensions: [
            'pdf',
            'markdown',
            'ppt',
            'html',
            'xls',
            'xlsx',
            'cs',
            'docx',
            'pptx',
            'xml'
        ]
    },
    audio: {
        icon: /*#__PURE__*/ React.createElement(AudioOutlined, null),
        type: 'audio',
        extensions: [
            'mp3',
            'wav'
        ]
    },
    video: {
        icon: /*#__PURE__*/ React.createElement(VideoCameraOutlined, null),
        type: 'video',
        extensions: [
            'mp4',
            'avi',
            'mov'
        ]
    }
};
var DEFAULT_FORMAT_MESSAGE = 'Supports ${extensions} formats.';
var buildFormatMessage = function buildFormatMessage(format, locale) {
    var _ref;
    var _format_extensions;
    var extensions = ((_format_extensions = format.extensions) === null || _format_extensions === void 0 ? void 0 : _format_extensions.join(', ')) || '';
    var template = (_ref = locale === null || locale === void 0 ? void 0 : locale['input.supportedFormatMessage']) !== null && _ref !== void 0 ? _ref : DEFAULT_FORMAT_MESSAGE;
    return compileTemplate(template, {
        extensions: extensions
    });
};
var FormatContent = function FormatContent(param) {
    var format = param.format, locale = param.locale;
    if (format.content) return /*#__PURE__*/ React.createElement(React.Fragment, null, format.content);
    return /*#__PURE__*/ React.createElement("div", {
        style: CONTENT_STYLE
    }, buildFormatMessage(format, locale));
};
export var AttachmentSupportedFormatsContent = function AttachmentSupportedFormatsContent(param) {
    var supportedFormat = param.supportedFormat, locale = param.locale;
    var format = supportedFormat || SupportedFileFormats.image;
    return /*#__PURE__*/ React.createElement(FormatContent, {
        format: format,
        locale: locale
    });
};
export var AttachmentButtonPopover = function AttachmentButtonPopover(param) {
    var children = param.children, supportedFormat = param.supportedFormat, localeProp = param.locale;
    var _useContext = useContext(I18nContext), contextLocale = _useContext.locale;
    var locale = localeProp !== undefined ? _object_spread({}, contextLocale, localeProp) : contextLocale;
    var isMobile = useMemo(function() {
        return isMobileDevice();
    }, []);
    // 移动设备无稳定 hover：点击时展示支持格式说明；上传仍由外层 click 统一触发。
    if (isMobile) {
        return /*#__PURE__*/ React.createElement(Popover, {
            trigger: "click",
            placement: "top",
            arrow: false,
            content: /*#__PURE__*/ React.createElement(AttachmentSupportedFormatsContent, {
                supportedFormat: supportedFormat,
                locale: locale
            })
        }, /*#__PURE__*/ React.createElement("span", {
            style: {
                display: 'inline-flex'
            }
        }, children));
    }
    return /*#__PURE__*/ React.createElement(Tooltip, {
        arrow: false,
        mouseEnterDelay: 1,
        trigger: "hover",
        title: /*#__PURE__*/ React.createElement(AttachmentSupportedFormatsContent, {
            supportedFormat: supportedFormat,
            locale: locale
        })
    }, /*#__PURE__*/ React.createElement("span", null, children));
};
export default AttachmentButtonPopover;
