const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_index = require("../pisellViewGrid/index.js");
const require_index$1 = require("../input/index.js");
const require_index$2 = require("../pisellEmpty/index.js");
const require_index$3 = require("../pisellAnchor/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _ant_design_icons = require("@ant-design/icons");
require("./index.less");
//#region src/components/pisellList01/index.tsx
const PisellList01 = ({ showSearch, showCategory, placeholder, dataSource, renderItem, className, style, onChange, onSearch, isShowEmpty = true, description }) => {
	const [currentAnchor, setCurrentAnchor] = (0, react.useState)("");
	const [products, setProducts] = (0, react.useState)([]);
	(0, react.useEffect)(() => {
		if (!showCategory) return setProducts(dataSource !== null && dataSource !== void 0 ? dataSource : []);
		if (currentAnchor) {
			var _currentData$children;
			const currentData = dataSource === null || dataSource === void 0 ? void 0 : dataSource.find((item) => item.href === currentAnchor);
			setProducts((_currentData$children = currentData === null || currentData === void 0 ? void 0 : currentData.children) !== null && _currentData$children !== void 0 ? _currentData$children : []);
		}
	}, [
		currentAnchor,
		dataSource,
		showCategory
	]);
	(0, react.useEffect)(() => {
		var _dataSource$0$href, _dataSource$;
		setCurrentAnchor((_dataSource$0$href = dataSource === null || dataSource === void 0 || (_dataSource$ = dataSource[0]) === null || _dataSource$ === void 0 ? void 0 : _dataSource$.href) !== null && _dataSource$0$href !== void 0 ? _dataSource$0$href : "");
	}, [dataSource]);
	/**
	* @title: 分类标题
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-13 16:21
	*/
	const categoryTitle = (0, react.useMemo)(() => {
		var _dataSource$find;
		return dataSource === null || dataSource === void 0 || (_dataSource$find = dataSource.find((item) => item.href === currentAnchor)) === null || _dataSource$find === void 0 ? void 0 : _dataSource$find.title;
	}, [currentAnchor, dataSource]);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: `pisell-list-01 ${className}`,
		style
	}, showSearch ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-list-01-search" }, /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		placeholder: placeholder || "Search",
		prefix: /* @__PURE__ */ react.default.createElement(_ant_design_icons.SearchOutlined, { style: { color: "#667085" } }),
		onChange: onSearch,
		allowClear: true,
		size: "large",
		className: "pisell-list-01-search-input"
	})) : null, showCategory ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-list-01-categories" }, /* @__PURE__ */ react.default.createElement(require_index$3.default, {
		items: dataSource,
		getCurrentAnchor: currentAnchor,
		onChange: (e) => {
			onChange === null || onChange === void 0 || onChange(e);
			setCurrentAnchor(e);
		}
	})) : null, /* @__PURE__ */ react.default.createElement("div", { className: `pisell-list-01-products ${!products.length && isShowEmpty ? "pisell-list-01-products-empty" : ""}` }, showCategory ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-list-01-products-title" }, categoryTitle) : null, products.length > 0 ? /* @__PURE__ */ react.default.createElement(require_index.default, {
		dataSource: products,
		columns: 1,
		verticalGap: 16,
		renderItem
	}) : isShowEmpty ? /* @__PURE__ */ react.default.createElement(require_index$2.default, { description }) : null));
};
//#endregion
exports.default = PisellList01;
