import { PaymentTenderTypeEnum } from "../../../enums/paymentTenderTypeEnum.mjs";
import { PaymentCardDetail } from "./PaymentCardDetail.mjs";
import { PaymentBankDetails } from "./PaymentBankDetails.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { FormControl, InputLabel, MenuItem, Select, makeStyles } from "@material-ui/core";
import { useTranslation } from "react-i18next";
//#region src/utilities/form/paymentForm/PaymentDropdown.tsx
const useStyles = makeStyles(() => ({ select: {
	background: "#F5F6F9",
	paddingTop: 2,
	paddingBottom: 0,
	paddingLeft: 0
} }));
/**
* PaymentDropdown component renders a dropdown menu for selecting a payment account.
* It supports both credit card and bank account payment types.
*
* @component
* @param {PaymentDropdownProps} props - The properties for the PaymentDropdown component.
* @param {Array} props.paymentAccounts - An array of payment accounts to display in the dropdown.
* @param {Function} props.setSelectedPaymentAccount - A function to set the selected payment account.
* @param {PaymentTenderTypeEnum} props.paymentType - The type of payment (CreditCard or BankAccount).
*
* @returns {JSX.Element} The rendered PaymentDropdown component.
*/
const PaymentDropdown = (t0) => {
	const $ = c(29);
	const { paymentAccounts, setSelectedPaymentAccount, paymentType } = t0;
	const [selectedPaymentCard, setSelectedPaymentCard] = useState(paymentAccounts?.[0]?.paymentTokenID || "");
	const classes = useStyles();
	const { t } = useTranslation();
	let t1;
	if ($[0] !== paymentType) {
		t1 = (card) => {
			switch (paymentType) {
				case PaymentTenderTypeEnum.CreditCard: return /* @__PURE__ */ React.createElement(PaymentCardDetail, { cardData: card });
				case PaymentTenderTypeEnum.ECheck: return /* @__PURE__ */ React.createElement(PaymentBankDetails, { bankData: card });
				default: return null;
			}
		};
		$[0] = paymentType;
		$[1] = t1;
	} else t1 = $[1];
	const renderMenuItemContent = t1;
	let t2;
	if ($[2] !== paymentAccounts || $[3] !== setSelectedPaymentAccount) {
		t2 = (event) => {
			const selectedPaymentAccount = paymentAccounts.find((account) => account.paymentTokenID === event.target.value);
			setSelectedPaymentCard(event.target.value);
			setSelectedPaymentAccount?.(selectedPaymentAccount);
		};
		$[2] = paymentAccounts;
		$[3] = setSelectedPaymentAccount;
		$[4] = t2;
	} else t2 = $[4];
	const handleChange = t2;
	let t3;
	if ($[5] !== paymentAccounts || $[6] !== renderMenuItemContent) {
		t3 = paymentAccounts?.map((card_0) => /* @__PURE__ */ React.createElement(MenuItem, {
			key: card_0.paymentTokenID,
			value: card_0.paymentTokenID,
			style: { padding: 0 }
		}, renderMenuItemContent(card_0)));
		$[5] = paymentAccounts;
		$[6] = renderMenuItemContent;
		$[7] = t3;
	} else t3 = $[7];
	const menuItems = t3;
	let t4;
	let t5;
	if ($[8] !== paymentAccounts || $[9] !== setSelectedPaymentAccount) {
		t4 = () => {
			const defaultPaymentAccount = paymentAccounts.find((account_0) => account_0.paymentTokenID === paymentAccounts?.[0]?.paymentTokenID);
			setSelectedPaymentAccount?.(defaultPaymentAccount);
		};
		t5 = [paymentAccounts, setSelectedPaymentAccount];
		$[8] = paymentAccounts;
		$[9] = setSelectedPaymentAccount;
		$[10] = t4;
		$[11] = t5;
	} else {
		t4 = $[10];
		t5 = $[11];
	}
	useEffect(t4, t5);
	let t6;
	if ($[12] !== t) {
		t6 = t("Select Payment Account");
		$[12] = t;
		$[13] = t6;
	} else t6 = $[13];
	let t7;
	if ($[14] !== t6) {
		t7 = /* @__PURE__ */ React.createElement(InputLabel, { id: "payment-select-label" }, t6);
		$[14] = t6;
		$[15] = t7;
	} else t7 = $[15];
	let t8;
	if ($[16] !== t) {
		t8 = t("Select Payment Account");
		$[16] = t;
		$[17] = t8;
	} else t8 = $[17];
	let t9;
	if ($[18] !== classes.select) {
		t9 = { root: classes.select };
		$[18] = classes.select;
		$[19] = t9;
	} else t9 = $[19];
	let t10;
	if ($[20] !== handleChange || $[21] !== menuItems || $[22] !== selectedPaymentCard || $[23] !== t8 || $[24] !== t9) {
		t10 = /* @__PURE__ */ React.createElement(Select, {
			labelId: "payment-select-label",
			label: t8,
			onChange: handleChange,
			value: selectedPaymentCard,
			classes: t9
		}, menuItems);
		$[20] = handleChange;
		$[21] = menuItems;
		$[22] = selectedPaymentCard;
		$[23] = t8;
		$[24] = t9;
		$[25] = t10;
	} else t10 = $[25];
	let t11;
	if ($[26] !== t10 || $[27] !== t7) {
		t11 = /* @__PURE__ */ React.createElement(FormControl, {
			fullWidth: true,
			variant: "outlined"
		}, t7, t10);
		$[26] = t10;
		$[27] = t7;
		$[28] = t11;
	} else t11 = $[28];
	return t11;
};
//#endregion
export { PaymentDropdown as default };

//# sourceMappingURL=PaymentDropdown.mjs.map