const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index = require("../../../booking/components/emptyBooking/index.js");
const require_utils = require("../utils.js");
const require_model = require("../../model.js");
const require_index$1 = require("../../components/Search/index.js");
const require_index$2 = require("../../../tabProduct/index.js");
const require_index$3 = require("./ProductItem/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/components/schedules/products/list/index.tsx
const ProductList = ({ loading, list }) => {
	const [search, setSearch] = (0, react.useState)("");
	const { state, dispatch } = (0, react.useContext)(require_model.Context);
	const { products, currentSelectDayDetail } = state;
	const renderList = (0, react.useMemo)(() => {
		const isIncludes = (str) => {
			return str.toLowerCase().indexOf(search.toLowerCase()) !== -1;
		};
		if (currentSelectDayDetail) return list.filter((item) => isIncludes(item.title));
		return require_utils.formatProductListByCategory(list, search ? (item) => isIncludes(item.title) : void 0);
	}, [
		search,
		list,
		currentSelectDayDetail
	]);
	console.log("state.scheduleMap", renderList);
	const searchChange = (e) => {
		setSearch(e);
	};
	const onClickItem = (item) => {
		let newData = { products: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, products), {}, {
			currentProduct: item,
			openProductDetailDrawer: !currentSelectDayDetail
		}) };
		if (currentSelectDayDetail) newData = {
			tabKey: "schedules",
			products: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, products), {}, {
				currentProduct: item,
				openProductDetailDrawer: !currentSelectDayDetail
			})
		};
		dispatch({
			type: "setState",
			payload: newData
		});
	};
	const empty = (0, react.useMemo)(() => {
		return /* @__PURE__ */ react.default.createElement(require_index.default, { description: _pisell_utils.locales.getText("pisell2.text.products.no-products") });
	}, []);
	const listDom = (0, react.useMemo)(() => {
		if (currentSelectDayDetail) return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-component-products-list-day" }, renderList.map((item) => {
			return /* @__PURE__ */ react.default.createElement(require_index$3.default, {
				key: item.id,
				item,
				onClickItem,
				layout: "day"
			});
		}));
		return /* @__PURE__ */ react.default.createElement(require_index$2.default, {
			scrollDom: ".pisell-lowcode__schedules-component-products",
			list: renderList,
			renderItem: (item) => {
				return /* @__PURE__ */ react.default.createElement(require_index$3.default, {
					key: item.id,
					item,
					onClickItem
				});
			}
		});
	}, [
		currentSelectDayDetail,
		renderList,
		onClickItem
	]);
	return /* @__PURE__ */ react.default.createElement(antd.Skeleton, {
		className: "pisell-lowcode__schedules-component-products-list-wrap",
		round: true,
		active: true,
		loading
	}, !list.length ? empty : /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		value: search,
		onChange: searchChange,
		style: { marginTop: 16 }
	}), renderList.length ? listDom : empty));
};
//#endregion
exports.default = ProductList;
