function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { 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 _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(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(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(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 _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useState, useRef } from 'react';
import { PisellFind } from "./index";
import { Table, List, Tag, Button, Space, Card } from 'antd';

/**
 * PisellFind 组件 Storybook
 * 基于 PisellLookup 的组件内查找优化版本
 */
var meta = {
  title: 'Plus Components/PisellFind',
  component: PisellFind,
  parameters: {
    layout: 'padded',
    docs: {
      description: {
        component: '基于 PisellLookup 的组件内查找组件，专门为已加载数据的查找场景优化。'
      }
    }
  },
  tags: ['autodocs']
};
export default meta;
/**
 * 模拟商品数据
 */
var mockProducts = [{
  id: 1,
  name: 'iPhone 15 Pro',
  price: 7999,
  category: '手机',
  stock: 100
}, {
  id: 2,
  name: 'iPhone 14',
  price: 5999,
  category: '手机',
  stock: 150
}, {
  id: 3,
  name: 'MacBook Pro',
  price: 12999,
  category: '电脑',
  stock: 50
}, {
  id: 4,
  name: 'MacBook Air',
  price: 7999,
  category: '电脑',
  stock: 80
}, {
  id: 5,
  name: 'iPad Air',
  price: 4799,
  category: '平板',
  stock: 120
}, {
  id: 6,
  name: 'iPad Pro',
  price: 6799,
  category: '平板',
  stock: 60
}, {
  id: 7,
  name: 'AirPods Pro',
  price: 1899,
  category: '耳机',
  stock: 200
}, {
  id: 8,
  name: 'Apple Watch',
  price: 2999,
  category: '手表',
  stock: 90
}];

/**
 * 基础示例 - 列表查找
 */
export var Basic = {
  render: function render() {
    var _useState = useState(mockProducts),
      _useState2 = _slicedToArray(_useState, 2),
      filteredData = _useState2[0],
      setFilteredData = _useState2[1];
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 16
      }
    }, /*#__PURE__*/React.createElement(PisellFind, {
      onSearch: function onSearch(keyword) {
        var filtered = mockProducts.filter(function (item) {
          return item.name.toLowerCase().includes(keyword.toLowerCase());
        });
        setFilteredData(filtered);
      }
    })), /*#__PURE__*/React.createElement(List, {
      dataSource: filteredData,
      renderItem: function renderItem(item) {
        return /*#__PURE__*/React.createElement(List.Item, null, /*#__PURE__*/React.createElement(List.Item.Meta, {
          title: item.name,
          description: /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(Tag, {
            color: "blue"
          }, item.category), /*#__PURE__*/React.createElement("span", {
            style: {
              color: '#ff4d4f',
              fontWeight: 'bold'
            }
          }, "\xA5", item.price), /*#__PURE__*/React.createElement("span", null, "\u5E93\u5B58: ", item.stock))
        }));
      }
    }));
  }
};

/**
 * 表格查找
 */
export var TableFind = {
  render: function render() {
    var _useState3 = useState(mockProducts),
      _useState4 = _slicedToArray(_useState3, 2),
      filteredData = _useState4[0],
      setFilteredData = _useState4[1];
    var columns = [{
      title: '商品名称',
      dataIndex: 'name',
      key: 'name'
    }, {
      title: '价格',
      dataIndex: 'price',
      key: 'price',
      render: function render(v) {
        return "\xA5".concat(v);
      }
    }, {
      title: '分类',
      dataIndex: 'category',
      key: 'category',
      render: function render(v) {
        return /*#__PURE__*/React.createElement(Tag, null, v);
      }
    }, {
      title: '库存',
      dataIndex: 'stock',
      key: 'stock'
    }];
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 16,
        display: 'flex',
        justifyContent: 'space-between',
        alignItems: 'center'
      }
    }, /*#__PURE__*/React.createElement("h3", null, "\u5546\u54C1\u5217\u8868"), /*#__PURE__*/React.createElement(PisellFind, {
      onSearch: function onSearch(keyword) {
        var filtered = mockProducts.filter(function (item) {
          return item.name.toLowerCase().includes(keyword.toLowerCase());
        });
        setFilteredData(filtered);
      }
    })), /*#__PURE__*/React.createElement(Table, {
      dataSource: filteredData,
      columns: columns,
      pagination: {
        pageSize: 10
      }
    }));
  }
};

/**
 * Input 模式查找
 */
