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 { ExclamationCircleOutlined } from "@ant-design/icons";
import { SquareArrowUpRight } from "@sofa-design/icons";
import React from "react";
import { useEditorStore } from "../store";
/**
 * 媒体加载失败时的错误链接组件
 *
 * 当图片、视频或音频加载失败时，显示一个可点击的链接
 * 支持自定义链接点击行为和打开方式
 *
 * @param props - 组件属性
 * @returns 错误链接元素
 *
 * @example
 * ```tsx
 * <MediaErrorLink
 *   url="https://example.com/image.jpg"
 *   displayText="图片链接"
 * />
 * ```
 */ var MediaErrorLinkComponent = function MediaErrorLinkComponent(param) {
    var url = param.url, fallbackUrl = param.fallbackUrl, displayText = param.displayText, style = param.style;
    var editorProps = useEditorStore().editorProps;
    var handleClick = function handleClick(e) {
        var _editorProps_linkConfig, _editorProps_linkConfig1;
        var finalUrl = url || fallbackUrl;
        if (!finalUrl) return;
        e.stopPropagation();
        e.preventDefault();
        if ((_editorProps_linkConfig = editorProps.linkConfig) === null || _editorProps_linkConfig === void 0 ? void 0 : _editorProps_linkConfig.onClick) {
            if (editorProps.linkConfig.onClick(finalUrl) === false) {
                return;
            }
        }
        if ((editorProps === null || editorProps === void 0 ? void 0 : (_editorProps_linkConfig1 = editorProps.linkConfig) === null || _editorProps_linkConfig1 === void 0 ? void 0 : _editorProps_linkConfig1.openInNewTab) !== false) {
            window.open(finalUrl, '_blank');
        } else {
            window.open(finalUrl, '_self');
        }
    };
    return /*#__PURE__*/ React.createElement("span", {
        onClick: handleClick,
        style: _object_spread({
            color: '#1890ff',
            textDecoration: 'underline',
            wordBreak: 'break-all',
            display: 'inline-flex',
            alignItems: 'center',
            gap: '8px',
            maxWidth: '100%',
            padding: '8px 12px',
            border: '1px dashed #d9d9d9',
            borderRadius: '6px',
            backgroundColor: '#fafafa'
        }, style)
    }, /*#__PURE__*/ React.createElement(ExclamationCircleOutlined, {
        style: {
            color: '#faad14'
        }
    }), displayText, /*#__PURE__*/ React.createElement(SquareArrowUpRight, null));
};
export var MediaErrorLink = /*#__PURE__*/ React.memo(MediaErrorLinkComponent);
