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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
    try {
        var info = gen[key](arg);
        var value = info.value;
    } catch (error) {
        reject(error);
        return;
    }
    if (info.done) {
        resolve(value);
    } else {
        Promise.resolve(value).then(_next, _throw);
    }
}
function _async_to_generator(fn) {
    return function() {
        var self = this, args = arguments;
        return new Promise(function(resolve, reject) {
            var gen = fn.apply(self, args);
            function _next(value) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
            }
            function _throw(err) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
            }
            _next(undefined);
        });
    };
}
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 _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);
}
function _ts_generator(thisArg, body) {
    var f, y, t, _ = {
        label: 0,
        sent: function() {
            if (t[0] & 1) throw t[1];
            return t[1];
        },
        trys: [],
        ops: []
    }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
    return d(g, "next", {
        value: verb(0)
    }), d(g, "throw", {
        value: verb(1)
    }), d(g, "return", {
        value: verb(2)
    }), typeof Symbol === "function" && d(g, Symbol.iterator, {
        value: function() {
            return this;
        }
    }), g;
    function verb(n) {
        return function(v) {
            return step([
                n,
                v
            ]);
        };
    }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while(g && (g = 0, op[0] && (_ = 0)), _)try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [
                op[0] & 2,
                t.value
            ];
            switch(op[0]){
                case 0:
                case 1:
                    t = op;
                    break;
                case 4:
                    _.label++;
                    return {
                        value: op[1],
                        done: false
                    };
                case 5:
                    _.label++;
                    y = op[1];
                    op = [
                        0
                    ];
                    continue;
                case 7:
                    op = _.ops.pop();
                    _.trys.pop();
                    continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                        _ = 0;
                        continue;
                    }
                    if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
                        _.label = op[1];
                        break;
                    }
                    if (op[0] === 6 && _.label < t[1]) {
                        _.label = t[1];
                        t = op;
                        break;
                    }
                    if (t && _.label < t[2]) {
                        _.label = t[2];
                        _.ops.push(op);
                        break;
                    }
                    if (t[2]) _.ops.pop();
                    _.trys.pop();
                    continue;
            }
            op = body.call(thisArg, _);
        } catch (e) {
            op = [
                6,
                e
            ];
            y = 0;
        } finally{
            f = t = 0;
        }
        if (op[0] & 5) throw op[1];
        return {
            value: op[0] ? op[1] : void 0,
            done: true
        };
    }
}
import { Input, Spin } from "antd";
import React, { useContext, useRef, useState } from "react";
import { ActionIconBox } from "../../Components/ActionIconBox";
import useClickAway from "../../Hooks/useClickAway";
import { useDebounceFn } from "../../Hooks/useDebounceFn";
import { I18nContext } from "../../I18n";
function SearchIcon(props) {
    return /*#__PURE__*/ React.createElement("svg", _object_spread({
        xmlns: "http://www.w3.org/2000/svg",
        xmlnsXlink: "http://www.w3.org/1999/xlink",
        fill: "none",
        version: "1.1",
        width: "14",
        height: "14",
        viewBox: "0 0 14 14"
    }, props), /*#__PURE__*/ React.createElement("g", {
        clipPath: "url(#master_svg0_645_36290/645_35767/1_00870)"
    }, /*#__PURE__*/ React.createElement("g", null, /*#__PURE__*/ React.createElement("path", {
        d: "M9.693555458984376,10.518662270507813C8.795425458984376,11.237102270507812,7.656175458984375,11.666702270507812,6.416595458984375,11.666702270507812C3.517095458984375,11.666702270507812,1.166595458984375,9.316202270507812,1.166595458984375,6.4167022705078125C1.166595458984375,3.5172022705078123,3.517095458984375,1.1667022705078125,6.416595458984375,1.1667022705078125C9.316095458984375,1.1667022705078125,11.666595458984375,3.5172022705078123,11.666595458984375,6.4167022705078125C11.666595458984375,7.656302270507813,11.236995458984374,8.795562270507812,10.518515458984375,9.693702270507812L12.662395458984374,11.837602270507812C12.771795458984375,11.947002270507813,12.833195458984376,12.095302270507812,12.833195458984376,12.250002270507812C12.833195458984376,12.572202270507812,12.572095458984375,12.833402270507813,12.249895458984374,12.833402270507813C12.095195458984374,12.833402270507813,11.946795458984376,12.771902270507812,11.837395458984375,12.662502270507812L9.693555458984376,10.518662270507813ZM10.499925458984375,6.4167022705078125C10.499925458984375,4.1615422705078124,8.671755458984375,2.3333722705078124,6.416595458984375,2.3333722705078124C4.161435458984375,2.3333722705078124,2.333265458984375,4.1615422705078124,2.333265458984375,6.4167022705078125C2.333265458984375,8.671862270507813,4.161435458984375,10.500032270507813,6.416595458984375,10.500032270507813C8.671755458984375,10.500032270507813,10.499925458984375,8.671862270507813,10.499925458984375,6.4167022705078125Z",
        fillRule: "evenodd",
        fill: "currentColor"
    }))));
}
/**
 * HistorySearch 组件 - 历史记录搜索组件
 *
 * 该组件提供一个搜索输入框，用于搜索历史记录。
 * 支持加载状态显示和错误处理。
 *
 * @component
 * @description 历史记录搜索组件，用于搜索历史对话记录
 * @param {HistorySearchProps} props - 组件属性
 * @param {string} props.searchKeyword - 搜索关键词
 * @param {(value: string) => void} props.onSearch - 搜索回调函数
 * @param {boolean} [props.enabled=false] - 是否启用搜索功能
 *
 * @example
 * ```tsx
 * <HistorySearch
 *   searchKeyword={keyword}
 *   onSearch={(value) => handleSearch(value)}
 *   enabled={true}
 * />
 * ```
 *
 * @returns {React.ReactElement|null} 渲染的搜索输入框组件，未启用时返回null
 *
 * @remarks
 * - 支持实时搜索
 * - 包含加载状态显示
 * - 支持清空输入
 * - 包含错误处理机制
 * - 响应式输入框设计
 * - 条件渲染支持
 * - 默认显示搜索图标，点击后展开搜索框
 */ export var HistorySearch = function(param) {
    var onSearch = param.onSearch, type = param.type, searchOptions = param.searchOptions;
    var _ref, _ref1;
    var locale = useContext(I18nContext).locale;
    var _useState = _sliced_to_array(useState(false), 2), loading = _useState[0], setLoading = _useState[1];
    var _useState1 = _sliced_to_array(useState(false), 2), isExpanded = _useState1[0], setIsExpanded = _useState1[1];
    var _useState2 = _sliced_to_array(useState(''), 2), inputValue = _useState2[0], setInputValue = _useState2[1];
    var ref = useRef(null);
    var trigger = (searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.trigger) || 'change';
    useClickAway(function() {
        if (!inputValue) {
            setIsExpanded(false);
        }
    }, ref);
    var handleSearchWithLoading = function(value) {
        return _async_to_generator(function() {
            var error;
            return _ts_generator(this, function(_state) {
                switch(_state.label){
                    case 0:
                        _state.trys.push([
                            0,
                            2,
                            3,
                            4
                        ]);
                        setLoading(true);
                        return [
                            4,
                            onSearch === null || onSearch === void 0 ? void 0 : onSearch(value)
                        ];
                    case 1:
                        _state.sent();
                        return [
                            3,
                            4
                        ];
                    case 2:
                        error = _state.sent();
                        return [
                            3,
                            4
                        ];
                    case 3:
                        setLoading(false);
                        return [
                            7
                        ];
                    case 4:
                        return [
                            2
                        ];
                }
            });
        })();
    };
    var handleToggleSearch = function() {
        setIsExpanded(!isExpanded);
    };
    var handleSearchChange = useDebounceFn(function(e) {
        return _async_to_generator(function() {
            var value;
            return _ts_generator(this, function(_state) {
                value = e.target.value;
                handleSearchWithLoading(value);
                return [
                    2
                ];
            });
        })();
    }, 360);
    var handleInputChange = function(e) {
        var value = e.target.value;
        setInputValue(value);
        if (trigger === 'change') {
            handleSearchChange.run(e);
        }
    };
    var handleKeyDown = function(e) {
        if (trigger === 'enter' && e.key === 'Enter') {
            handleSearchWithLoading(inputValue);
        }
    };
    // 展开后显示搜索框
    return /*#__PURE__*/ React.createElement("div", {
        ref: ref,
        style: {
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'space-between',
            height: 32,
            padding: isExpanded ? 0 : '0 6px 0 12px'
        }
    }, isExpanded ? /*#__PURE__*/ React.createElement(Input, {
        placeholder: (_ref = searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.placeholder) !== null && _ref !== void 0 ? _ref : type === 'task' ? (locale === null || locale === void 0 ? void 0 : locale['chat.task.search.placeholder']) || '搜索任务' : (locale === null || locale === void 0 ? void 0 : locale['chat.history.search.placeholder']) || '搜索话题',
        prefix: loading ? /*#__PURE__*/ React.createElement(Spin, {
            size: "small"
        }) : /*#__PURE__*/ React.createElement(SearchIcon, {
            style: {
                color: 'var(--color-gray-text-secondary)'
            }
        }),
        value: inputValue,
        onChange: handleInputChange,
        onKeyDown: handleKeyDown,
        style: {
            width: '100%',
            height: 32,
            background: 'var(--color-gray-bg-card-light)'
        },
        onClear: function() {
            setInputValue('');
            handleSearchWithLoading('');
        },
        allowClear: true,
        variant: "filled",
        autoFocus: true
    }) : /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("div", {
        style: {
            font: 'var(--font-text-body-emphasized-sm)',
            letterSpacing: 'var(--letter-spacing-body-emphasized-sm, normal)',
            color: 'var(--color-gray-text-light)',
            flex: 1
        }
    }, (_ref1 = searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.text) !== null && _ref1 !== void 0 ? _ref1 : type === 'task' ? (locale === null || locale === void 0 ? void 0 : locale['chat.history.historyTasks']) || '历史任务' : (locale === null || locale === void 0 ? void 0 : locale['chat.history.historyChats']) || '历史对话'), /*#__PURE__*/ React.createElement(ActionIconBox, {
        onClick: handleToggleSearch,
        title: (locale === null || locale === void 0 ? void 0 : locale['chat.history.search']) || '搜索',
        style: {
            width: 28,
            height: 28,
            color: 'var(--color-gray-text-secondary)'
        }
    }, /*#__PURE__*/ React.createElement(SearchIcon, null))));
};
/**
 * @deprecated 请使用 HistorySearch 替代
 */ export var SearchComponent = HistorySearch;
