import { ConfigProvider } from "antd";
import classNames from "classnames";
import React, { useContext } from "react";
import { AvatarList } from "../../components/ContributorAvatar";
import { DragHandle } from "../../tools/DragHandle";
import { useStyle } from "./style";
export function LinkCard(param) {
    var element = param.element, attributes = param.attributes, children = param.children;
    var _element_otherProps, _element_otherProps_collaborators, _element_otherProps1, _element_otherProps2;
    var context = useContext(ConfigProvider.ConfigContext);
    var baseCls = context === null || context === void 0 ? void 0 : context.getPrefixCls('agentic-md-editor-link-card');
    var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var htmlRef = React.useRef(null);
    return wrapSSR(/*#__PURE__*/ React.createElement("div", attributes, /*#__PURE__*/ React.createElement("div", {
        className: classNames(baseCls, hashId),
        "data-be": "link-card",
        "data-drag-el": true,
        draggable: false,
        onContextMenu: function(e) {
            e.stopPropagation();
        },
        onMouseDown: function(e) {
            e.stopPropagation();
        },
        style: {
            display: 'flex'
        }
    }, /*#__PURE__*/ React.createElement("div", {
        style: {
            display: 'flex',
            height: '100%',
            minWidth: '0',
            fontSize: 60,
            minHeight: '100px',
            lineHeight: '100px'
        }
    }, children.at(0)), /*#__PURE__*/ React.createElement(DragHandle, null), /*#__PURE__*/ React.createElement("div", {
        ref: htmlRef,
        style: {
            flex: 1
        },
        onClick: function() {
            if (typeof window === 'undefined') return;
            window.open(element === null || element === void 0 ? void 0 : element.url);
        },
        className: classNames("".concat(baseCls, "-container"), hashId)
    }, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-container-content"), hashId),
        contentEditable: false
    }, element.icon ? /*#__PURE__*/ React.createElement("img", {
        className: classNames("".concat(baseCls, "-container-content-icon"), hashId),
        src: element.icon,
        width: 56
    }) : null, /*#__PURE__*/ React.createElement("div", {
        style: {
            flex: 1,
            minWidth: 0
        }
    }, /*#__PURE__*/ React.createElement("a", {
        href: element === null || element === void 0 ? void 0 : element.url,
        className: classNames("".concat(baseCls, "-container-content-title"), hashId),
        onClick: function(e) {
            e.stopPropagation();
            e.preventDefault();
            if (typeof window === 'undefined') return;
            window.open(element === null || element === void 0 ? void 0 : element.url);
        },
        download: element.title || element.name || 'no title'
    }, element.title || element.name || 'no title'), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-container-content-description"), hashId)
    }, element.description ? element.description : element === null || element === void 0 ? void 0 : element.url), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-container-content-collaborators"), hashId)
    }, ((_element_otherProps = element.otherProps) === null || _element_otherProps === void 0 ? void 0 : _element_otherProps.collaborators) ? /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement(AvatarList, {
        displayList: ((_element_otherProps1 = element.otherProps) === null || _element_otherProps1 === void 0 ? void 0 : (_element_otherProps_collaborators = _element_otherProps1.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_otherProps2 = element.otherProps) === null || _element_otherProps2 === void 0 ? void 0 : _element_otherProps2.updateTime) ? /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(baseCls, "-container-content-updateTime"), hashId),
        style: {
            color: 'rgba(0,0,0,0.45)',
            fontSize: 12
        }
    }, element.otherProps.updateTime) : null)))), /*#__PURE__*/ React.createElement("div", {
        style: {
            display: 'flex',
            height: '100%',
            minWidth: '4px',
            minHeight: '100px',
            fontSize: 60,
            lineHeight: '100px'
        }
    }, children.at(-1)))));
}
