import React, { useState } from 'react';
import { BILLING_CYCLES, Plan } from '../../types';
import PricingTable from '../core/PricingTable';
import ToggleButton from '../ui/ToggleButton';
import useBillingPlans from '@/billing-ui/hooks/useBillingPlans';
import { useBillingContext } from '@/billing-ui/context/BillingContext';
import CloseIcon from '../../assets/images/icons/close.svg';
import Image from 'next/image';
interface BillingModalProps {
onSelectPlan: (plan: Plan | null) => void;
onContactUs: () => void;
onTrial: (planCode: string) => void;
onClose: () => void;
}
const BillingModal: React.FC<BillingModalProps> = ({ onSelectPlan, onContactUs, onTrial, onClose }) => {
const { userToken } = useBillingContext();
const [isMonthly, setIsMonthly] = useState(true);
const { plans } = useBillingPlans(
String(userToken),
isMonthly ? BILLING_CYCLES.MONTHLY : BILLING_CYCLES.YEARLY
);
const handleToggle = (cycle: string) => {
setIsMonthly(cycle === BILLING_CYCLES.MONTHLY);
};
return (
<div className="fixed inset-0 flex items-center justify-center bg-black bg-opacity-20 backdrop-blur-xl z-50 py-7">
<div className="relative flex flex-col items-center bg-white rounded-3xl shadow-lg p-8">
<button onClick={onClose} className="absolute top-3 right-3" aria-label="Close modal">
<Image src={CloseIcon} alt="Close" width={24} height={24} />
</button>
<div className="flex flex-col items-center mb-6">
<h2 className="text-center font-extrabold text-textPrimary text-2xl mt-2">Choose your Plan</h2>
<p className="text-center text-textTertiary mt-2 text-sm">
Select from the best plan, ensuring a perfect match. Need more or less? Customize your
subscription for a seamless fit!
</p>
<ToggleButton
cycles={[BILLING_CYCLES.MONTHLY, BILLING_CYCLES.YEARLY]}
onToggle={handleToggle}
activeCycle={isMonthly ? BILLING_CYCLES.MONTHLY : BILLING_CYCLES.YEARLY}
/>
</div>
<PricingTable onSubscribe={onSelectPlan} onContactUs={onContactUs} onTrial={onTrial} plans={plans} />
</div>
</div>
);
};
export default BillingModal;