const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../clientName/index.js");
const require_InfiniteScroll = require("../InfiniteScroll/InfiniteScroll.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/plus/clinetSearch/ResultList/index.tsx
const ResultListTag = antd.Tag;
const ResultList = (0, react.forwardRef)(({ dataSource, hasMore, loading, holderTitle, onLoadMore, onRowClick, translateText }, ref) => {
	const scrollContainerRef = (0, react.useRef)(null);
	const scrollContainerIdRef = (0, react.useRef)(`client-search-result-list-scroll-${Math.random().toString(36).slice(2)}`);
	(0, react.useImperativeHandle)(ref, () => ({ resetScrollPosition: () => {
		if (scrollContainerRef.current) {
			scrollContainerRef.current.scrollTop = 0;
			scrollContainerRef.current.scrollLeft = 0;
		}
	} }));
	const renderHeader = () => {
		if (!(dataSource === null || dataSource === void 0 ? void 0 : dataSource.length)) return null;
		return /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__header" }, /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--name" }, _pisell_utils.locales.getText("pisell2.text.client-search.name")), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--register-time" }, _pisell_utils.locales.getText("pisell2.text.client-search.register-time")), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--membership" }, _pisell_utils.locales.getText("pisell2.text.client-search.membership")), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--contact-info" }, _pisell_utils.locales.getText("pisell2.text.client-search.contact-info")), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__header-cell client-search-result-list__cell--holder" }, holderTitle || _pisell_utils.locales.getText("pisell2.text.client-search.holder")));
	};
	return /* @__PURE__ */ react.default.createElement("div", {
		ref: scrollContainerRef,
		id: scrollContainerIdRef.current,
		className: "client-search-result-list"
	}, loading && /* @__PURE__ */ react.default.createElement(antd.Spin, {
		spinning: loading || false,
		className: "pisell-client-search-result-loading",
		size: "large"
	}), renderHeader(), /* @__PURE__ */ react.default.createElement(require_InfiniteScroll.default, {
		dataLength: dataSource.length,
		next: () => onLoadMore === null || onLoadMore === void 0 ? void 0 : onLoadMore(),
		hasMore: hasMore || false,
		className: "client-search-result-list__infinite",
		loader: /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__message" }, _pisell_utils.locales.getText("pisell2.text.loading")),
		endMessage: /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__message" }, (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) ? _pisell_utils.locales.getText("pisell2.text.no-more-data") : null),
		scrollableTarget: scrollContainerIdRef.current,
		scrollThreshold: "180px"
	}, /* @__PURE__ */ react.default.createElement(antd.List, {
		className: "client-search-result-list__list",
		dataSource,
		renderItem: (item, index) => {
			var _latest_wallet_detail, _item$contacts_info, _item$contacts_info2, _item$contacts_info3, _item$form_record;
			const membershipText = (_latest_wallet_detail = item.latest_wallet_detail) === null || _latest_wallet_detail === void 0 || (_latest_wallet_detail = _latest_wallet_detail.wallet) === null || _latest_wallet_detail === void 0 ? void 0 : _latest_wallet_detail.name;
			const translatedMembershipText = translateText === null || translateText === void 0 ? void 0 : translateText(membershipText);
			return /* @__PURE__ */ react.default.createElement(antd.List.Item, {
				key: item.id,
				className: "client-search-result-list__item"
			}, /* @__PURE__ */ react.default.createElement("div", {
				className: "client-search-result-list__item-content",
				onClick: () => onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(item, index || 0)
			}, /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--name" }, /* @__PURE__ */ react.default.createElement(require_index.default, { dataSource: item }), /* @__PURE__ */ react.default.createElement("div", null, item.phone || "-"), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__ellipsis" }, item.email || "-")), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--register-time" }, (0, dayjs.default)(item.created_at).format("YYYY-MM-DD") || "-"), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--membership" }, membershipText && translatedMembershipText ? /* @__PURE__ */ react.default.createElement(ResultListTag, {
				color: "gold",
				className: "client-search-result-list__membership-tag"
			}, translatedMembershipText) : "-"), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--contact-info" }, /* @__PURE__ */ react.default.createElement(require_index.default, { dataSource: item === null || item === void 0 || (_item$contacts_info = item.contacts_info) === null || _item$contacts_info === void 0 ? void 0 : _item$contacts_info.value }), /* @__PURE__ */ react.default.createElement("div", null, (item === null || item === void 0 || (_item$contacts_info2 = item.contacts_info) === null || _item$contacts_info2 === void 0 || (_item$contacts_info2 = _item$contacts_info2.value) === null || _item$contacts_info2 === void 0 || (_item$contacts_info2 = _item$contacts_info2.phone) === null || _item$contacts_info2 === void 0 ? void 0 : _item$contacts_info2.phone) || "-"), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__ellipsis" }, (item === null || item === void 0 || (_item$contacts_info3 = item.contacts_info) === null || _item$contacts_info3 === void 0 || (_item$contacts_info3 = _item$contacts_info3.value) === null || _item$contacts_info3 === void 0 ? void 0 : _item$contacts_info3.email) || "-")), /* @__PURE__ */ react.default.createElement("div", { className: "client-search-result-list__cell client-search-result-list__cell--holder" }, (item === null || item === void 0 || (_item$form_record = item.form_record) === null || _item$form_record === void 0 ? void 0 : _item$form_record.length) > 0 ? item.form_record.map((itemForm) => {
				return /* @__PURE__ */ react.default.createElement("div", {
					key: itemForm === null || itemForm === void 0 ? void 0 : itemForm.id,
					className: "client-search-result-list__ellipsis"
				}, (itemForm === null || itemForm === void 0 ? void 0 : itemForm.main_field) || "-");
			}) : "-")));
		}
	})));
});
//#endregion
exports.default = ResultList;
