import { TenantTypeEnums } from "../../enums/unitySystemEnums.mjs";
import { c } from "react-compiler-runtime";
import React, { forwardRef } from "react";
import { TextField } from "@material-ui/core";
import { Autocomplete } from "@material-ui/lab";
//#region src/utilities/tenant/TenantSelect.tsx
const sanitizeRecordId = (tenantName) => tenantName.replace(/\s+/g, "");
const TenantSelect = forwardRef((props, ref) => {
	const $ = c(27);
	const { tenants, value, onTenantChange, id: t0, label: t1, className, disableClearable: t2, textFieldProps, recordIdPrefix: t3 } = props;
	const id = t0 === void 0 ? "tenant-select" : t0;
	const label = t1 === void 0 ? "Current Tenant" : t1;
	const disableClearable = t2 === void 0 ? true : t2;
	const recordIdPrefix = t3 === void 0 ? "udpRecord-TenantSelect" : t3;
	let t4;
	if ($[0] !== tenants) {
		t4 = tenants.some(_temp) && tenants.some(_temp2);
		$[0] = tenants;
		$[1] = t4;
	} else t4 = $[1];
	const userTenantsContainsMultipleTypes = t4;
	const sortTenantsByNameAlphacetically = _temp4;
	let t5;
	if ($[2] !== userTenantsContainsMultipleTypes) {
		t5 = (tenants_1) => {
			if (!userTenantsContainsMultipleTypes) {
				sortTenantsByNameAlphacetically(tenants_1);
				return tenants_1;
			}
			const clientTenants = tenants_1.filter(_temp5);
			sortTenantsByNameAlphacetically(clientTenants);
			const productTenants = tenants_1.filter(_temp6);
			sortTenantsByNameAlphacetically(productTenants);
			return clientTenants.concat(productTenants);
		};
		$[2] = userTenantsContainsMultipleTypes;
		$[3] = t5;
	} else t5 = $[3];
	const groupTenantsByTypeAndFilter = t5;
	let t6;
	if ($[4] !== groupTenantsByTypeAndFilter || $[5] !== tenants) {
		t6 = tenants ? groupTenantsByTypeAndFilter(tenants) : [];
		$[4] = groupTenantsByTypeAndFilter;
		$[5] = tenants;
		$[6] = t6;
	} else t6 = $[6];
	const options = t6;
	let t7;
	if ($[7] !== onTenantChange) {
		t7 = (event, newValue, reason) => {
			if (reason !== "select-option" || !newValue) return;
			onTenantChange?.(newValue);
		};
		$[7] = onTenantChange;
		$[8] = t7;
	} else t7 = $[8];
	const handleChange = t7;
	let t8;
	if ($[9] !== userTenantsContainsMultipleTypes) {
		t8 = (option_1) => userTenantsContainsMultipleTypes ? option_1.tenantType === TenantTypeEnums.Product ? "Product" : "Client" : null;
		$[9] = userTenantsContainsMultipleTypes;
		$[10] = t8;
	} else t8 = $[10];
	let t9;
	if ($[11] !== label || $[12] !== textFieldProps) {
		t9 = (params) => /* @__PURE__ */ React.createElement(TextField, {
			...params,
			label,
			variant: "standard",
			...textFieldProps
		});
		$[11] = label;
		$[12] = textFieldProps;
		$[13] = t9;
	} else t9 = $[13];
	let t10;
	if ($[14] !== recordIdPrefix) {
		t10 = (option_2) => /* @__PURE__ */ React.createElement("li", {
			style: {
				width: "100%",
				height: "100%",
				listStyleType: "none"
			},
			udprecordid: `${recordIdPrefix}-${sanitizeRecordId(option_2?.tenantName ?? "")}`
		}, option_2?.tenantName ?? "");
		$[14] = recordIdPrefix;
		$[15] = t10;
	} else t10 = $[15];
	let t11;
	if ($[16] !== className || $[17] !== disableClearable || $[18] !== handleChange || $[19] !== id || $[20] !== options || $[21] !== ref || $[22] !== t10 || $[23] !== t8 || $[24] !== t9 || $[25] !== value) {
		t11 = /* @__PURE__ */ React.createElement(Autocomplete, {
			ref,
			className,
			id,
			value,
			options,
			disableClearable,
			getOptionSelected: _temp7,
			getOptionLabel: _temp8,
			onChange: handleChange,
			groupBy: t8,
			renderInput: t9,
			renderOption: t10
		});
		$[16] = className;
		$[17] = disableClearable;
		$[18] = handleChange;
		$[19] = id;
		$[20] = options;
		$[21] = ref;
		$[22] = t10;
		$[23] = t8;
		$[24] = t9;
		$[25] = value;
		$[26] = t11;
	} else t11 = $[26];
	return t11;
});
TenantSelect.displayName = "TenantSelect";
function _temp(tenant_0) {
	return tenant_0.tenantType == TenantTypeEnums.Tenant;
}
function _temp2(tenant) {
	return tenant.tenantType == TenantTypeEnums.Product;
}
function _temp3(tenant_1, otherTenant) {
	if (tenant_1.tenantName.toLowerCase() < otherTenant.tenantName.toLowerCase()) return -1;
	else if (tenant_1.tenantName.toLowerCase() > otherTenant.tenantName.toLowerCase()) return 1;
	else return 0;
}
function _temp4(tenants_0) {
	tenants_0.sort(_temp3);
}
function _temp5(tenant_2) {
	return tenant_2.tenantType == TenantTypeEnums.Tenant;
}
function _temp6(tenant_3) {
	return tenant_3.tenantType == TenantTypeEnums.Product;
}
function _temp7(option, selected) {
	return option?.tenantId === selected?.tenantId;
}
function _temp8(option_0) {
	return option_0?.tenantName ?? "";
}
//#endregion
export { TenantSelect };

//# sourceMappingURL=TenantSelect.mjs.map