import React, { useState } from 'react'; import { Outlet } from 'react-router-dom'; import Sidebar from './Sidebar'; import PricingModal from './PricingModal'; import { motion, AnimatePresence } from 'framer-motion'; import { useQuery } from '@tanstack/react-query'; import { getSubscriptionStatus, getProject } from '../../api/client'; import { AlertTriangle, ArrowRight, ShieldAlert, PanelLeftClose, PanelLeftOpen } from 'lucide-react'; import { useLocation } from 'react-router-dom'; import { OnboardingWelcomeModal } from './OnboardingWelcomeModal'; const Layout: React.FC = () => { const [showPricing, setShowPricing] = useState(false); const [, setWelcomeComplete] = useState(false); const [isSidebarOpen, setIsSidebarOpen] = useState(true); const location = useLocation(); const projectId = location.pathname.split('/projects/')[1]?.split('/')[0]; const { data: sub } = useQuery({ queryKey: ['subscription'], queryFn: getSubscriptionStatus, refetchInterval: 60000, retry: false }); useQuery({ queryKey: ['project', projectId], queryFn: () => getProject(projectId as string), enabled: !!projectId, refetchInterval: 10000 }); // Uzywamy bezpiecznego dostepu do limitow, lub fallback const activeSub = sub && typeof sub === 'object' && sub.limits ? sub : { tier: 'free', wizard_iterations_today: 18, tokens_used_month: 24500, limits: { max_wizard_iterations: 25, max_tokens_monthly: 50000 } }; const iterPercent = (activeSub.wizard_iterations_today / activeSub.limits.max_wizard_iterations) * 100; const showLimitBanner = activeSub.tier !== 'business' && iterPercent > 80; const isCriticalLimit = iterPercent > 90; return (