const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_withResponsive = require("../../../../responsive/withResponsive.js");
const require_ClientSelector = require("./ClientSelector.js");
let react = require("react");
react = require_runtime.__toESM(react);
let ahooks = require("ahooks");
require("./index.less");
//#region src/plus/saleDetail/components/Client/index.tsx
function ClientBase({ dataSource, className, isShowAvatar, variant }) {
	const context = require_useEngineContext.default();
	const customerState = dataSource.customer;
	const selectedCustomer = customerState.selected;
	const handleSelectClient = (0, ahooks.useMemoizedFn)((record) => {
		customerState.select(record);
	});
	const handleContactsInfoChange = (0, ahooks.useMemoizedFn)((contactsInfo) => {
		dataSource.sales.setContactsInfo(contactsInfo);
	});
	const handleOpenCustomerDetail = (0, ahooks.useMemoizedFn)((record, onSuccess) => {
		var _context$appHelper;
		const action = (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.action;
		if (!action || !(record === null || record === void 0 ? void 0 : record.id)) return;
		action({
			type: "pisell1.handleOpenCustomerModal",
			data: { id: record.id },
			callback: onSuccess
		});
	});
	return /* @__PURE__ */ react.default.createElement(require_ClientSelector.ClientSelector, {
		className,
		value: selectedCustomer,
		list: customerState.list,
		loading: customerState.loading,
		loadingMore: customerState.loadingMore,
		hasMore: customerState.hasMore,
		pagination: customerState.pagination,
		isShowAvatar,
		variant,
		onSearch: customerState.search,
		onLoadMore: customerState.loadMore,
		onChangePage: customerState.changePage,
		onSelect: handleSelectClient,
		onAddToFirst: (record) => {
			customerState.addToFirst(record);
		},
		resolveContactsInfo: (record) => {
			var _ref;
			return (record === null || record === void 0 || (_ref = record.contacts_info) === null || _ref === void 0 ? void 0 : _ref.value) || null;
		},
		onContactsInfoChange: handleContactsInfoChange,
		onOpenCustomerDetail: handleOpenCustomerDetail
	});
}
ClientBase.displayName = "Client";
const Client = require_withResponsive.default(ClientBase);
//#endregion
exports.Client = Client;
