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 { ChevronsUpDown, Copy } from "@sofa-design/icons";
import React, { useContext } from "react";
import { ActionIconBox } from "../../Components/ActionIconBox";
import { I18nContext } from "../../I18n";
import { LoadImage } from "../../Plugins/code/components/LoadImage";
import { langIconMap } from "../../Plugins/code/langIconMap";
var TOOLBAR_BASE_STYLE = {
    borderTopLeftRadius: 'inherit',
    borderTopRightRadius: 'inherit',
    backgroundColor: 'transparent',
    paddingLeft: '0.25em',
    paddingRight: '0.25em',
    width: '100%',
    position: 'sticky',
    left: 0,
    top: 0,
    fontSize: '1em',
    font: 'var(--font-text-h6-base)',
    color: 'inherit',
    justifyContent: 'space-between',
    zIndex: 50,
    height: '38px',
    display: 'flex',
    alignItems: 'center',
    padding: '9px 12px',
    gap: '16px',
    alignSelf: 'stretch',
    boxSizing: 'border-box',
    userSelect: 'none'
};
var TOOLBAR_LEFT_STYLE = {
    display: 'flex',
    alignItems: 'center',
    gap: 8
};
var LANG_LABEL_STYLE = {
    display: 'flex',
    alignItems: 'center',
    cursor: 'pointer',
    gap: 4,
    font: 'inherit',
    color: 'inherit',
    userSelect: 'none'
};
var LANG_ICON_WRAPPER_STYLE = {
    height: '1em',
    width: '1em',
    fontSize: '16px',
    display: 'flex'
};
var LANG_ICON_INNER_STYLE = {
    height: '1em',
    width: '1em'
};
var TOOLBAR_RIGHT_STYLE = {
    display: 'flex',
    gap: 5,
    alignItems: 'center'
};
var COPY_BUTTON_STYLE = {
    fontSize: '1em',
    lineHeight: '1.75em',
    marginLeft: '0.125em'
};
var TOOLBAR_BORDER = '1px solid var(--color-gray-border-light)';
/**
 * 计算 toolbar 容器最终样式：仅在展开态附加底部分隔线。
 * 提取为函数避免 inline 表达式让 React diff 失稳。
 */ var buildToolbarStyle = function buildToolbarStyle(expanded) {
    return _object_spread_props(_object_spread({}, TOOLBAR_BASE_STYLE), {
        borderBottom: expanded ? TOOLBAR_BORDER : 'none'
    });
};
var CodeBlockToolbarComponent = function CodeBlockToolbarComponent(param) {
    var language = param.language, expanded = param.expanded, theme = param.theme, onCopy = param.onCopy, onToggleExpanded = param.onToggleExpanded;
    var _i18n_locale, _i18n_locale1;
    var i18n = useContext(I18nContext);
    var langIcon = langIconMap.get((language === null || language === void 0 ? void 0 : language.toLowerCase()) || '');
    var actionTheme = theme === 'dark' ? 'dark' : 'light';
    return /*#__PURE__*/ React.createElement("div", {
        "data-testid": "code-toolbar",
        contentEditable: false,
        style: buildToolbarStyle(expanded)
    }, /*#__PURE__*/ React.createElement("div", {
        style: TOOLBAR_LEFT_STYLE
    }, /*#__PURE__*/ React.createElement("div", {
        style: LANG_LABEL_STYLE
    }, langIcon && /*#__PURE__*/ React.createElement("div", {
        style: LANG_ICON_WRAPPER_STYLE
    }, /*#__PURE__*/ React.createElement(LoadImage, {
        style: LANG_ICON_INNER_STYLE,
        src: langIcon
    })), /*#__PURE__*/ React.createElement("span", null, language || 'plain text'))), /*#__PURE__*/ React.createElement("div", {
        style: TOOLBAR_RIGHT_STYLE
    }, /*#__PURE__*/ React.createElement(ActionIconBox, {
        theme: actionTheme,
        title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale = i18n.locale) === null || _i18n_locale === void 0 ? void 0 : _i18n_locale.copy) || '复制',
        style: COPY_BUTTON_STYLE,
        onClick: onCopy
    }, /*#__PURE__*/ React.createElement(Copy, null)), /*#__PURE__*/ React.createElement(ActionIconBox, {
        title: (i18n === null || i18n === void 0 ? void 0 : (_i18n_locale1 = i18n.locale) === null || _i18n_locale1 === void 0 ? void 0 : _i18n_locale1.expandCollapse) || '展开/收起',
        theme: actionTheme,
        onClick: onToggleExpanded
    }, /*#__PURE__*/ React.createElement(ChevronsUpDown, null))));
};
CodeBlockToolbarComponent.displayName = 'CodeBlockToolbar';
export var CodeBlockToolbar = /*#__PURE__*/ React.memo(CodeBlockToolbarComponent);
