import React from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { useTranslation } from 'react-i18next'; import Sidebar from '../components/Sidebar'; import { useAuth } from '../context/AuthContext'; import axios from 'axios'; import { Sparkles, Check, X, Zap, ArrowRight, Bot, Layout, Heart, Users, BookTemplate } from 'lucide-react'; const PricingCard = ({ type, price, description, features, popular, color, buttonText, isCurrentPlan, onClick, loading }) => { const { t } = useTranslation(); return ( {popular && (
{t("subscription.most_recommended")}
)}

{type}

$ {price} {t("subscription.per_month")}

{description}

{isCurrentPlan ? t("subscription.current_plan", "Current Plan") : loading ? t("subscription.upgrading", "Upgrading...") : buttonText} {!isCurrentPlan && !loading && }
); }; const SubscriptionPage = () => { const { t } = useTranslation(); const { user, updateUser } = useAuth(); const [loadingTier, setLoadingTier] = React.useState(null); const [notification, setNotification] = React.useState(null); const handleUpgrade = async (tierName) => { if (!user) return; setLoadingTier(tierName); try { const API_URL = import.meta.env.VITE_API_URL; const res = await axios.post(`${API_URL}/payments/change-tier/${user.id}`, { tier: tierName }); updateUser(res.data); setNotification({ type: 'success', message: t('subscription.upgrade_success', { tier: tierName }) || `Plan switched to ${tierName} successfully!` }); setTimeout(() => setNotification(null), 4000); } catch (err) { console.error('[Subscription] Upgrade failed:', err); setNotification({ type: 'error', message: err.response?.data?.message || 'Upgrade failed. Please try again.' }); setTimeout(() => setNotification(null), 4000); } finally { setLoadingTier(null); } }; const plans = [ { key: "Free", type: t("subscription.plans.free.title"), price: "0", description: t("subscription.plans.free.desc"), buttonText: t("subscription.plans.free.btn"), features: [ { text: t("subscription.plans.free.feat1"), included: true }, { text: t("subscription.plans.free.feat2"), included: true }, { text: t("subscription.plans.free.feat3"), included: true }, { text: t("subscription.plans.free.feat4"), included: true }, { text: t("subscription.plans.free.feat5"), included: true }, ] }, { key: "Pro", type: t("subscription.plans.pro.title"), price: "10", popular: true, description: t("subscription.plans.pro.desc"), buttonText: t("subscription.plans.pro.btn"), features: [ { text: t("subscription.plans.pro.feat1"), included: true }, { text: t("subscription.plans.pro.feat2"), included: true }, { text: t("subscription.plans.pro.feat3"), included: true }, { text: t("subscription.plans.pro.feat4"), included: true }, { text: t("subscription.plans.pro.feat5"), included: true }, ] }, { key: "Ultra", type: t("subscription.plans.ultra.title"), price: "25", description: t("subscription.plans.ultra.desc"), buttonText: t("subscription.plans.ultra.btn"), features: [ { text: t("subscription.plans.ultra.feat1"), included: true }, { text: t("subscription.plans.ultra.feat2"), included: true }, { text: t("subscription.plans.ultra.feat3"), included: true }, { text: t("subscription.plans.ultra.feat4"), included: true }, { text: t("subscription.plans.ultra.feat5"), included: true }, { text: t("subscription.plans.ultra.feat6"), included: true }, ] } ]; const currentUserTier = user?.subscriptionTier || "Free"; return (
{/* Notification Banner */} {notification && ( {notification.message} )} {/* Background Elements */}

{t("subscription.title_p1", "Unlock the ")} {t("subscription.title_highlight", "Pro Tools")} {t("subscription.title_p2", " of TaskFlow")}

{t("subscription.subtitle")}

{plans.map((plan, i) => ( handleUpgrade(plan.key)} loading={loadingTier === plan.key} /> ))}
{[ { icon: Bot, label: t('subscription.compare.ai_gens', 'AI Generations / day'), free: '3', pro: '200', ultra: '∞' }, { icon: Layout, label: t('subscription.compare.canvases', 'Canvases'), free: '3', pro: '∞', ultra: '∞' }, { icon: Sparkles, label: t('subscription.compare.nodes', 'Nodes per canvas'), free: '200', pro: '∞', ultra: '∞' }, { icon: Heart, label: t('subscription.compare.habits', 'Habits'), free: '3', pro: '∞', ultra: '∞' }, { icon: Users, label: t('subscription.compare.board_members', 'Board members'), free: '2', pro: '10', ultra: '∞' }, { icon: BookTemplate, label: t('subscription.compare.custom_templates', 'Custom Templates'), free: false, pro: false, ultra: true }, ].map((row, i) => ( {[row.free, row.pro, row.ultra].map((val, j) => ( ))} ))}
{t('subscription.compare.feature', 'Feature')} {t('subscription.plans.free.title', 'Free')} {t('subscription.plans.pro.title', 'Pro')} {t('subscription.plans.ultra.title', 'Ultra')}
{row.label} {val === true ? ( ) : val === false ? ( ) : ( {val} )}
); }; export default SubscriptionPage;