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 { Download as DownloadIcon, Eye as EyeIcon, Locate, SquareArrowOutUpRight as ShareIcon } from "@sofa-design/icons";
import classNames from "clsx";
import React, { memo } from "react";
import { ActionIconBox } from "../../../Components/ActionIconBox";
import { shouldShowFileDownloadAction, shouldShowFilePreviewAction } from "../fileListRowActions";
import { ensureNodeWithId, handleDefaultShare, handleFileDownload } from "../handlers";
var FileTreeLeafTitleComponent = function FileTreeLeafTitleComponent(param) {
    var node = param.node, prefixCls = param.prefixCls, hashId = param.hashId, locale = param.locale, onDownload = param.onDownload, onPreview = param.onPreview, onShare = param.onShare, onLocate = param.onLocate;
    var _node_file_name, _ref, _node_file_id;
    var fileWithId = ensureNodeWithId(_object_spread_props(_object_spread({}, node.file), {
        name: (_node_file_name = node.file.name) !== null && _node_file_name !== void 0 ? _node_file_name : node.name,
        id: (_ref = (_node_file_id = node.file.id) !== null && _node_file_id !== void 0 ? _node_file_id : node.id) !== null && _ref !== void 0 ? _ref : node.key
    }));
    var isDisabled = node.disabled === true;
    var showDownloadButton = shouldShowFileDownloadAction(fileWithId, onDownload);
    var handleDownload = function handleDownload(e) {
        e.stopPropagation();
        if (onDownload) {
            onDownload(fileWithId);
            return;
        }
        handleFileDownload(fileWithId);
    };
    var handlePreview = function handlePreview(e) {
        e.stopPropagation();
        void (onPreview === null || onPreview === void 0 ? void 0 : onPreview(fileWithId));
    };
    var handleShare = function handleShare(e) {
        e.stopPropagation();
        if (onShare) {
            onShare(fileWithId, {
                anchorEl: e.currentTarget,
                origin: 'list'
            });
            return;
        }
        handleDefaultShare(fileWithId);
    };
    var showPreviewButton = shouldShowFilePreviewAction(fileWithId, onPreview);
    var showShareButton = fileWithId.canShare === true;
    var showLocationButton = fileWithId.canLocate === true;
    var handleLocate = function handleLocate(e) {
        e.stopPropagation();
        onLocate === null || onLocate === void 0 ? void 0 : onLocate(fileWithId);
    };
    var actionBtnClass = classNames("".concat(prefixCls, "-leaf-action-btn"), hashId);
    var titleTextClass = classNames("".concat(prefixCls, "-leaf-title-text"), hashId);
    if (isDisabled) {
        return /*#__PURE__*/ React.createElement("span", {
            className: titleTextClass,
            title: fileWithId.name
        }, fileWithId.name);
    }
    return /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-leaf-title"), hashId)
    }, /*#__PURE__*/ React.createElement("div", {
        className: titleTextClass,
        title: fileWithId.name
    }, fileWithId.name), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-leaf-actions"), hashId),
        onClick: function onClick(e) {
            return e.stopPropagation();
        }
    }, showPreviewButton ? /*#__PURE__*/ React.createElement(ActionIconBox, {
        key: "preview",
        title: (locale === null || locale === void 0 ? void 0 : locale['workspace.file.preview']) || '预览',
        onClick: handlePreview,
        tooltipProps: {
            mouseEnterDelay: 0.3
        },
        className: actionBtnClass
    }, /*#__PURE__*/ React.createElement(EyeIcon, null)) : null, showLocationButton ? /*#__PURE__*/ React.createElement(ActionIconBox, {
        key: "locate",
        title: (locale === null || locale === void 0 ? void 0 : locale['workspace.file.location']) || '定位',
        onClick: handleLocate,
        tooltipProps: {
            mouseEnterDelay: 0.3
        },
        className: actionBtnClass
    }, /*#__PURE__*/ React.createElement(Locate, null)) : null, showShareButton ? /*#__PURE__*/ React.createElement(ActionIconBox, {
        key: "share",
        title: (locale === null || locale === void 0 ? void 0 : locale['workspace.file.share']) || '分享',
        onClick: handleShare,
        tooltipProps: {
            mouseEnterDelay: 0.3
        },
        className: actionBtnClass
    }, /*#__PURE__*/ React.createElement(ShareIcon, null)) : null, showDownloadButton ? /*#__PURE__*/ React.createElement(ActionIconBox, {
        key: "download",
        title: (locale === null || locale === void 0 ? void 0 : locale['workspace.file.download']) || '下载',
        onClick: handleDownload,
        tooltipProps: {
            mouseEnterDelay: 0.3
        },
        className: actionBtnClass
    }, /*#__PURE__*/ React.createElement(DownloadIcon, null)) : null));
};
FileTreeLeafTitleComponent.displayName = 'FileTreeLeafTitle';
export var FileTreeLeafTitle = /*#__PURE__*/ memo(FileTreeLeafTitleComponent);
