function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
    try {
        var info = gen[key](arg);
        var value = info.value;
    } catch (error) {
        reject(error);
        return;
    }
    if (info.done) {
        resolve(value);
    } else {
        Promise.resolve(value).then(_next, _throw);
    }
}
function _async_to_generator(fn) {
    return function() {
        var self = this, args = arguments;
        return new Promise(function(resolve, reject) {
            var gen = fn.apply(self, args);
            function _next(value) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
            }
            function _throw(err) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
            }
            _next(undefined);
        });
    };
}
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 _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
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;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function _ts_generator(thisArg, body) {
    var f, y, t, _ = {
        label: 0,
        sent: function() {
            if (t[0] & 1) throw t[1];
            return t[1];
        },
        trys: [],
        ops: []
    }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
    return d(g, "next", {
        value: verb(0)
    }), d(g, "throw", {
        value: verb(1)
    }), d(g, "return", {
        value: verb(2)
    }), typeof Symbol === "function" && d(g, Symbol.iterator, {
        value: function() {
            return this;
        }
    }), g;
    function verb(n) {
        return function(v) {
            return step([
                n,
                v
            ]);
        };
    }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while(g && (g = 0, op[0] && (_ = 0)), _)try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [
                op[0] & 2,
                t.value
            ];
            switch(op[0]){
                case 0:
                case 1:
                    t = op;
                    break;
                case 4:
                    _.label++;
                    return {
                        value: op[1],
                        done: false
                    };
                case 5:
                    _.label++;
                    y = op[1];
                    op = [
                        0
                    ];
                    continue;
                case 7:
                    op = _.ops.pop();
                    _.trys.pop();
                    continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                        _ = 0;
                        continue;
                    }
                    if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
                        _.label = op[1];
                        break;
                    }
                    if (op[0] === 6 && _.label < t[1]) {
                        _.label = t[1];
                        t = op;
                        break;
                    }
                    if (t && _.label < t[2]) {
                        _.label = t[2];
                        _.ops.push(op);
                        break;
                    }
                    if (t[2]) _.ops.pop();
                    _.trys.pop();
                    continue;
            }
            op = body.call(thisArg, _);
        } catch (e) {
            op = [
                6,
                e
            ];
            y = 0;
        } finally{
            f = t = 0;
        }
        if (op[0] & 5) throw op[1];
        return {
            value: op[0] ? op[1] : void 0,
            done: true
        };
    }
}
import { DeleteFilled, EyeOutlined, LoadingOutlined } from "@ant-design/icons";
import { Modal, Popover, Skeleton } from "antd";
import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { useRefFunction } from "../../../../Hooks/useRefFunction";
import { useDebounceFn } from "@ant-design/pro-components";
import { Rnd } from "react-rnd";
import { Transforms } from "slate";
import { ActionIconBox } from "../../../../Components/ActionIconBox";
import { I18nContext } from "../../../../I18n";
import { useSelStatus } from "../../../hooks/editor";
import { AvatarList } from "../../components/ContributorAvatar";
import { MediaErrorLink } from "../../components/MediaErrorLink";
import { useEditorStore } from "../../store";
import { useGetSetState } from "../../utils";
import { getMediaType } from "../../utils/dom";
import { ReadonlyImage } from "../Image";
/**
 * 可调整大小的图片组件
 *
 * 功能特性：
 * - 支持拖拽调整图片尺寸
 * - 保持图片宽高比
 * - 加载状态处理
 * - 选中状态视觉反馈
 * - 响应式尺寸调整
 *
 * @param props - 组件属性
 * @returns 可调整大小的图片元素
 *
 * @example
 * ```tsx
 * <ResizeImage
 *   src="image.jpg"
 *   selected={true}
 *   defaultSize={{ width: 300, height: 200 }}
 *   onResizeStop={(size) => console.log('新尺寸:', size)}
 * />
 * ```
 */ export var ResizeImage = function ResizeImage(_0) {
    var onResizeStart = _0.onResizeStart, onResizeStop = _0.onResizeStop, selected = _0.selected, defaultSize = _0.defaultSize, props = _object_without_properties(_0, [
        "onResizeStart",
        "onResizeStop",
        "selected",
        "defaultSize"
    ]);
    var _React_useState = _sliced_to_array(React.useState(true), 2), loading = _React_useState[0], setLoading = _React_useState[1];
    var radio = useRef(1);
    var _React_useState1 = _sliced_to_array(React.useState({
        width: (defaultSize === null || defaultSize === void 0 ? void 0 : defaultSize.width) || 400,
        height: (defaultSize === null || defaultSize === void 0 ? void 0 : defaultSize.height) || 0
    }), 2), size = _React_useState1[0], setSize = _React_useState1[1];
    var imgRef = useRef(null);
    //@ts-expect-error
    var resize = useDebounceFn(function(size) {
        var _imgRef_current, _imgRef_current1;
        setSize({
            width: size.width,
            height: size.width / radio.current
        });
        (_imgRef_current = imgRef.current) === null || _imgRef_current === void 0 ? void 0 : _imgRef_current.style.setProperty('width', "".concat(size.width, "px"));
        (_imgRef_current1 = imgRef.current) === null || _imgRef_current1 === void 0 ? void 0 : _imgRef_current1.style.setProperty('height', "".concat((size.width || 0) / radio.current, "px"));
    }, 160);
    return /*#__PURE__*/ React.createElement("div", {
        "data-testid": "resize-image-container",
        style: {
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center',
            borderRadius: 4,
            overflow: 'hidden',
            width: size.width,
            height: size.height,
            maxWidth: '100%',
            boxSizing: 'border-box'
        }
    }, loading ? /*#__PURE__*/ React.createElement("div", {
        style: {
            width: '100px',
            height: '100px',
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center',
            background: 'rgba(0,0,0,0.05)',
            borderRadius: 12
        }
    }, /*#__PURE__*/ React.createElement(LoadingOutlined, {
        style: {
            fontSize: 24,
            color: '#1890ff'
        }
    })) : null, /*#__PURE__*/ React.createElement(Rnd, {
        onResizeStart: onResizeStart,
        onResizeStop: function onResizeStop1() {
            onResizeStop === null || onResizeStop === void 0 ? void 0 : onResizeStop(size);
        },
        default: {
            x: 0,
            y: 0,
            width: '100%',
            height: '100%'
        },
        size: size,
        disableDragging: true,
        style: {
            userSelect: 'none',
            WebkitUserSelect: 'none',
            MozUserSelect: 'none',
            msUserSelect: 'none'
        },
        onResize: function onResize(_, dir, ele) {
            var _imgRef_current, _imgRef_current1;
            (_imgRef_current = imgRef.current) === null || _imgRef_current === void 0 ? void 0 : _imgRef_current.style.setProperty('width', "".concat(ele.clientWidth, "px"));
            (_imgRef_current1 = imgRef.current) === null || _imgRef_current1 === void 0 ? void 0 : _imgRef_current1.style.setProperty('height', "".concat((ele.clientWidth || 0) / radio.current, "px"));
            resize.cancel();
            resize.run({
                width: ele.clientWidth,
                height: (ele.clientWidth || 0) / radio.current
            });
        }
    }, /*#__PURE__*/ React.createElement("img", _object_spread({
        "data-testid": "resize-image",
        draggable: false,
        onLoad: function onLoad(e) {
            setLoading(false);
            var width = e.target.naturalWidth;
            var height = e.target.naturalHeight;
            radio.current = width / height;
            var containerWidth = document.documentElement.clientWidth || window.innerWidth || 600;
            var maxAllowedWidth = Math.min(containerWidth * 0.9, 600);
            width = Math.min(width, maxAllowedWidth);
            setSize({
                width: width,
                height: width / radio.current
            });
        },
        alt: 'image',
        referrerPolicy: 'no-referrer',
        width: "min(".concat(size.width, "px, 100%)"),
        ref: imgRef,
        style: {
            width: '100%',
            height: 'auto',
            position: 'relative',
            zIndex: 99,
            outline: selected ? '2px solid #1890ff' : 'none',
            boxShadow: selected ? '0 0 0 2px #1890ff' : 'none',
            minHeight: 20,
            display: loading ? 'none' : 'block',
            userSelect: 'none',
            WebkitUserSelect: 'none',
            MozUserSelect: 'none',
            msUserSelect: 'none',
            pointerEvents: 'none'
        }
    }, props))));
};
export function Media(param) {
    var element = param.element, attributes = param.attributes, children = param.children;
    var _state, _state1;
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    var _useSelStatus = _sliced_to_array(useSelStatus(element), 2), _ = _useSelStatus[0], path = _useSelStatus[1];
    var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, readonly = _useEditorStore.readonly;
    var locale = useContext(I18nContext).locale;
    var htmlRef = React.useRef(null);
    var _useState = _sliced_to_array(useState(false), 2), showAsText = _useState[0], setShowAsText = _useState[1];
    var _useGetSetState = _sliced_to_array(useGetSetState({
        height: element.height,
        dragging: false,
        loadSuccess: true,
        url: '',
        selected: false,
        type: getMediaType(element === null || element === void 0 ? void 0 : element.url, element.alt)
    }), 2), state = _useGetSetState[0], setState = _useGetSetState[1];
    var updateElement = useRefFunction(function(attr) {
        if (!markdownEditorRef.current) return;
        Transforms.setNodes(markdownEditorRef.current, attr, {
            at: path
        });
    });
    // 如果 finished 为 false，设置 5 秒超时，超时后显示为文本
    useEffect(function() {
        if (element.finished === false) {
            setShowAsText(false);
            var timer = setTimeout(function() {
                setShowAsText(true);
            }, 5000);
            return function() {
                clearTimeout(timer);
            };
        } else {
            setShowAsText(false);
        }
    }, [
        element.finished
    ]);
    var initial = useRefFunction(function() {
        return _async_to_generator(function() {
            var type, finalType, realUrl, img, video, audio;
            return _ts_generator(this, function(_state) {
                type = getMediaType(element === null || element === void 0 ? void 0 : element.url, element.alt);
                type = !type ? 'image' : type;
                finalType = [
                    'image',
                    'video',
                    'autio',
                    'attachment'
                ].includes(type) ? type : 'other';
                setState({
                    type: finalType
                });
                realUrl = element === null || element === void 0 ? void 0 : element.url;
                setState({
                    url: realUrl
                });
                if (finalType === 'image' || finalType === 'other') {
                    img = document.createElement('img');
                    img.referrerPolicy = 'no-referrer';
                    img.crossOrigin = 'anonymous';
                    img.src = realUrl;
                    img.onerror = function() {
                        setState({
                            loadSuccess: false
                        });
                    };
                    img.onload = function() {
                        return setState({
                            loadSuccess: true
                        });
                    };
                }
                if (finalType === 'video') {
                    video = document.createElement('video');
                    video.src = realUrl;
                    video.preload = 'metadata';
                    video.onerror = function() {
                        setState({
                            loadSuccess: false
                        });
                    };
                    video.onloadedmetadata = function() {
                        setState({
                            loadSuccess: true
                        });
                    };
                }
                if (finalType === 'audio') {
                    audio = document.createElement('audio');
                    audio.src = realUrl;
                    audio.preload = 'metadata';
                    audio.onerror = function() {
                        setState({
                            loadSuccess: false
                        });
                    };
                    audio.onloadedmetadata = function() {
                        setState({
                            loadSuccess: true
                        });
                    };
                }
                if (!element.mediaType) {
                    updateElement({
                        mediaType: state().type
                    });
                }
                return [
                    2
                ];
            });
        })();
    });
    useLayoutEffect(function() {
        initial();
    }, [
        element === null || element === void 0 ? void 0 : element.url
    ]);
    var imageDom = useMemo(function() {
        var _state, _state1;
        if (state().type !== 'image' && state().type !== 'other') return null;
        // 检查是否为不完整的图片（finished 状态）
        if (element.finished === false) {
            // 如果 5 秒后仍未完成，显示为文本
            if (showAsText) {
                return /*#__PURE__*/ React.createElement("div", {
                    style: {
                        padding: '8px 12px',
                        border: '1px solid #d9d9d9',
                        borderRadius: '4px',
                        color: 'rgba(0, 0, 0, 0.65)',
                        wordBreak: 'break-all'
                    }
                }, element.alt || element.url || '图片链接');
            }
            // 5 秒内显示 loading 状态的占位符
            return /*#__PURE__*/ React.createElement(Skeleton.Image, {
                active: true
            });
        }
        return !readonly ? /*#__PURE__*/ React.createElement(ResizeImage, {
            defaultSize: {
                width: element.width,
                height: element.height
            },
            selected: state().selected,
            src: (_state = state()) === null || _state === void 0 ? void 0 : _state.url,
            onResizeStart: function onResizeStart() {
                setState({
                    selected: true
                });
            },
            onResizeStop: function onResizeStop(size) {
                Transforms.setNodes(markdownEditorRef.current, size, {
                    at: path
                });
                setState({
                    selected: false
                });
            }
        }) : /*#__PURE__*/ React.createElement(ReadonlyImage, {
            src: ((_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url) || (element === null || element === void 0 ? void 0 : element.url),
            alt: (element === null || element === void 0 ? void 0 : element.alt) || 'image',
            width: element.width,
            height: element.height,
            crossOrigin: "anonymous"
        });
    }, [
        state().type,
        (_state = state()) === null || _state === void 0 ? void 0 : _state.url,
        readonly,
        state().selected,
        element.finished,
        showAsText,
        element === null || element === void 0 ? void 0 : element.rawMarkdown
    ]);
    var mediaElement = useMemo(function() {
        var _element_otherProps;
        var rawMarkdown = (element === null || element === void 0 ? void 0 : element.rawMarkdown) || (element === null || element === void 0 ? void 0 : (_element_otherProps = element.otherProps) === null || _element_otherProps === void 0 ? void 0 : _element_otherProps.rawMarkdown);
        if (state().type === 'video') {
            var _state;
            // 如果是不完整状态
            if (element.finished === false) {
                // 如果 5 秒后仍未完成，显示为文本
                if (showAsText) {
                    return /*#__PURE__*/ React.createElement("div", {
                        style: {
                            padding: '8px 12px',
                            border: '1px solid #d9d9d9',
                            borderRadius: '4px',
                            color: 'rgba(0, 0, 0, 0.65)',
                            wordBreak: 'break-all'
                        }
                    }, element.alt || element.url || '视频链接');
                }
                // 5 秒内显示 loading 占位符
                return /*#__PURE__*/ React.createElement(Skeleton.Image, {
                    active: true
                });
            }
            if (!state().loadSuccess) {
                var _state1, _state2;
                return /*#__PURE__*/ React.createElement(MediaErrorLink, {
                    url: (_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url,
                    fallbackUrl: element === null || element === void 0 ? void 0 : element.url,
                    displayText: element.alt || ((_state2 = state()) === null || _state2 === void 0 ? void 0 : _state2.url) || (element === null || element === void 0 ? void 0 : element.url) || '视频链接'
                });
            }
            return /*#__PURE__*/ React.createElement("video", {
                "data-testid": "video-element",
                controls: element.controls !== false,
                autoPlay: element.autoplay,
                loop: element.loop,
                muted: element.muted,
                poster: element.poster,
                style: {
                    width: element.width ? "".concat(element.width, "px") : '100%',
                    height: element.height ? "".concat(element.height, "px") : 'auto',
                    maxWidth: '100%',
                    borderRadius: '6px',
                    boxShadow: '0 2px 8px rgba(0, 0, 0, 0.1)',
                    display: 'block'
                },
                src: ((_state = state()) === null || _state === void 0 ? void 0 : _state.url) || '',
                preload: "metadata",
                onError: function onError() {
                    var _state;
                    console.warn('Video failed to load:', (_state = state()) === null || _state === void 0 ? void 0 : _state.url);
                    setState({
                        loadSuccess: false
                    });
                }
            });
        }
        if (state().type === 'audio') {
            var _state3;
            // 如果是不完整状态
            if (element.finished === false) {
                // 如果 5 秒后仍未完成，显示为文本
                if (showAsText) {
                    return /*#__PURE__*/ React.createElement("div", {
                        style: {
                            padding: '8px 12px',
                            border: '1px solid #d9d9d9',
                            borderRadius: '4px',
                            color: 'rgba(0, 0, 0, 0.65)',
                            wordBreak: 'break-all'
                        }
                    }, element.alt || element.url || '音频链接');
                }
                // 5 秒内显示 loading 占位符
                return /*#__PURE__*/ React.createElement("div", {
                    style: {
                        display: 'inline-flex',
                        alignItems: 'center',
                        gap: '8px',
                        padding: '12px 16px',
                        border: '1px dashed #d9d9d9',
                        borderRadius: '6px',
                        backgroundColor: '#fafafa',
                        minWidth: '200px',
                        justifyContent: 'center'
                    }
                }, /*#__PURE__*/ React.createElement(LoadingOutlined, {
                    style: {
                        color: '#1890ff',
                        fontSize: '16px'
                    },
                    spin: true
                }), /*#__PURE__*/ React.createElement("span", {
                    style: {
                        color: '#666',
                        fontSize: '13px',
                        wordBreak: 'break-all'
                    }
                }, rawMarkdown || (element === null || element === void 0 ? void 0 : element.alt) || '音频加载中...'));
            }
            if (!state().loadSuccess) {
                var _state4, _state5;
                return /*#__PURE__*/ React.createElement(MediaErrorLink, {
                    url: (_state4 = state()) === null || _state4 === void 0 ? void 0 : _state4.url,
                    fallbackUrl: element === null || element === void 0 ? void 0 : element.url,
                    displayText: element.alt || ((_state5 = state()) === null || _state5 === void 0 ? void 0 : _state5.url) || (element === null || element === void 0 ? void 0 : element.url) || '音频链接'
                });
            }
            return /*#__PURE__*/ React.createElement("audio", {
                "data-testid": "audio-element",
                controls: true,
                style: {
                    width: '100%',
                    height: 'auto'
                },
                src: ((_state3 = state()) === null || _state3 === void 0 ? void 0 : _state3.url) || '',
                onError: function onError() {
                    var _state;
                    console.warn('Audio failed to load:', (_state = state()) === null || _state === void 0 ? void 0 : _state.url);
                    setState({
                        loadSuccess: false
                    });
                }
            }, "Your browser does not support the", /*#__PURE__*/ React.createElement("code", null, "audio"), " element.");
        }
        if (state().type === 'attachment') {
            var _state6, _element_alt, _element_alt1, _element_otherProps1, _element_otherProps_collaborators, _element_otherProps2, _element_otherProps3;
            return /*#__PURE__*/ React.createElement("div", {
                style: {
                    padding: 12,
                    boxSizing: 'border-box',
                    border: '1px solid #f0f0f0',
                    borderRadius: '0.5em',
                    width: '100%',
                    backgroundImage: 'linear-gradient(rgb(249, 251, 255) 0%, rgb(243, 248, 255) 100%)',
                    flex: 1,
                    display: 'flex',
                    alignItems: 'center',
                    gap: 12,
                    color: '#262626',
                    justifyContent: 'space-between'
                }
            }, /*#__PURE__*/ React.createElement("div", {
                style: {
                    display: 'flex',
                    alignItems: 'center',
                    gap: 12,
                    color: '#262626',
                    fontSize: 16,
                    flex: 1,
                    minWidth: 0
                }
            }, /*#__PURE__*/ React.createElement("div", {
                style: {
                    flex: 1,
                    minWidth: 0
                }
            }, /*#__PURE__*/ React.createElement("a", {
                href: (_state6 = state()) === null || _state6 === void 0 ? void 0 : _state6.url,
                style: {
                    overflow: 'ellipsis',
                    textOverflow: 'ellipsis',
                    textWrap: 'nowrap',
                    textDecoration: 'none',
                    display: 'block',
                    color: '#262626'
                },
                download: ((_element_alt = element.alt) === null || _element_alt === void 0 ? void 0 : _element_alt.replace('attachment:', '')) || 'attachment'
            }, ((_element_alt1 = element.alt) === null || _element_alt1 === void 0 ? void 0 : _element_alt1.replace('attachment:', '')) || 'attachment'), /*#__PURE__*/ React.createElement("div", {
                style: {
                    flex: 1,
                    minWidth: 0,
                    display: 'flex',
                    justifyContent: 'space-between'
                }
            }, ((_element_otherProps1 = element.otherProps) === null || _element_otherProps1 === void 0 ? void 0 : _element_otherProps1.collaborators) ? /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement(AvatarList, {
                displayList: ((_element_otherProps2 = element.otherProps) === null || _element_otherProps2 === void 0 ? void 0 : (_element_otherProps_collaborators = _element_otherProps2.collaborators) === null || _element_otherProps_collaborators === void 0 ? void 0 : _element_otherProps_collaborators.map(function(item) {
                    var _Object_keys, _Object_values;
                    return {
                        name: (_Object_keys = Object.keys(item)) === null || _Object_keys === void 0 ? void 0 : _Object_keys.at(0),
                        collaboratorNumber: ((_Object_values = Object.values(item)) === null || _Object_values === void 0 ? void 0 : _Object_values.at(0)) || 0
                    };
                }).slice(0, 5)) || []
            })) : /*#__PURE__*/ React.createElement("div", null), ((_element_otherProps3 = element.otherProps) === null || _element_otherProps3 === void 0 ? void 0 : _element_otherProps3.updateTime) ? /*#__PURE__*/ React.createElement("div", {
                style: {
                    color: 'rgba(0,0,0,0.45)',
                    fontSize: 12
                }
            }, element.otherProps.updateTime) : null))), /*#__PURE__*/ React.createElement("div", {
                "data-icon-box": true,
                style: {
                    padding: '0 18px'
                }
            }, /*#__PURE__*/ React.createElement(EyeOutlined, {
                onClick: function onClick() {
                    var _state;
                    if (typeof window === 'undefined') return;
                    window.open((_state = state()) === null || _state === void 0 ? void 0 : _state.url);
                },
                style: {
                    fontSize: 16,
                    cursor: 'pointer'
                }
            })));
        }
        return null;
    }, [
        state().type,
        (_state1 = state()) === null || _state1 === void 0 ? void 0 : _state1.url,
        element.finished,
        showAsText,
        element === null || element === void 0 ? void 0 : element.rawMarkdown
    ]);
    return /*#__PURE__*/ React.createElement("div", attributes, /*#__PURE__*/ React.createElement("div", {
        "data-be": "media",
        "data-drag-el": true,
        "data-testid": "media-container",
        style: {
            cursor: 'pointer',
            position: 'relative',
            display: 'flex',
            alignItems: 'flex-end',
            userSelect: 'none',
            WebkitUserSelect: 'none',
            MozUserSelect: 'none',
            msUserSelect: 'none',
            width: '100%',
            maxWidth: '100%',
            boxSizing: 'border-box'
        },
        draggable: false,
        onContextMenu: function onContextMenu(e) {
            e.stopPropagation();
        },
        onMouseDown: function onMouseDown(e) {
            e.stopPropagation();
        },
        onDragStart: function onDragStart(e) {
            e.preventDefault();
            e.stopPropagation();
        }
    }, /*#__PURE__*/ React.createElement(Popover, {
        arrow: false,
        styles: {
            body: {
                padding: 8
            }
        },
        trigger: "click",
        open: state().selected && !readonly ? undefined : false,
        content: /*#__PURE__*/ React.createElement(ActionIconBox, {
            title: (locale === null || locale === void 0 ? void 0 : locale.delete) || '删除',
            type: "danger",
            onClick: function onClick(e) {
                e.stopPropagation();
                Modal.confirm({
                    title: (locale === null || locale === void 0 ? void 0 : locale.deleteMedia) || '删除媒体',
                    content: (locale === null || locale === void 0 ? void 0 : locale.confirmDelete) || '确定删除该媒体吗？',
                    onOk: function onOk() {
                        Transforms.removeNodes(markdownEditorRef.current, {
                            at: path
                        });
                    }
                });
            }
        }, /*#__PURE__*/ React.createElement(DeleteFilled, null))
    }, /*#__PURE__*/ React.createElement("div", {
        onClick: function onClick() {
            setTimeout(function() {
                setState({
                    selected: true
                });
            }, 16);
        },
        tabIndex: -1,
        style: {
            color: 'transparent',
            padding: 4,
            userSelect: 'none',
            display: 'flex',
            flexDirection: 'column',
            width: mediaElement ? '100%' : undefined,
            maxWidth: '100%',
            boxSizing: 'border-box'
        },
        ref: htmlRef,
        draggable: false,
        contentEditable: false,
        "data-be": "media-container"
    }, mediaElement, imageDom, /*#__PURE__*/ React.createElement("div", {
        style: {
            display: 'none'
        }
    }, children)))));
}
