import useEngineContext from "../../../../hooks/useEngineContext.js";
import withResponsive from "../../../../responsive/withResponsive.js";
import { ClientSelector } from "./ClientSelector.js";
import React from "react";
import { useMemoizedFn } from "ahooks";
import "./index.less";
//#region src/plus/saleDetail/components/Client/index.tsx
function ClientBase({ dataSource, className, isShowAvatar, variant }) {
	const context = useEngineContext();
	const customerState = dataSource.customer;
	const selectedCustomer = customerState.selected;
	const handleSelectClient = useMemoizedFn((record) => {
		customerState.select(record);
	});
	const handleContactsInfoChange = useMemoizedFn((contactsInfo) => {
		dataSource.sales.setContactsInfo(contactsInfo);
	});
	const handleOpenCustomerDetail = 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.createElement(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 = withResponsive(ClientBase);
//#endregion
export { Client };
