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 _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 _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 _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;
}
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 { ConfigProvider } from "antd";
import classNames from "classnames";
import React, { memo, useCallback, useContext, useEffect, useRef, useState } from "react";
import { LayoutHeader } from "../Components/LayoutHeader";
import { useAgenticLayoutStyle } from "./style";
/**
 * AgenticLayout 组件 - 智能体布局组件
 *
 * 该组件提供一个三栏布局的容器，支持左中右三个区域的灵活配置。
 * 左右侧栏支持折叠功能，中间区域自适应宽度。
 *
 * @component
 * @description 智能体布局组件，提供左中右三栏布局
 * @param {AgenticLayoutProps} props - 组件属性
 * @param {ReactNode} [props.left] - 左侧内容
 * @param {ReactNode} props.center - 中间内容
 * @param {ReactNode} [props.right] - 右侧内容
 * @param {LayoutHeaderConfig} [props.header] - 头部配置
 * @param {React.CSSProperties} [props.style] - 自定义样式
 * @param {string} [props.className] - 自定义CSS类名
 * @param {number} [props.leftWidth=256] - 左侧宽度
 * @param {number} [props.rightWidth=540] - 右侧宽度
 * @param {string | number} [props.minHeight='600px'] - 最小高度
 *
 * @example
 * ```tsx
 * <AgenticLayout
 *   left={<History />}
 *   center={<ChatLayout />}
 *   right={<Workspace />}
 *   header={{
 *     title: "智能体助手",
 *     showShare: true,
 *     showLeftCollapse: true,
 *     showRightCollapse: true,
 *     onLeftCollapse: (collapsed) => console.log('左侧折叠:', collapsed),
 *     onRightCollapse: (collapsed) => console.log('右侧折叠:', collapsed),
 *     onShare: () => console.log('分享')
 *   }}
 * />
 * ```
 *
 * @returns {React.ReactElement} 渲染的布局组件
 *
 * @remarks
 * - 支持左右侧栏的独立折叠控制
 * - 中间区域自适应剩余宽度
 * - 提供响应式布局适配
 * - 支持自定义宽度和高度
 * - 集成 Ant Design 主题系统
 */ // 常量定义
