import React from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { useTranslation } from 'react-i18next'; import axios from 'axios'; import { Check, Zap, ArrowRight, Layout, Network, Users, LayoutTemplate, Infinity as InfinityIcon } from 'lucide-react'; import Sidebar from '../components/Sidebar'; import { useAuth } from '../context/AuthContext'; import { FREE_LIMITS, PLAN_FREE, PLAN_PLUS, PLUS_PRICE_USD, normalizePlan } from '../config/plans'; const PlanCard = ({ title, price, description, features, highlighted, buttonText, isCurrentPlan, onClick, loading, delay }) => { const { t } = useTranslation(); return ( {highlighted && (
{t('plans.no_limits', 'No limits')}
)}

{title}

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

{description}

{isCurrentPlan ? t('subscription.current_plan', 'Current plan') : loading ? t('subscription.upgrading', 'Switching...') : buttonText} {!isCurrentPlan && !loading && }
); }; const SubscriptionPage = () => { const { t } = useTranslation(); const { user, updateUser } = useAuth(); const [loadingPlan, setLoadingPlan] = React.useState(null); const [notification, setNotification] = React.useState(null); const notify = (type, message) => { setNotification({ type, message }); setTimeout(() => setNotification(null), 4500); }; const handleChangePlan = async (plan) => { if (!user) return; setLoadingPlan(plan); try { const API_URL = import.meta.env.VITE_API_URL; const res = await axios.post(`${API_URL}/payments/change-tier`, { tier: plan }); updateUser(res.data); notify('success', t('plans.switched', { plan, defaultValue: `Your plan is now ${plan}.` })); } catch (err) { if (err.response?.status === 402) { notify('error', t('plans.payments_soon', 'Online payments are not connected yet. Plus will be available soon.')); } else { notify('error', err.response?.data?.message || t('plans.switch_failed', 'Could not change the plan. Please try again.')); } } finally { setLoadingPlan(null); } }; const currentPlan = normalizePlan(user?.subscriptionTier); const plans = [ { key: PLAN_FREE, title: 'Free', price: '0', description: t('plans.free_desc', 'Everything you need to plan on your own.'), buttonText: t('plans.free_btn', 'Switch to Free'), features: [ t('plans.feat_boards', { count: FREE_LIMITS.boards, defaultValue: `Up to ${FREE_LIMITS.boards} boards` }), t('plans.feat_nodes', { count: FREE_LIMITS.nodesPerBoard, defaultValue: `Up to ${FREE_LIMITS.nodesPerBoard} nodes per board` }), t('plans.feat_guests', { count: FREE_LIMITS.guestsPerBoard, defaultValue: `Up to ${FREE_LIMITS.guestsPerBoard} guests per board` }), t('plans.feat_templates', { count: FREE_LIMITS.templates, defaultValue: `${FREE_LIMITS.templates} saved templates` }), t('plans.feat_core', 'All node types, auto-layout, PNG/JSON export'), ], }, { key: PLAN_PLUS, title: 'Plus', price: String(PLUS_PRICE_USD), highlighted: true, description: t('plans.plus_desc', 'For big plans and teams. No caps on anything.'), buttonText: t('plans.plus_btn', 'Get Plus'), features: [ t('plans.feat_unlimited_boards', 'Unlimited boards'), t('plans.feat_unlimited_nodes', 'Unlimited nodes'), t('plans.feat_unlimited_guests', 'Unlimited collaborators'), t('plans.feat_unlimited_templates', 'Unlimited saved templates'), t('plans.feat_everything_free', 'Everything in Free'), ], }, ]; const rows = [ { icon: Layout, label: t('plans.row_boards', 'Boards'), free: FREE_LIMITS.boards }, { icon: Network, label: t('plans.row_nodes', 'Nodes per board'), free: FREE_LIMITS.nodesPerBoard }, { icon: Users, label: t('plans.row_guests', 'Guests per board'), free: FREE_LIMITS.guestsPerBoard }, { icon: LayoutTemplate, label: t('plans.row_templates', 'Saved templates'), free: FREE_LIMITS.templates }, ]; return (
{notification && ( {notification.message} )}

{t('plans.title_p1', 'Two plans. ')} {t('plans.title_highlight', 'No fine print.')}

{t('plans.subtitle', 'Free has small creation limits. Plus has none.')}

{plans.map((plan, i) => ( handleChangePlan(plan.key)} loading={loadingPlan === plan.key} /> ))}
{rows.map((row, i) => ( ))}
{t('subscription.compare.feature', 'Feature')} Free Plus
{row.label} {row.free}
); }; export default SubscriptionPage;