var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellList01/index.tsx
var pisellList01_exports = {};
__export(pisellList01_exports, {
  default: () => pisellList01_default
});
module.exports = __toCommonJS(pisellList01_exports);
var import_react = __toESM(require("react"));
var import_icons = require("@ant-design/icons");
var import_pisellViewGrid = __toESM(require("../pisellViewGrid"));
var import_pisellAnchor = __toESM(require("../pisellAnchor"));
var import_pisellEmpty = __toESM(require("../pisellEmpty"));
var import_input = __toESM(require("../input"));
var import_index = require("./index.less");
var PisellList01 = ({
  showSearch,
  showCategory,
  placeholder,
  dataSource,
  renderItem,
  className,
  style,
  onChange,
  onSearch,
  isShowEmpty = true,
  description
}) => {
  const [currentAnchor, setCurrentAnchor] = (0, import_react.useState)("");
  const [products, setProducts] = (0, import_react.useState)([]);
  (0, import_react.useEffect)(() => {
    if (!showCategory) {
      return setProducts(dataSource ?? []);
    }
    if (currentAnchor) {
      const currentData = dataSource == null ? void 0 : dataSource.find(
        (item) => item.href === currentAnchor
      );
      setProducts((currentData == null ? void 0 : currentData.children) ?? []);
    }
  }, [currentAnchor, dataSource, showCategory]);
  (0, import_react.useEffect)(() => {
    var _a;
    setCurrentAnchor(((_a = dataSource == null ? void 0 : dataSource[0]) == null ? void 0 : _a.href) ?? "");
  }, [dataSource]);
  const categoryTitle = (0, import_react.useMemo)(() => {
    var _a;
    return (_a = dataSource == null ? void 0 : dataSource.find((item) => item.href === currentAnchor)) == null ? void 0 : _a.title;
  }, [currentAnchor, dataSource]);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `pisell-list-01 ${className}`, style }, showSearch ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-list-01-search" }, /* @__PURE__ */ import_react.default.createElement(
    import_input.default,
    {
      placeholder: placeholder || "Search",
      prefix: /* @__PURE__ */ import_react.default.createElement(import_icons.SearchOutlined, { style: { color: "#667085" } }),
      onChange: onSearch,
      allowClear: true,
      size: "large",
      className: "pisell-list-01-search-input"
    }
  )) : null, showCategory ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-list-01-categories" }, /* @__PURE__ */ import_react.default.createElement(
    import_pisellAnchor.default,
    {
      items: dataSource,
      getCurrentAnchor: currentAnchor,
      onChange: (e) => {
        onChange == null ? void 0 : onChange(e);
        setCurrentAnchor(e);
      }
    }
  )) : null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `pisell-list-01-products ${!products.length && isShowEmpty ? "pisell-list-01-products-empty" : ""}`
    },
    showCategory ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-list-01-products-title" }, categoryTitle) : null,
    products.length > 0 ? /* @__PURE__ */ import_react.default.createElement(
      import_pisellViewGrid.default,
      {
        dataSource: products,
        columns: 1,
        verticalGap: 16,
        renderItem
      }
    ) : isShowEmpty ? /* @__PURE__ */ import_react.default.createElement(import_pisellEmpty.default, { description }) : null
  ));
};
var pisellList01_default = PisellList01;
