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] = "11fd9342-bb6c-4426-a771-89a81caa27ce", e._sentryDebugIdIdentifier = "sentry-dbid-11fd9342-bb6c-4426-a771-89a81caa27ce");
} catch (e) {}
import { o as createLogger, r as useTranslation } from "./translation-Br5wIPO-.js";
import { n as httpGet, s as useApiContext } from "./http-CHTzpXCd.js";
import { i as drop } from "./AnalyticsContext-C0HNdPss.js";
import { S as isUndefinedOrNull } from "./validatorUtils-Dz6AklT-.js";
import { t as Field } from "./Field-BEqknhTe.js";
import { t as Select } from "./Select-CMFHti4N.js";
import { r as InputBase, t as InputText } from "./InputText-CadVntiC.js";
import { n as isDateOlderThanAYear } from "./utils-Do5CMPEN.js";
import { t as currencyByCountry } from "./types-DjplYXLf.js";
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
import { jsx } from "preact/jsx-runtime";
import { useQuery } from "@tanstack/preact-query";
//#region src/components/Business/forms/FinancialInformation/mapping/mapFinancialInformationToFinancialReport.ts
var mapFinancialInformationToFinancialReport = ({ currency, financialReportingDate, numberOfEmployees, balanceSheetTotal, annualTurnover }, dateOfIncorporation) => {
	if (dateOfIncorporation && !isDateOlderThanAYear(dateOfIncorporation)) return { employeeCount: typeof numberOfEmployees === "number" ? numberOfEmployees.toFixed(0) : numberOfEmployees };
	return {
		currencyOfFinancialData: currency,
		dateOfFinancialData: financialReportingDate,
		employeeCount: typeof numberOfEmployees === "number" ? numberOfEmployees.toFixed(0) : numberOfEmployees,
		balanceSheetTotal: balanceSheetTotal?.toFixed(2) ?? void 0,
		annualTurnover: annualTurnover?.toFixed(2) ?? void 0
	};
};
//#endregion
//#region src/components/Business/forms/FinancialInformation/mapping/mapFinancialReportsToFinancialInformation.ts
var mapFinancialReportsToFinancialInformation = (financialReports, withReportedValueOption = true) => {
	if (financialReports.length === 0) throw new Error("No financial reports");
	const mostRecentReport = financialReports.reduce((latest, curr) => {
		if (curr?.dateOfFinancialData && latest?.dateOfFinancialData && curr?.dateOfFinancialData > latest?.dateOfFinancialData) return curr;
		return latest;
	}, financialReports[0]);
	const financialInfo = {
		numberOfEmployees: mostRecentReport.employeeCount ? parseInt(mostRecentReport.employeeCount) : void 0,
		financialReportingDate: mostRecentReport.dateOfFinancialData,
		currency: mostRecentReport.currencyOfFinancialData
	};
	if (mostRecentReport.balanceSheetTotal !== void 0) {
		financialInfo.reportedValueOption = "balanceSheetTotal";
		financialInfo.balanceSheetTotal = parseFloat(mostRecentReport.balanceSheetTotal);
	}
	if (mostRecentReport.annualTurnover !== void 0) {
		financialInfo.reportedValueOption = "annualTurnover";
		financialInfo.annualTurnover = parseFloat(mostRecentReport.annualTurnover);
	}
	return withReportedValueOption ? financialInfo : drop("reportedValueOption").from(financialInfo);
};
//#endregion
//#region src/api/datasets/useLegalForms.ts
var getLegalForms = async (countryCode, baseUrl) => {
	return httpGet({
		baseUrl,
		path: `datasets/legalForms/${countryCode}`
	});
};
var useLegalForms = (countryCode, options) => {
	const { baseUrl } = useApiContext();
	return useQuery({
		queryKey: ["legalForms", countryCode],
		queryFn: () => getLegalForms(countryCode, baseUrl.value),
		...options
	});
};
//#endregion
//#region src/components/EFP/fields/LegalFormField/LegalFormField.tsx
function LegalFormField({ name = "legalForm", data, valid, errorMessage, label, readonly, handleChangeFor, countryCode }) {
	const { t: commonT } = useTranslation("common");
	const { data: legalFormsData } = useLegalForms(countryCode);
	const handleChangeForRef = useRef(handleChangeFor);
	useEffect(() => {
		handleChangeForRef.current = handleChangeFor;
	}, [handleChangeFor]);
	const handleChangeForLegalForm = useCallback((e) => {
		const legalFormEvent = { target: {
			name: "legalForm",
			value: e.target.value
		} };
		handleChangeFor("legalForm")(legalFormEvent);
	}, [handleChangeFor]);
	useEffect(() => {
		const legalFormEvent = { target: {
			name: "legalFormLabel",
			value: legalFormsData?.find((legalForm) => legalForm.id === data.legalForm)?.name
		} };
		handleChangeForRef.current("legalFormLabel")(legalFormEvent);
	}, [data.legalForm, legalFormsData]);
	return /* @__PURE__ */ jsx(Field, {
		name,
		label: label || commonT(($) => $["businessStructure"]),
		errorMessage,
		isValid: valid.legalForm,
		children: (childProps) => /* @__PURE__ */ jsx(Select, {
			...childProps,
			name,
			placeholder: commonT(($) => $["selectOne"]),
			selected: data.legalForm,
			items: legalFormsData ?? [],
			readonly: readonly && !!data,
			onChange: handleChangeForLegalForm
		})
	});
}
//#endregion
//#region src/components/ui/molecules/InputCurrency/InputCurrency.tsx
var logger = createLogger();
var determineDecimalSeparator = (formatter) => formatter.formatToParts(.1).find((part) => part.type === "decimal").value;
var determineCurrencySymbol = (formatter) => formatter.formatToParts(0).find((part) => part.type === "currency").value;
var getNumberFromFormattedCurrency = (formatted, decimalSeparator) => {
	const lastDecimalIndex = formatted.lastIndexOf(decimalSeparator);
	const normalized = Array.from(formatted).reduce((acc, curr, i) => {
		if (/[0-9]/.test(curr)) return acc + curr;
		if (i === lastDecimalIndex) return `${acc}.`;
		return acc;
	}, "");
	return parseFloat(normalized);
};
var InputCurrency = ({ locale, currency, amount, onAmountChanged, ...baseProps }) => {
	const formatter = useMemo(() => new Intl.NumberFormat(locale, {
		style: "currency",
		currency
	}), [locale, currency]);
	const decimalSeparator = useMemo(() => determineDecimalSeparator(formatter), [formatter]);
	const currencySymbol = useMemo(() => determineCurrencySymbol(formatter), [formatter]);
	const [text, setText] = useState("");
	const onInput = (e) => {
		setText(e.currentTarget.value);
	};
	const onBlur = (e) => {
		const rawValue = e.currentTarget.value;
		const value = getNumberFromFormattedCurrency(rawValue, decimalSeparator);
		if (Number.isNaN(value)) {
			logger.warn(`Unable to get number from formatted currency: "${rawValue}"`);
			setText(isUndefinedOrNull(amount) ? currencySymbol : formatter.format(amount));
			return;
		}
		onAmountChanged(value);
	};
	useEffect(() => {
		setText(isUndefinedOrNull(amount) ? currencySymbol : formatter.format(amount));
	}, [
		amount,
		currencySymbol,
		formatter
	]);
	return /* @__PURE__ */ jsx(InputText, {
		...baseProps,
		value: text,
		onInput,
		onBlur
	});
};
//#endregion
//#region src/components/ui/molecules/InputNumber/InputNumber.tsx
function InputNumber(props) {
	return /* @__PURE__ */ jsx(InputBase, {
		...props,
		type: "number"
	});
}
//#endregion
//#region src/components/Shared/fields/Currency/Currency.tsx
var CURRENCY_FIELD = ["currency"];
function Currency({ data, valid, errors, labels, readonly, handleChangeFor, country }) {
	const { t } = useTranslation("common");
	const currenciesForCurrCountry = currencyByCountry[country];
	const countryCurrenciesItems = currenciesForCurrCountry ? currenciesForCurrCountry.map((currency) => ({
		id: currency,
		name: currency
	})) : [];
	return /* @__PURE__ */ jsx(Field, {
		name: "currency",
		label: labels.currency,
		errorMessage: errors.currency,
		isValid: valid.currency,
		dataTestId: "currency",
		children: (childProps) => /* @__PURE__ */ jsx(Select, {
			...childProps,
			onChange: handleChangeFor("currency", "blur"),
			name: "currency",
			placeholder: t(($) => $["currencyPlaceholder"]),
			selected: data.currency,
			items: countryCurrenciesItems,
			readonly: readonly && !!data.currency
		})
	});
}
//#endregion
export { LegalFormField as a, InputCurrency as i, Currency as n, mapFinancialReportsToFinancialInformation as o, InputNumber as r, mapFinancialInformationToFinancialReport as s, CURRENCY_FIELD as t };
