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;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
import { EditorUtils } from "../../utils";
import { decodeURIComponentUrl, findAttachment } from "./parseHtml";
/**
 * 处理图片节点
 * @param currentElement - 当前处理的图片元素，包含url和alt属性
 * @returns 返回格式化的图片节点对象
 */ export var handleImage = function(currentElement) {
    return EditorUtils.createMediaNode(decodeURIComponentUrl(currentElement === null || currentElement === void 0 ? void 0 : currentElement.url), 'image', {
        alt: currentElement.alt,
        finished: currentElement.finished
    });
};
/**
 * 处理附件链接
 */ export var handleAttachmentLink = function(currentElement) {
    var text = currentElement.children.map(function(n) {
        return n.value || '';
    }).join('');
    var attach = findAttachment(text);
    if (!attach) return null;
    var name = text.match(/>(.*)<\/a>/);
    return {
        type: 'attach',
        url: decodeURIComponentUrl(attach === null || attach === void 0 ? void 0 : attach.url),
        size: attach.size,
        children: [
            {
                type: 'card-before',
                children: [
                    {
                        text: ''
                    }
                ]
            },
            {
                type: 'card-after',
                children: [
                    {
                        text: ''
                    }
                ]
            }
        ],
        name: name ? name[1] : attach === null || attach === void 0 ? void 0 : attach.url
    };
};
/**
 * 处理链接卡片
 */ export var handleLinkCard = function(currentElement, config) {
    var _currentElement_children;
    var link = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.at(0);
    return _object_spread_props(_object_spread({}, config), {
        type: 'link-card',
        url: decodeURIComponentUrl(link === null || link === void 0 ? void 0 : link.url),
        children: [
            {
                type: 'card-before',
                children: [
                    {
                        text: ''
                    }
                ]
            },
            {
                type: 'card-after',
                children: [
                    {
                        text: ''
                    }
                ]
            }
        ],
        name: link.title
    });
};
