const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_model = require("../../../info/model.js");
const require_index = require("../../../../../plus/contactInfo/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
//#region src/components/booking/info2/service/contactInfoMode/index.tsx
const ContactInfoMode = () => {
	var _state$client$value6, _state$contacts_info3, _state$contacts_info4;
	const { state, dispatch } = (0, react.useContext)(require_model.Context);
	console.log("state>>>>>>>>>", state);
	(0, react.useEffect)(() => {
		var _state$contacts_info, _state$client$value, _state$client$value2, _state$contacts_info2;
		console.log("state>>>>>>>>>111", state === null || state === void 0 || (_state$contacts_info = state.contacts_info) === null || _state$contacts_info === void 0 ? void 0 : _state$contacts_info.client_id);
		console.log("state>>>>>>>>>222", (_state$client$value = state.client.value) === null || _state$client$value === void 0 ? void 0 : _state$client$value.id);
		if (((_state$client$value2 = state.client.value) === null || _state$client$value2 === void 0 ? void 0 : _state$client$value2.id) != (state === null || state === void 0 || (_state$contacts_info2 = state.contacts_info) === null || _state$contacts_info2 === void 0 ? void 0 : _state$contacts_info2.client_id)) {
			var _state$client$value3;
			const contactInfo = (_state$client$value3 = state.client.value) === null || _state$client$value3 === void 0 || (_state$client$value3 = _state$client$value3.contacts_info) === null || _state$client$value3 === void 0 ? void 0 : _state$client$value3.value;
			if (!contactInfo) {
				var _state$client, _state$client$value4;
				const { first_name, last_name, phone, country_calling_code, country_code, email } = ((_state$client = state.client) === null || _state$client === void 0 ? void 0 : _state$client.value) || {};
				dispatch({
					type: "setContactsInfo",
					payload: {
						value: {
							first_name: first_name || "",
							last_name: last_name || "",
							phone: {
								phone: phone || "",
								country_calling_code: country_calling_code || "",
								country_code: country_code || ""
							},
							email: email || ""
						},
						client_id: (_state$client$value4 = state.client.value) === null || _state$client$value4 === void 0 ? void 0 : _state$client$value4.id
					}
				});
			} else {
				var _state$client$value5;
				dispatch({
					type: "setContactsInfo",
					payload: {
						value: require_objectSpread2._objectSpread2({}, contactInfo || {}),
						client_id: (_state$client$value5 = state.client.value) === null || _state$client$value5 === void 0 ? void 0 : _state$client$value5.id
					}
				});
			}
		}
	}, [(_state$client$value6 = state.client.value) === null || _state$client$value6 === void 0 ? void 0 : _state$client$value6.id, state === null || state === void 0 || (_state$contacts_info3 = state.contacts_info) === null || _state$contacts_info3 === void 0 ? void 0 : _state$contacts_info3.client_id]);
	const handleSave = (value) => {
		dispatch({
			type: "setContactsInfo",
			payload: {
				value,
				edit: true
			}
		});
	};
	return /* @__PURE__ */ react.default.createElement("div", { style: { marginTop: "24px" } }, /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-lowcode__booking-contact-info-title",
		style: {
			fontSize: "16px",
			fontWeight: 500,
			marginBottom: "8px"
		}
	}, _pisell_utils.locales.getText("pisell2.booking.text.contact-info.title")), /* @__PURE__ */ react.default.createElement(require_index.default, {
		dataSource: ((_state$contacts_info4 = state.contacts_info) === null || _state$contacts_info4 === void 0 ? void 0 : _state$contacts_info4.value) || null,
		isShowDelete: false,
		isShowAvatar: false,
		isShowPhone: true,
		isShowEmail: true,
		style: { padding: "14px 0 14px 14px" },
		onSave: handleSave
	}));
};
//#endregion
exports.default = ContactInfoMode;