export var InputMode = {
  render: function render() {
    var _useState5 = useState(mockProducts),
      _useState6 = _slicedToArray(_useState5, 2),
      filteredData = _useState6[0],
      setFilteredData = _useState6[1];
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 16
      }
    }, /*#__PURE__*/React.createElement(PisellFind, {
      triggerType: "input",
      placeholder: "\u641C\u7D22\u5546\u54C1\u540D\u79F0",
      onSearch: function onSearch(keyword) {
        var filtered = mockProducts.filter(function (item) {
          return item.name.toLowerCase().includes(keyword.toLowerCase());
        });
        setFilteredData(filtered);
      }
    })), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: 'repeat(4, 1fr)',
        gap: 16
      }
    }, filteredData.map(function (item) {
      return /*#__PURE__*/React.createElement(Card, {
        key: item.id,
        size: "small"
      }, /*#__PURE__*/React.createElement("h4", null, item.name), /*#__PURE__*/React.createElement("p", {
        style: {
          color: '#ff4d4f',
          fontWeight: 'bold'
        }
      }, "\xA5", item.price), /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(Tag, null, item.category), /*#__PURE__*/React.createElement("span", null, "\u5E93\u5B58: ", item.stock)));
    })));
  }
};

/**
 * 使用 Ref 控制
 */
export var WithRef = {
  render: function render() {
    var _useState7 = useState(mockProducts),
      _useState8 = _slicedToArray(_useState7, 2),
      filteredData = _useState8[0],
      setFilteredData = _useState8[1];
    var findRef = useRef(null);
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Space, {
      style: {
        marginBottom: 16
      }
    }, /*#__PURE__*/React.createElement(Button, {
      onClick: function onClick() {
        var _findRef$current;
        return (_findRef$current = findRef.current) === null || _findRef$current === void 0 ? void 0 : _findRef$current.open();
      }
    }, "\u6253\u5F00\u67E5\u627E"), /*#__PURE__*/React.createElement(Button, {
      onClick: function onClick() {
        var _findRef$current2;
        return (_findRef$current2 = findRef.current) === null || _findRef$current2 === void 0 ? void 0 : _findRef$current2.close();
      }
    }, "\u5173\u95ED\u67E5\u627E"), /*#__PURE__*/React.createElement(Button, {
      onClick: function onClick() {
        var _findRef$current3;
        return (_findRef$current3 = findRef.current) === null || _findRef$current3 === void 0 ? void 0 : _findRef$current3.setKeyword('iPhone');
      }
    }, "\u641C\u7D22 iPhone"), /*#__PURE__*/React.createElement(Button, {
      onClick: function onClick() {
        var _findRef$current4;
        var keyword = (_findRef$current4 = findRef.current) === null || _findRef$current4 === void 0 ? void 0 : _findRef$current4.getKeyword();
        alert("\u5F53\u524D\u5173\u952E\u8BCD: ".concat(keyword));
      }
    }, "\u83B7\u53D6\u5173\u952E\u8BCD")), /*#__PURE__*/React.createElement(PisellFind, {
      ref: findRef,
      onSearch: function onSearch(keyword) {
        var filtered = mockProducts.filter(function (item) {
          return item.name.toLowerCase().includes(keyword.toLowerCase());
        });
        setFilteredData(filtered);
      }
    }), /*#__PURE__*/React.createElement(Table, {
      dataSource: filteredData,
      columns: [{
        title: '商品名称',
        dataIndex: 'name'
      }, {
        title: '价格',
        dataIndex: 'price',
        render: function render(v) {
          return "\xA5".concat(v);
        }
      }],
      style: {
        marginTop: 16
      }
    }));
  }
};

/**
 * 显示确认按钮
 */
export var WithConfirmButton = {
  render: function render() {
    var _useState9 = useState(mockProducts),
      _useState10 = _slicedToArray(_useState9, 2),
      filteredData = _useState10[0],
      setFilteredData = _useState10[1];
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 16
      }
    }, /*#__PURE__*/React.createElement(PisellFind, {
      showConfirmButton: true,
      confirmButtonText: "Search",
      onSearch: function onSearch(keyword) {
        var filtered = mockProducts.filter(function (item) {
          return item.name.toLowerCase().includes(keyword.toLowerCase());
        });
        setFilteredData(filtered);
      }
    })), /*#__PURE__*/React.createElement(List, {
      dataSource: filteredData,
      renderItem: function renderItem(item) {
        return /*#__PURE__*/React.createElement(List.Item, null, /*#__PURE__*/React.createElement(List.Item.Meta, {
          title: item.name,
          description: "\xA5".concat(item.price)
        }));
      }
    }));
  }
};

/**
 * 关闭历史记录
 */