var MIN_RIGHT_WIDTH = 400;
var MAX_RIGHT_WIDTH_RATIO = 0.7;
var DEFAULT_LEFT_WIDTH = 256;
var DEFAULT_RIGHT_WIDTH = 540;
var AgenticLayoutComponent = function(param) {
    var left = param.left, center = param.center, right = param.right, header = param.header, style = param.style, className = param.className, _param_leftWidth = param.leftWidth, leftWidth = _param_leftWidth === void 0 ? DEFAULT_LEFT_WIDTH : _param_leftWidth, _param_rightWidth = param.rightWidth, rightWidth = _param_rightWidth === void 0 ? DEFAULT_RIGHT_WIDTH : _param_rightWidth;
    var _ref, _ref1, _ref2, _ref3, _header_leftCollapsible, _header_rightCollapsible;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('agentic-layout');
    var _useAgenticLayoutStyle = useAgenticLayoutStyle(prefixCls), wrapSSR = _useAgenticLayoutStyle.wrapSSR, hashId = _useAgenticLayoutStyle.hashId;
    // 从 header 配置中获取折叠状态
    var leftCollapsed = (_ref = (_ref1 = header === null || header === void 0 ? void 0 : header.leftCollapsed) !== null && _ref1 !== void 0 ? _ref1 : header === null || header === void 0 ? void 0 : header.leftDefaultCollapsed) !== null && _ref !== void 0 ? _ref : false;
    var rightCollapsed = (_ref2 = (_ref3 = header === null || header === void 0 ? void 0 : header.rightCollapsed) !== null && _ref3 !== void 0 ? _ref3 : header === null || header === void 0 ? void 0 : header.rightDefaultCollapsed) !== null && _ref2 !== void 0 ? _ref2 : false;
    // 右侧边栏宽度状态
    var _useState = _sliced_to_array(useState(rightWidth), 2), currentRightWidth = _useState[0], setCurrentRightWidth = _useState[1];
    var isResizingRef = useRef(false);
    var resizeStartX = useRef(0);
    var resizeStartWidth = useRef(rightWidth);
    // 计算最大宽度（浏览器窗口的70%）
    var getMaxRightWidth = useCallback(function() {
        if (typeof window === 'undefined') return Infinity;
        return window.innerWidth * MAX_RIGHT_WIDTH_RATIO;
    }, []);
    // 当 rightWidth prop 变化时更新状态
    useEffect(function() {
        setCurrentRightWidth(rightWidth);
    }, [
        rightWidth
    ]);
    // 监听窗口大小变化，确保右侧边栏宽度不超过最大限制
    useEffect(function() {
        var handleWindowResize = function() {
            var maxWidth = getMaxRightWidth();
            if (currentRightWidth > maxWidth) {
                setCurrentRightWidth(maxWidth);
            }
        };
        window.addEventListener('resize', handleWindowResize);
        return function() {
            window.removeEventListener('resize', handleWindowResize);
        };
    }, [
        currentRightWidth,
        getMaxRightWidth
    ]);
    // 处理拖拽过程
    var handleResizeMove = useCallback(function(e) {
        if (!isResizingRef.current) return;
        // 向左拖拽（扩大右侧边栏）时 deltaX 为正，向右拖拽（缩小）时 deltaX 为负
        var deltaX = resizeStartX.current - e.clientX;
        var newWidth = resizeStartWidth.current + deltaX;
        var maxWidth = getMaxRightWidth();
        // 限制宽度范围
        var clampedWidth = Math.max(MIN_RIGHT_WIDTH, Math.min(newWidth, maxWidth));
        setCurrentRightWidth(clampedWidth);
    }, [
        getMaxRightWidth
    ]);
    // 处理拖拽结束
    var handleResizeEnd = useCallback(function handleMouseUp() {
        isResizingRef.current = false;
        document.removeEventListener('mousemove', handleResizeMove);
        document.removeEventListener('mouseup', handleMouseUp);
        document.body.style.cursor = '';
        document.body.style.userSelect = '';
    }, [
        handleResizeMove
    ]);
    // 处理拖拽开始
    var handleResizeStart = useCallback(function(e) {
        e.preventDefault();
        e.stopPropagation();
        isResizingRef.current = true;
        resizeStartX.current = e.clientX;
        resizeStartWidth.current = currentRightWidth;
        document.addEventListener('mousemove', handleResizeMove);
        document.addEventListener('mouseup', handleResizeEnd);
        document.body.style.cursor = 'col-resize';
        document.body.style.userSelect = 'none';
    }, [
        currentRightWidth,
        handleResizeMove,
        handleResizeEnd
    ]);
    // 清理事件监听器
    useEffect(function() {
        return function() {
            document.removeEventListener('mousemove', handleResizeMove);
            document.removeEventListener('mouseup', handleResizeEnd);
            document.body.style.cursor = '';
            document.body.style.userSelect = '';
        };
    }, [
        handleResizeMove,
        handleResizeEnd
    ]);
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: classNames(prefixCls, className, hashId),
        style: style
    }, /*#__PURE__*/ React.createElement("div", {
        className: "".concat(prefixCls, "-body ").concat(hashId),
        style: {
            display: 'flex',
            flex: 1
        }
    }, left && /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-sidebar"), "".concat(prefixCls, "-sidebar-left"), _define_property({}, "".concat(prefixCls, "-sidebar-left-collapsed"), leftCollapsed), hashId),
        style: {
            width: leftCollapsed ? 0 : leftWidth,
            minWidth: leftCollapsed ? 0 : leftWidth,
            maxWidth: leftCollapsed ? 0 : leftWidth
        }
    }, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-sidebar-content"), hashId)
    }, left)), /*#__PURE__*/ React.createElement("div", {
        className: "".concat(prefixCls, "-main ").concat(hashId),
        style: {
            flex: 1,
            minWidth: MIN_RIGHT_WIDTH
        }
    }, header && /*#__PURE__*/ React.createElement(LayoutHeader, _object_spread_props(_object_spread({}, header), {
        leftCollapsible: (_header_leftCollapsible = header.leftCollapsible) !== null && _header_leftCollapsible !== void 0 ? _header_leftCollapsible : !!left,
        rightCollapsible: (_header_rightCollapsible = header.rightCollapsible) !== null && _header_rightCollapsible !== void 0 ? _header_rightCollapsible : !!right
    })), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-main-content"), hashId)
    }, center))), right && /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-sidebar-wrapper-right"), hashId),
        style: {
            display: 'flex',
            alignItems: 'stretch',
            height: '100%'
        }
    }, !rightCollapsed && /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-resize-handle"), "".concat(prefixCls, "-resize-handle-right"), hashId),
        onMouseDown: handleResizeStart
    }), /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-sidebar"), "".concat(prefixCls, "-sidebar-right"), _define_property({}, "".concat(prefixCls, "-sidebar-right-collapsed"), rightCollapsed), hashId),
        style: {
            width: rightCollapsed ? 0 : currentRightWidth,
            minWidth: rightCollapsed ? 0 : currentRightWidth,
            maxWidth: rightCollapsed ? 0 : currentRightWidth
        }
    }, /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefixCls, "-sidebar-content"), hashId)
    }, right)))));
};
// 使用 React.memo 优化性能，避免不必要的重新渲染
export var AgenticLayout = /*#__PURE__*/ memo(AgenticLayoutComponent);
