"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonQueryList = CommonQueryList;
const i18n_1 = __importDefault(require("../../../../locales/i18n.js"));
const React = __importStar(require("react"));
const cn_ui_1 = require("@cainiaofe/cn-ui");
const condition_query_display_utils_1 = require("../../../../cn-ai-filter/utils/display/condition-query-display-utils");
/**
 * 常用查询条件列表组件
 */
function CommonQueryList({ loading, pinnedQueries, unpinnedQueries, onQueryClick, onPinQuery, onUnpinQuery, onClose, schema, }) {
    const handleQueryClick = React.useCallback((tokens) => {
        onQueryClick(tokens);
        onClose === null || onClose === void 0 ? void 0 : onClose();
    }, [onQueryClick, onClose]);
    if (loading) {
        return (React.createElement("div", { className: "cn-ai-filter__common-query-loading" }, i18n_1.default.get({ id: 'Loading', dm: '加载中...' })));
    }
    return (React.createElement(React.Fragment, null,
        React.createElement("div", { className: "cn-ai-filter__common-query-section-title" }, i18n_1.default.get({ id: 'MySearchCriteria', dm: '我的查询条件' })),
        pinnedQueries.length > 0 ? (React.createElement(React.Fragment, null, pinnedQueries.map((pinnedQuery) => {
            const displayItems = (0, condition_query_display_utils_1.conditionQueryDisplayUtils)(pinnedQuery.tokens, schema);
            return (React.createElement("div", { key: pinnedQuery.id, className: "cn-ai-filter__common-query-item cn-ai-filter__common-query-item--pinned" },
                React.createElement("div", { className: "cn-ai-filter__common-query-content", onClick: () => handleQueryClick(pinnedQuery.tokens) }, displayItems.map((item, itemIndex) => {
                    const displayKey = `${pinnedQuery.id}-item-${itemIndex}`;
                    if (item.type === 'NATURAL_LANGUAGE' && item.text) {
                        return (React.createElement("div", { key: displayKey, className: "cn-ai-filter__common-query-text" }, item.text));
                    }
                    else if (item.type === 'STRUCTURED' && item.tag) {
                        return (React.createElement("div", { key: displayKey, className: "cn-ai-filter__common-query-tag" },
                            item.tag.displayName,
                            ": ",
                            item.tag.displayValue));
                    }
                    return null;
                })),
                React.createElement(cn_ui_1.CnIcon, { type: "pin", size: "medium", className: "cn-ai-filter__common-query-pin-icon cn-ai-filter__common-query-pin-icon--pinned", onClick: (e) => {
                        e.stopPropagation();
                        onUnpinQuery(pinnedQuery.id);
                    } })));
        }))) : (React.createElement("div", { className: "cn-ai-filter__common-query-empty" }, i18n_1.default.get({ id: 'NoMyQueryCriteria', dm: '暂无我的查询条件' }))),
        pinnedQueries.length > 0 && unpinnedQueries.length > 0 && (React.createElement("div", { className: "cn-ai-filter__common-query-divider" })),
        React.createElement("div", { className: "cn-ai-filter__common-query-section-title" }, i18n_1.default.get({ id: 'AIIntelligentRecommendation', dm: 'AI智能推荐' })),
        unpinnedQueries.length > 0 ? (React.createElement(React.Fragment, null, unpinnedQueries.map((translator, index) => {
            const { tokens = [], id } = translator;
            // 使用 conditionQueryDisplayUtils 格式化显示项
            const displayItems = (0, condition_query_display_utils_1.conditionQueryDisplayUtils)(tokens, schema);
            // 生成唯一 key
            const itemKey = id || `query-${index}`;
            return (React.createElement("div", { key: itemKey, className: "cn-ai-filter__common-query-item" },
                React.createElement("div", { className: "cn-ai-filter__common-query-content", onClick: () => handleQueryClick(tokens) }, displayItems.map((item, itemIndex) => {
                    const displayKey = `${itemKey}-item-${itemIndex}`;
                    if (item.type === 'NATURAL_LANGUAGE' && item.text) {
                        return (React.createElement("div", { key: displayKey, className: "cn-ai-filter__common-query-text" }, item.text));
                    }
                    else if (item.type === 'STRUCTURED' && item.tag) {
                        return (React.createElement("div", { key: displayKey, className: "cn-ai-filter__common-query-tag" },
                            item.tag.displayName,
                            ": ",
                            item.tag.displayValue));
                    }
                    return null;
                })),
                React.createElement(cn_ui_1.CnIcon, { type: "pin", size: "medium", className: "cn-ai-filter__common-query-pin-icon", onClick: (e) => {
                        e.stopPropagation();
                        onPinQuery(translator);
                    } })));
        }))) : (React.createElement("div", { className: "cn-ai-filter__common-query-empty" }, i18n_1.default.get({ id: 'NoAIIntelligentRecommendation', dm: '暂无AI智能推荐' })))));
}