export var NoHistory = {
  render: function render() {
    var _useState11 = useState(mockProducts),
      _useState12 = _slicedToArray(_useState11, 2),
      filteredData = _useState12[0],
      setFilteredData = _useState12[1];
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 16
      }
    }, /*#__PURE__*/React.createElement(PisellFind, {
      showHistory: false,
      onSearch: function onSearch(keyword) {
        var filtered = mockProducts.filter(function (item) {
          return item.name.toLowerCase().includes(keyword.toLowerCase());
        });
        setFilteredData(filtered);
      }
    })), /*#__PURE__*/React.createElement(List, {
      dataSource: filteredData,
      renderItem: function renderItem(item) {
        return /*#__PURE__*/React.createElement(List.Item, null, item.name);
      }
    }));
  }
};

/**
 * 多字段搜索
 */
export var MultiFieldSearch = {
  render: function render() {
    var _useState13 = useState(mockProducts),
      _useState14 = _slicedToArray(_useState13, 2),
      filteredData = _useState14[0],
      setFilteredData = _useState14[1];
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 16
      }
    }, /*#__PURE__*/React.createElement(PisellFind, {
      buttonText: "\u641C\u7D22\u5546\u54C1",
      onSearch: function onSearch(keyword) {
        var kw = keyword.toLowerCase();
        var filtered = mockProducts.filter(function (item) {
          return item.name.toLowerCase().includes(kw) || item.category.toLowerCase().includes(kw);
        });
        setFilteredData(filtered);
      }
    }), /*#__PURE__*/React.createElement("p", {
      style: {
        marginTop: 8,
        color: '#999',
        fontSize: 12
      }
    }, "\u652F\u6301\u641C\u7D22\u5546\u54C1\u540D\u79F0\u548C\u5206\u7C7B")), /*#__PURE__*/React.createElement(Table, {
      dataSource: filteredData,
      columns: [{
        title: '商品名称',
        dataIndex: 'name'
      }, {
        title: '价格',
        dataIndex: 'price',
        render: function render(v) {
          return "\xA5".concat(v);
        }
      }, {
        title: '分类',
        dataIndex: 'category',
        render: function render(v) {
          return /*#__PURE__*/React.createElement(Tag, null, v);
        }
      }, {
        title: '库存',
        dataIndex: 'stock'
      }]
    }));
  }
};

/**
 * Drawer 模式
 */
export var DrawerMode = {
  render: function render() {
    var _useState15 = useState(mockProducts),
      _useState16 = _slicedToArray(_useState15, 2),
      filteredData = _useState16[0],
      setFilteredData = _useState16[1];
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 16
      }
    }, /*#__PURE__*/React.createElement(PisellFind, {
      displayType: "drawer",
      drawerPlacement: "right",
      onSearch: function onSearch(keyword) {
        var filtered = mockProducts.filter(function (item) {
          return item.name.toLowerCase().includes(keyword.toLowerCase());
        });
        setFilteredData(filtered);
      }
    })), /*#__PURE__*/React.createElement(List, {
      dataSource: filteredData,
      renderItem: function renderItem(item) {
        return /*#__PURE__*/React.createElement(List.Item, null, /*#__PURE__*/React.createElement(List.Item.Meta, {
          title: item.name,
          description: "\xA5".concat(item.price)
        }));
      }
    }));
  }
};

/**
 * Playground - 自由配置
 */
export var Playground = {
  render: function render() {
    var _useState17 = useState(mockProducts),
      _useState18 = _slicedToArray(_useState17, 2),
      filteredData = _useState18[0],
      setFilteredData = _useState18[1];
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 16
      }
    }, /*#__PURE__*/React.createElement(PisellFind, {
      triggerType: "button",
      buttonText: "Find",
      showConfirmButton: false,
      showHistory: true,
      maxHistoryCount: 10,
      size: "middle",
      disabled: false,
      onSearch: function onSearch(keyword) {
        var filtered = mockProducts.filter(function (item) {
          return item.name.toLowerCase().includes(keyword.toLowerCase());
        });
        setFilteredData(filtered);
      }
    })), /*#__PURE__*/React.createElement(Table, {
      dataSource: filteredData,
      columns: [{
        title: '商品名称',
        dataIndex: 'name'
      }, {
        title: '价格',
        dataIndex: 'price',
        render: function render(v) {
          return "\xA5".concat(v);
        }
      }, {
        title: '分类',
        dataIndex: 'category',
        render: function render(v) {
          return /*#__PURE__*/React.createElement(Tag, null, v);
        }
      }]
    }));
  }
};