function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { LaptopMinimal, PanelLeftFill, PanelLeftFillFold, SquareArrowOutUpRight } from "@sofa-design/icons";
import { Button, ConfigProvider } from "antd";
import classNames from "classnames";
import { useMergedState } from "rc-util";
import React, { useContext } from "react";
import { I18nContext } from "../../I18n";
import { ActionIconBox } from "../ActionIconBox";
import { useLayoutHeaderStyle } from "./style";
/**
 * LayoutHeader 组件 - 布局头部组件
 *
 * 该组件提供了一个通用的布局头部区域，包含标题、左侧折叠按钮、分享按钮和右侧折叠按钮。
 * 支持自定义左侧和右侧的额外内容，以及受控和非受控模式。
 *
 * @component
 * @description 布局头部组件，提供完整的头部布局和交互功能
 * @param {LayoutHeaderProps} props - 组件属性
 *
 * @example
 * ```tsx
 * import { LayoutHeader } from './LayoutHeader';
 *
 * // 基本用法
 * <LayoutHeader
 *   title="AI 助手"
 *   onLeftCollapse={() => console.log('左侧折叠')}
 *   onRightCollapse={() => console.log('右侧折叠')}
 *   onShare={() => console.log('分享')}
 * />
 *
 * // 受控模式 - 折叠状态
 * <LayoutHeader
 *   title="AI 助手"
 *   leftCollapsed={leftCollapsed}
 *   rightCollapsed={rightCollapsed}
 *   onLeftCollapse={setLeftCollapsed}
 *   onRightCollapse={setRightCollapsed}
 * />
 *
 * // 非受控模式 - 默认折叠状态
 * <LayoutHeader
 *   title="AI 助手"
 *   leftDefaultCollapsed={true}
 *   rightDefaultCollapsed={false}
 *   onLeftCollapse={(collapsed) => console.log('左侧折叠状态:', collapsed)}
 *   onRightCollapse={(collapsed) => console.log('右侧折叠状态:', collapsed)}
 * />
 *
 * // 自定义内容
 * <LayoutHeader
 *   title="AI 助手"
 *   leftExtra={<div>自定义左侧内容</div>}
 *   rightExtra={<div>自定义右侧内容</div>}
 * />
 * ```
 *
 * @returns {React.ReactElement} 渲染的头部组件
 */ var LayoutHeader = function(param) {
    var _param_title = param.title, title = _param_title === void 0 ? 'AI 助手' : _param_title, _param_showShare = param.showShare, showShare = _param_showShare === void 0 ? true : _param_showShare, _param_leftCollapsible = param.leftCollapsible, leftCollapsible = _param_leftCollapsible === void 0 ? true : _param_leftCollapsible, _param_rightCollapsible = param.rightCollapsible, rightCollapsible = _param_rightCollapsible === void 0 ? false : _param_rightCollapsible, controlledLeftCollapsed = param.leftCollapsed, controlledRightCollapsed = param.rightCollapsed, _param_leftDefaultCollapsed = param.leftDefaultCollapsed, leftDefaultCollapsed = _param_leftDefaultCollapsed === void 0 ? false : _param_leftDefaultCollapsed, _param_rightDefaultCollapsed = param.rightDefaultCollapsed, rightDefaultCollapsed = _param_rightDefaultCollapsed === void 0 ? false : _param_rightDefaultCollapsed, onLeftCollapse = param.onLeftCollapse, onRightCollapse = param.onRightCollapse, onShare = param.onShare, leftExtra = param.leftExtra, rightExtra = param.rightExtra, className = param.className;
    var locale = useContext(I18nContext).locale;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('layout-header');
    var _useLayoutHeaderStyle = useLayoutHeaderStyle(prefixCls), wrapSSR = _useLayoutHeaderStyle.wrapSSR, hashId = _useLayoutHeaderStyle.hashId;
    // 使用 useMergedState 管理左侧折叠状态
    var _useMergedState = _sliced_to_array(useMergedState(leftDefaultCollapsed, {
        value: controlledLeftCollapsed,
        onChange: onLeftCollapse
    }), 2), leftCollapsed = _useMergedState[0], setLeftCollapsed = _useMergedState[1];
    // 使用 useMergedState 管理右侧折叠状态
    var _useMergedState1 = _sliced_to_array(useMergedState(rightDefaultCollapsed, {
        value: controlledRightCollapsed,
        onChange: onRightCollapse
    }), 2), rightCollapsed = _useMergedState1[0], setRightCollapsed = _useMergedState1[1];
    var handleLeftCollapse = function() {
        if (leftCollapsible) {
            setLeftCollapsed(!leftCollapsed);
        }
    };
    var handleRightCollapse = function() {
        if (rightCollapsible) {
            setRightCollapsed(!rightCollapsed);
        }
    };
    var handleShare = function() {
        onShare === null || onShare === void 0 ? void 0 : onShare();
    };
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: classNames(prefixCls, hashId, className)
    }, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-left"), hashId)
    }, leftCollapsible && /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ActionIconBox, {
        onClick: handleLeftCollapse,
        "aria-label": (locale === null || locale === void 0 ? void 0 : locale['chatFlow.collapseLeft']) || '折叠左侧边栏',
        title: (locale === null || locale === void 0 ? void 0 : locale['chatFlow.collapseLeft']) || '折叠左侧边栏'
    }, leftCollapsed ? /*#__PURE__*/ React.createElement(PanelLeftFill, null) : /*#__PURE__*/ React.createElement(PanelLeftFillFold, null)), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-left-separator"), hashId)
    })), /*#__PURE__*/ React.createElement("h1", {
        className: classNames("".concat(prefixCls, "-left-title"), hashId)
    }, title), leftExtra), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-right"), hashId)
    }, showShare && /*#__PURE__*/ React.createElement(Button, {
        size: "small",
        className: classNames("".concat(prefixCls, "-right-share-btn"), hashId),
        onClick: handleShare,
        "aria-label": (locale === null || locale === void 0 ? void 0 : locale['chatFlow.shareDialog']) || '分享对话',
        icon: /*#__PURE__*/ React.createElement(SquareArrowOutUpRight, null),
        color: "default"
    }, (locale === null || locale === void 0 ? void 0 : locale['chatFlow.share']) || '分享'), rightCollapsible && /*#__PURE__*/ React.createElement(ActionIconBox, {
        onClick: handleRightCollapse,
        "aria-label": (locale === null || locale === void 0 ? void 0 : locale['chatFlow.collapseRight']) || '折叠右侧边栏',
        title: (locale === null || locale === void 0 ? void 0 : locale['chatFlow.collapseRight']) || '折叠右侧边栏'
    }, /*#__PURE__*/ React.createElement(LaptopMinimal, null)), rightExtra)));
};
export { LayoutHeader };
