const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_useEngineContext = require("../../../hooks/useEngineContext.js");
const require_index = require("../../../utils/index.js");
const require_serve = require("./serve.js");
const require_index$1 = require("./List/index.js");
const require_index$2 = require("./Add/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_icon_es_PlusCircle = require("@pisell/icon/es/PlusCircle");
_pisell_icon_es_PlusCircle = require_runtime.__toESM(_pisell_icon_es_PlusCircle);
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
let _pisell_icon_es_ChevronLeft = require("@pisell/icon/es/ChevronLeft");
_pisell_icon_es_ChevronLeft = require_runtime.__toESM(_pisell_icon_es_ChevronLeft);
require("./index.less");
//#region src/components/pisellSelectCustomerModal/RightPanel/index.tsx
const defaultParams = {
	skip: 1,
	num: 10,
	sort_by: "id",
	search: ""
};
const RightPanel = (props) => {
	const { value, onChange, phone } = props;
	const [page, setPage] = (0, react.useState)("list");
	const context = require_useEngineContext.default();
	require_index.request.setRequest(context.appHelper.utils.request);
	const [customerOrigin, setCustomerOrigin] = (0, react.useState)({
		skip: 1,
		count: 0,
		list: []
	});
	const [params, setParams] = (0, react.useState)(defaultParams);
	const _getCustomerList = (0, ahooks.useRequest)(require_serve.getCustomerList, {
		manual: true,
		onSuccess: (res, param) => {
			const _params = param[0];
			setParams(_params);
			let list = [];
			if (_params.skip === 1) list = res.list;
			else list = customerOrigin.list.concat(res.list);
			setCustomerOrigin(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, res), {}, { list }));
		}
	});
	(0, react.useEffect)(() => {
		if (page !== "list") return;
		_getCustomerList.run(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, defaultParams), {}, { search: phone }));
	}, [phone, page]);
	const header = (0, react.useMemo)(() => {
		if (page === "list") return /* @__PURE__ */ react.default.createElement("div", { className: "select-customer-right-panel-header" }, /* @__PURE__ */ react.default.createElement("span", null, phone ? _pisell_utils.locales.getText("pisell2.text.result-found") : _pisell_utils.locales.getText("pisell2.text.personnel-list")), /* @__PURE__ */ react.default.createElement("span", {
			className: "select-customer-right-panel-header-create-btn",
			onClick: () => {
				setPage("create");
			}
		}, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_PlusCircle.default, { className: "select-customer-right-panel-header-icon" }), _pisell_utils.locales.getText("pisell2.text.create")));
		return /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("select-customer-right-panel-header", { "select-customer-right-panel-header-create": page === "create" }) }, /* @__PURE__ */ react.default.createElement(_pisell_icon_es_ChevronLeft.default, {
			className: "select-customer-right-panel-header-icon select-customer-right-panel-header-icon-back",
			onClick: () => {
				setPage("list");
			}
		}), _pisell_utils.locales.getText("pisell2.text.create-new-client"));
	}, [phone, page]);
	/**
	* @title: 创建客户
	* @description:
	* @param {any} values
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-11-02 09:31
	*/
	const addChange = (values) => {
		setPage("list");
		if (values === null || values === void 0 ? void 0 : values.is_checked) onChange === null || onChange === void 0 || onChange(values);
		setCustomerOrigin(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, customerOrigin), {}, {
			count: customerOrigin.count + 1,
			list: [values].concat(customerOrigin.list)
		}));
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "select-customer-right-panel" }, /* @__PURE__ */ react.default.createElement("div", { className: "select-customer-right-panel-header" }, header), page === "list" ? /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		loading: _getCustomerList.loading,
		phone,
		customerOrigin,
		value,
		onChange,
		onLoadMore: () => {
			if (customerOrigin.list.length >= customerOrigin.count) return;
			_getCustomerList.run(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, params), {}, { skip: params.skip + 1 }));
		},
		setPage
	}) : null, page === "create" ? /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		phone,
		onChange: addChange
	}) : null);
};
//#endregion
exports.default = RightPanel;
