import { TenantTypeEnums } from "../../enums/unitySystemEnums.mjs";
import { UdpAutocomplete } from "../../UI/fluent-web-components/UdpAutocomplete.mjs";
import { c } from "react-compiler-runtime";
import React from "react";
//#region src/utilities/tenant/UdpTenantSelect.tsx
const sortByName = (list) => [...list].sort((a, b) => a.tenantName.toLowerCase().localeCompare(b.tenantName.toLowerCase()));
const UdpTenantSelect = (t0) => {
	const $ = c(12);
	const { tenants, value, onTenantChange, label: t1 } = t0;
	const label = t1 === void 0 ? "Current Tenant" : t1;
	let t2;
	bb0: {
		if (!tenants) {
			let t3;
			if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
				t3 = [];
				$[0] = t3;
			} else t3 = $[0];
			t2 = t3;
			break bb0;
		}
		if (!(tenants.some(_temp) && tenants.some(_temp2))) {
			let t3;
			if ($[1] !== tenants) {
				t3 = sortByName(tenants);
				$[1] = tenants;
				$[2] = t3;
			} else t3 = $[2];
			t2 = t3;
			break bb0;
		}
		let t3;
		if ($[3] !== tenants) {
			t3 = [...sortByName(tenants.filter(_temp3)), ...sortByName(tenants.filter(_temp4))];
			$[3] = tenants;
			$[4] = t3;
		} else t3 = $[4];
		t2 = t3;
	}
	const options = t2;
	let t3;
	if ($[5] !== onTenantChange) {
		t3 = (e) => {
			if (e.target.value) onTenantChange?.(e.target.value);
		};
		$[5] = onTenantChange;
		$[6] = t3;
	} else t3 = $[6];
	const handleChange = t3;
	const t4 = value ?? void 0;
	let t5;
	if ($[7] !== handleChange || $[8] !== label || $[9] !== options || $[10] !== t4) {
		t5 = /* @__PURE__ */ React.createElement(UdpAutocomplete, {
			value: t4,
			options,
			optionLabel: _temp5,
			optionValue: "tenantId",
			label,
			includeErrorPadding: false,
			onChange: handleChange
		});
		$[7] = handleChange;
		$[8] = label;
		$[9] = options;
		$[10] = t4;
		$[11] = t5;
	} else t5 = $[11];
	return t5;
};
function _temp(t_0) {
	return t_0.tenantType === TenantTypeEnums.Tenant;
}
function _temp2(t) {
	return t.tenantType === TenantTypeEnums.Product;
}
function _temp3(t_1) {
	return t_1.tenantType === TenantTypeEnums.Tenant;
}
function _temp4(t_2) {
	return t_2.tenantType === TenantTypeEnums.Product;
}
function _temp5(option) {
	return option?.tenantName ?? "";
}
//#endregion
export { UdpTenantSelect };

//# sourceMappingURL=UdpTenantSelect.mjs.map