import { _asyncToGenerator } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import useSendModal from "./sendModal/useSendModal.js";
import SendModal from "./sendModal/index.js";
import React, { useMemo } from "react";
import { locales } from "@pisell/utils";
import { Button, Tooltip, message } from "@pisell/materials";
import { ReloadOutlined } from "@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 } = useSendModal(state === null || state === void 0 ? void 0 : state.bookingId);
	const handleReload = function() {
		var _ref = _asyncToGenerator(function* () {
			yield reload();
			message.success(locales.getText("pisell2.text.send-form-reminder-refresh"));
		});
		return function handleReload() {
			return _ref.apply(this, arguments);
		};
	}();
	const defaultValues = 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.createElement("div", { className: "pisell-lowcode__booking-form-footer" }, /* @__PURE__ */ React.createElement(Tooltip, { title: locales.getText("pisell2.text.send-form-reminder-tooltip") }, /* @__PURE__ */ React.createElement(Button, {
		size: "large",
		icon: /* @__PURE__ */ React.createElement(ReloadOutlined, null),
		onClick: handleReload
	})), /* @__PURE__ */ React.createElement(Button, {
		size: "large",
		block: true,
		type: "primary",
		onClick: handleOpen
	}, locales.getText("pisell2.text.send-form-reminder")), open && /* @__PURE__ */ React.createElement(SendModal, {
		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
export { Footer as default };
