import React from 'react';
import { Tag } from 'antd';
import { CloseOutlined } from '@ant-design/icons';
/**
 * SearchHistory 组件
 * 展示搜索历史记录
 */
export var SearchHistory = function SearchHistory(props) {
  var history = props.history,
    onSelect = props.onSelect,
    onRemove = props.onRemove,
    onClear = props.onClear,
    render = props.render,
    className = props.className,
    style = props.style;

  // 如果没有历史记录，不显示
  if (!history || history.length === 0) {
    return null;
  }

  // 使用自定义渲染
  if (render) {
    return /*#__PURE__*/React.createElement(React.Fragment, null, render(history, onSelect));
  }

  /**
   * 处理点击历史记录
   */
  var handleClick = function handleClick(keyword) {
    onSelect(keyword);
  };

  /**
   * 处理删除历史记录
   */
  var handleRemove = function handleRemove(e, keyword) {
    e.stopPropagation();
    onRemove === null || onRemove === void 0 || onRemove(keyword);
  };

  /**
   * 处理清除全部历史记录
   */
  var handleClearAll = function handleClearAll() {
    onClear === null || onClear === void 0 || onClear();
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-lookup-history ".concat(className || ''),
    style: style
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-lookup-history-list"
  }, history.map(function (item, index) {
    return /*#__PURE__*/React.createElement(Tag, {
      key: "".concat(item, "-").concat(index),
      className: "pisell-lookup-history-item",
      onClick: function onClick() {
        return handleClick(item);
      },
      closable: !!onRemove,
      onClose: function onClose(e) {
        return handleRemove(e, item);
      },
      closeIcon: /*#__PURE__*/React.createElement(CloseOutlined, null)
    }, item);
  })));
};
SearchHistory.displayName = 'SearchHistory';