const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_index = require("./PhoneField/index.js");
const require_serve = require("../serve.js");
const require_index$1 = require("./GenderField/index.js");
const require_index$2 = require("./BirthdayField/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/pisellSelectCustomerModal/RightPanel/Add/index.tsx
const _excluded = ["phone"];
const AddClient = (props) => {
	const { onChange, phone } = props;
	const [form] = antd.Form.useForm();
	const useIsChecked = antd.Form.useWatch("is_checked", form);
	(0, react.useEffect)(() => {
		form.setFieldsValue({ phone: {
			code: "+61",
			phone
		} });
	}, [phone]);
	const _addClient = (0, ahooks.useRequest)(require_serve.addCustomer, {
		manual: true,
		onSuccess: (res, param) => {
			var _param$;
			onChange(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, (_param$ = param[0]) === null || _param$ === void 0 ? void 0 : _param$.customer), {}, { id: res.customer_id }));
		}
	});
	const onFinish = (values) => {
		var _values$phone;
		const { phone } = values, rest = require_objectWithoutProperties._objectWithoutProperties(values, _excluded);
		if (!values.first_name && !values.last_name && !values.email && !(values === null || values === void 0 || (_values$phone = values.phone) === null || _values$phone === void 0 ? void 0 : _values$phone.phone)) {
			antd.message.info(_pisell_utils.locales.getText("pisell2.text.add-client.confirm"));
			return;
		}
		_addClient.run({
			customer: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({
				accepts_marketing: 0,
				register_channel: "shop",
				tax_exempt: 1
			}, rest), {}, {
				first_name: rest.first_name || "",
				last_name: rest.last_name || "",
				note: rest.note || "",
				email: rest.email || "",
				country_calling_code: phone.code || "",
				phone: phone.phone || ""
			}),
			address: {
				first_name: "",
				last_name: "",
				company: "",
				address1: "",
				address2: "",
				city: "",
				country_code: "AU",
				province_code: "ACT",
				phone: "",
				country: "澳大利亚",
				province: "Australian Capital Territory",
				country_calling_code: "+61"
			},
			tags: []
		});
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "select-customer-right-panel-add-client" }, /* @__PURE__ */ react.default.createElement(antd.Form, {
		form,
		onFinish,
		layout: "vertical",
		initialValues: {
			is_checked: 0,
			phone: {
				code: "+61",
				phone: ""
			}
		}
	}, /* @__PURE__ */ react.default.createElement(antd.Row, { gutter: [16, 0] }, /* @__PURE__ */ react.default.createElement(antd.Col, { span: 12 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: _pisell_utils.locales.getText("pisell2.text.firstname"),
		name: "first_name"
	}, /* @__PURE__ */ react.default.createElement(antd.Input, { size: "large" }))), /* @__PURE__ */ react.default.createElement(antd.Col, { span: 12 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: _pisell_utils.locales.getText("pisell2.text.lastname"),
		name: "last_name"
	}, /* @__PURE__ */ react.default.createElement(antd.Input, { size: "large" }))), /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: _pisell_utils.locales.getText("pisell2.text.gender"),
		name: "gender"
	}, /* @__PURE__ */ react.default.createElement(require_index$1.default, null))), /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: _pisell_utils.locales.getText("pisell2.text.birthday"),
		name: "birthday"
	}, /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		itemStyle: { flex: 1 },
		style: {
			display: "flex",
			gap: 16,
			width: "100%"
		},
		useSpace: false
	}))), /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: _pisell_utils.locales.getText("pisell2.text.phone"),
		name: "phone"
	}, /* @__PURE__ */ react.default.createElement(require_index.default, null))), /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: _pisell_utils.locales.getText("pisell2.text.email"),
		name: "email",
		rules: [{
			pattern: /^([a-zA-Z0-9_\-\.+])+@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,63})+$/,
			message: _pisell_utils.locales.getText("pisell2.text.email-error-message")
		}]
	}, /* @__PURE__ */ react.default.createElement(antd.Input, { size: "large" }))), /* @__PURE__ */ react.default.createElement(antd.Col, { span: 24 }, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		label: _pisell_utils.locales.getText("pisell2.text.notes"),
		name: "note"
	}, /* @__PURE__ */ react.default.createElement(antd.Input.TextArea, { size: "large" }))), /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
		hidden: true,
		name: "is_checked"
	}, /* @__PURE__ */ react.default.createElement(antd.Input, null))), /* @__PURE__ */ react.default.createElement("div", { className: "select-customer-right-panel-add-client__footer" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		size: "large",
		style: { flex: 1 },
		onClick: () => {
			form.setFieldsValue({ is_checked: 0 });
			form.submit();
		},
		loading: _addClient.loading && !useIsChecked
	}, _pisell_utils.locales.getText("pisell2.text.save")), /* @__PURE__ */ react.default.createElement(antd.Button, {
		type: "primary",
		size: "large",
		style: { flex: 1 },
		onClick: () => {
			form.setFieldsValue({ is_checked: 1 });
			form.submit();
		},
		loading: _addClient.loading && useIsChecked
	}, _pisell_utils.locales.getText("pisell2.text.save-and-select")))));
};
//#endregion
exports.default = AddClient;
