const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useSendModal = require("./sendModal/useSendModal.js");
const require_index = require("./sendModal/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let _ant_design_icons = require("@ant-design/icons");
//#region src/components/booking/forms/footer.tsx
const Footer = ({ state, reload }) => {
	var _state$client2, _state$contacts_info2, _state$form, _state$client3;
	const { open, setOpen, handleOpen, handleValuesChange, handleOk } = require_useSendModal.default(state === null || state === void 0 ? void 0 : state.bookingId);
	const handleReload = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			yield reload();
			_pisell_materials.message.success(_pisell_utils.locales.getText("pisell2.text.send-form-reminder-refresh"));
		});
		return function handleReload() {
			return _ref.apply(this, arguments);
		};
	}();
	const defaultValues = (0, react.useMemo)(() => {
		var _state$contacts_info, _state$client;
		const { email: contactsEmail, phone: contactsPhone } = ((_state$contacts_info = state.contacts_info) === null || _state$contacts_info === void 0 ? void 0 : _state$contacts_info.value) || {};
		const { email: clientEmail, phone: clientPhone, country_calling_code: clientCode } = ((_state$client = state.client) === null || _state$client === void 0 ? void 0 : _state$client.value) || {};
		let email = contactsEmail || clientEmail;
		let phone = (contactsPhone === null || contactsPhone === void 0 ? void 0 : contactsPhone.phone) || clientPhone;
		let code = (contactsPhone === null || contactsPhone === void 0 ? void 0 : contactsPhone.country_calling_code) || clientCode || "+61";
		if (!code.startsWith("+")) code = `+${code}`;
		return {
			sendSms: !!phone,
			sendEmail: !!email,
			email,
			phone: {
				code,
				phone
			}
		};
	}, [(_state$client2 = state.client) === null || _state$client2 === void 0 ? void 0 : _state$client2.value, (_state$contacts_info2 = state.contacts_info) === null || _state$contacts_info2 === void 0 ? void 0 : _state$contacts_info2.value]);
	if (!state.bookingId || !(state === null || state === void 0 || (_state$form = state.form) === null || _state$form === void 0 ? void 0 : _state$form.forms.length)) return null;
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__booking-form-footer" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Tooltip, { title: _pisell_utils.locales.getText("pisell2.text.send-form-reminder-tooltip") }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		size: "large",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.ReloadOutlined, null),
		onClick: handleReload
	})), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		size: "large",
		block: true,
		type: "primary",
		onClick: handleOpen
	}, _pisell_utils.locales.getText("pisell2.text.send-form-reminder")), open && /* @__PURE__ */ react.default.createElement(require_index.default, {
		refreshKey: (_state$client3 = state.client) === null || _state$client3 === void 0 || (_state$client3 = _state$client3.value) === null || _state$client3 === void 0 ? void 0 : _state$client3.id,
		open,
		onCancel: () => setOpen(false),
		onOk: handleOk,
		onValuesChange: handleValuesChange,
		defaultValues
	}));
};
//#endregion
exports.default = Footer;
