try {
	let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
	n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "63af1994-830f-4ea1-9503-b435991b2506", e._sentryDebugIdIdentifier = "sentry-dbid-63af1994-830f-4ea1-9503-b435991b2506");
} catch (e) {}
import { o as createLogger, r as useTranslation } from "./translation-Br5wIPO-.js";
import { r as Loader, t as Button } from "./Button-BDEdGXnd.js";
import { r as useLegalEntity, t as ROOT_LE } from "./useLegalEntity-Dm6g0wmt.js";
import { t as Header } from "./Header-B_MIsVov.js";
import { C as EntityTypes } from "./processCapabilities-CDSEJpB8.js";
import { t as useAnalyticsContext } from "./useAnalyticsContext-DfTXpZbA.js";
import { t as useToastContext } from "./useToastContext-CK7UoZ5Z.js";
import { n as useCapabilityProblems, t as getProblemsForEntity } from "./getProblemsForEntity-COcJt47f.js";
import { t as useUpdateLegalEntity } from "./useUpdateLegalEntity-CUs6TYPF.js";
import { a as defaultFieldMetadata, i as contactDetailsValidationRules, l as useValidatePhoneNumberImperatively, o as fieldConfig, s as getAsyncPhoneValidationRules, t as ContactDetails } from "./ContactDetails-C3MS4diz.js";
import { t as ErrorPanel } from "./ErrorPanel-5g1eTEVD.js";
import { t as createFormUtils } from "./formUtils-DERTAXyh.js";
import { t as useMultiForm } from "./useMultiForm-tpVMuqHM.js";
import { t as useTaskLandedEvent } from "./useTaskLandedEvent-DCdJo64z.js";
import { t as resolveFieldMetadata } from "./fieldConfigurations-B3oqm4GC.js";
import { t as Spacer } from "./Spacer-D1yp_1Io.js";
import { useCallback, useMemo } from "preact/hooks";
import { jsx, jsxs } from "preact/jsx-runtime";
import { useQueryClient } from "@tanstack/preact-query";
//#region src/components/Shared/tasks/CustomerSupport/mapping/mapCustomerSupportSchemaToCustomerSupportType.ts
var mapCustomerSupportSchemaToCustomerSupportType = (customerSupport) => {
	return {
		email: customerSupport?.customerSupport?.email || "",
		phone: {
			number: customerSupport?.customerSupport?.phoneNumber?.number || "",
			type: "mobile"
		}
	};
};
//#endregion
//#region src/components/Shared/tasks/CustomerSupport/CustomerSupport.tsx
var logger = createLogger();
var CustomerSupport = (props) => {
	const { data, isLoading } = useLegalEntity(ROOT_LE);
	if (isLoading || !data) return /* @__PURE__ */ jsx(Loader, { size: "large" });
	return /* @__PURE__ */ jsx(CustomerSupportInner, {
		...props,
		legalEntity: data
	});
};
function CustomerSupportInner({ country, onSubmit, legalEntity }) {
	const capabilityProblems = useCapabilityProblems();
	const problems = capabilityProblems ? getProblemsForEntity(capabilityProblems, EntityTypes.LEGAL_ENTITY, legalEntity.id) : void 0;
	const { t } = useTranslation("common");
	const userEvents = useAnalyticsContext();
	const { showToast } = useToastContext();
	const formUtils = createFormUtils({}, t);
	const { mutateAsync: updateLegalEntity } = useUpdateLegalEntity();
	const queryClient = useQueryClient();
	const requiredFields = { customerSupport: ["email", "phoneNumber"] };
	const validators = useCallback((data) => ({ customerSupport: {
		...contactDetailsValidationRules,
		phoneNumber: resolveFieldMetadata(fieldConfig[data?.customerSupport?.phoneNumber?.phoneCountryCode ?? country], {}, defaultFieldMetadata)?.validators
	} }), [country]);
	const validatePhoneNumber = useValidatePhoneNumberImperatively();
	const asyncValidators = useMemo(() => ({ customerSupport: { phoneNumber: getAsyncPhoneValidationRules(validatePhoneNumber).phoneNumber } }), [validatePhoneNumber]);
	const legalEntityType = legalEntity.type;
	const { data, handleChangeFor, valid, errors, isValid, triggerValidation } = useMultiForm({
		requiredFields,
		defaultData: { customerSupport: {
			phoneNumber: legalEntity[legalEntityType]?.support?.phone,
			email: legalEntity[legalEntityType]?.support?.email
		} },
		rules: validators,
		asyncRules: asyncValidators
	});
	/**
	* Analytics
	*/
	useTaskLandedEvent("CUSTOMER_SUPPORT");
	const submitForm = async () => {
		const isAsyncValidationValid = await triggerValidation("customerSupport");
		if (!isValid?.customerSupport || !isAsyncValidationValid) return;
		const support = mapCustomerSupportSchemaToCustomerSupportType(data);
		const payload = { [legalEntityType]: { support } };
		try {
			await updateLegalEntity({
				...payload,
				id: legalEntity.id
			});
			queryClient.invalidateQueries({ queryKey: ["legalEntity", legalEntity?.id] });
			onSubmit();
			userEvents.addTaskEvent("Success", { actionType: "submit" });
		} catch {
			const label = t(($) => $["failedToUpdateDetails"]);
			logger.error(label, payload);
			showToast({
				label,
				variant: "error"
			});
		}
	};
	const handleFieldChange = (fieldName, mode) => handleChangeFor(fieldName, "customerSupport", mode);
	return /* @__PURE__ */ jsxs("form", {
		"aria-describedby": "ariaErrorField",
		children: [
			/* @__PURE__ */ jsx(Header, {
				title: t(($) => $["customerSupport"]),
				description: t(($) => $["howYourCustomersCanReachYou"])
			}),
			/* @__PURE__ */ jsx(ErrorPanel, {
				verificationErrors: problems?.verificationErrors?.["customerSupport"],
				formUtils,
				id: "ariaErrorField"
			}),
			/* @__PURE__ */ jsx(ContactDetails, {
				data: data.customerSupport,
				errors: errors.customerSupport,
				valid: valid.customerSupport,
				country,
				requiredFields: requiredFields?.customerSupport,
				handleFieldChange
			}),
			/* @__PURE__ */ jsxs("div", {
				class: "u-display-flex u-margin-top-48",
				children: [/* @__PURE__ */ jsx(Spacer, {}), /* @__PURE__ */ jsx(Button, {
					onClick: submitForm,
					children: t(($) => $["submit"])
				})]
			})
		]
	});
}
//#endregion
export { CustomerSupport };
