const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_utils = require("../booking/utils.js");
const require_index = require("../booking/components/drawer/index.js");
const require_index$1 = require("../booking/components/addButton/index.js");
const require_index$2 = require("../tabProduct/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_icon_es_SearchLg = require("@pisell/icon/es/SearchLg");
_pisell_icon_es_SearchLg = require_runtime.__toESM(_pisell_icon_es_SearchLg);
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./index.less");
//#region src/components/selectModal/index.tsx
const MAX_LENGTH = 999;
const SelectModal = (props) => {
	const { value, onChange, dataSource = [], renderValueItem, renderOptionItem, disabled, className, style, maxLength = MAX_LENGTH, buttonProps, drawerProps, tabProductProps, loading } = props;
	const [open, setOpen] = (0, react.useState)(false);
	const [search, setSearch] = (0, react.useState)("");
	const _value = (0, react.useMemo)(() => {
		return value || [];
	}, [value]);
	const onOpen = () => {
		setOpen(true);
	};
	const onClose = () => {
		setSearch("");
		setOpen(false);
	};
	const renderList = (0, react.useMemo)(() => {
		let _list = dataSource || [];
		const isIncludes = (str) => {
			return str.toLowerCase().indexOf(search.toLowerCase()) !== -1;
		};
		return require_utils.formatProductListByCategory(_list, search ? (item) => isIncludes(item.title) : void 0);
	}, [search, dataSource]);
	const onSelect = (item) => {
		onChange === null || onChange === void 0 || onChange((0, _pisell_utils.changeArray)(_value, item, "id"));
		onClose();
	};
	return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("pisell2-select-modal", className),
		style
	}, /* @__PURE__ */ react.default.createElement(antd.Skeleton, {
		active: true,
		round: true,
		loading
	}, _value.map((item) => {
		return renderValueItem === null || renderValueItem === void 0 ? void 0 : renderValueItem(item, (item) => {
			onOpen();
		});
	})), _value.length < maxLength ? /* @__PURE__ */ react.default.createElement(require_index$1.default, require_objectSpread2._objectSpread2({ onClick: onOpen }, buttonProps)) : null, /* @__PURE__ */ react.default.createElement(require_index.default, require_objectSpread2._objectSpread2({
		open,
		onClose,
		header: /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-service-header" }, /* @__PURE__ */ react.default.createElement(antd.Input, {
			prefix: /* @__PURE__ */ react.default.createElement(_pisell_icon_es_SearchLg.default, null),
			style: {
				marginTop: 16,
				height: 44
			},
			placeholder: "",
			allowClear: true,
			value: search,
			onChange: (e) => {
				setSearch(e.target.value);
			}
		}))
	}, drawerProps), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-service-body" }, /* @__PURE__ */ react.default.createElement(require_index$2.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({ list: renderList }, tabProductProps), {}, { renderItem: (item) => {
		return renderOptionItem === null || renderOptionItem === void 0 ? void 0 : renderOptionItem(item, onSelect);
	} })))));
};
//#endregion
exports.default = SelectModal;
