import { useState, useEffect } from "react";
import type { EventTypeAppSettingsComponent } from "@calcom/app-store/types";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Alert } from "@calcom/ui/components/alert";
import { Select } from "@calcom/ui/components/form";
import { TextField } from "@calcom/ui/components/form";
import {
currencyOptions,
convertToSmallestCurrencyUnit,
convertFromSmallestToPresentableCurrencyUnit,
} from "../lib/currencyOptions";
import { BTCPayPaymentOptions as paymentOptions } from "../zod";
type Option = { value: string; label: string };
const EventTypeAppSettingsInterface: EventTypeAppSettingsComponent = ({
eventType,
getAppData,
setAppData,
}) => {
const { t } = useLocale();
const price = getAppData("price");
const currency = getAppData("currency") || (currencyOptions.length > 0 ? currencyOptions[0].value : "");
const [selectedCurrency, setSelectedCurrency] = useState(
currencyOptions.find((c) => c.value === currency) ||
(currencyOptions.length > 0
? {
label: currencyOptions[0].label,
value: currencyOptions[0].value,
}
: null)
);
const paymentOption = getAppData("paymentOption");
const paymentOptionSelectValue = paymentOptions?.find((option) => paymentOption === option.value) || {
label: paymentOptions.length > 0 ? paymentOptions[0].label : "",
value: paymentOptions.length > 0 ? paymentOptions[0].value : "",
};
const seatsEnabled = !!eventType.seatsPerTimeSlot;
const [requirePayment, setRequirePayment] = useState(getAppData("enabled"));
const recurringEventDefined = eventType.recurringEvent?.count !== undefined;
// make sure a currency is selected
useEffect(() => {
if (requirePayment && !getAppData("currency")) {
setAppData("currency", currencyOptions[0].value);
}
}, [requirePayment, getAppData, setAppData]);
const disableDecimalPlace = (value: number) => {
return Math.floor(value);
};
return (
<>
{recurringEventDefined ? (