import { useEffect } from "react"; import { useNavigate, useParams } from "react-router-dom"; import * as LucideIcons from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import { ArrowLeft, BookOpen, Clock, Check, Tag, CalendarDays, } from "lucide-react"; import { useClientTiers } from "@/contexts/ClientTiersProvider"; import { useProfile } from "@/contexts/ProfileProvider"; import { PageMeta } from "@/contexts/MetadataContext"; import { useDateFormat } from "@/hooks/useDateFormat"; import { resolveTierBadge } from "@/utils/tierBadge.util"; import { getTierColor } from "@/utils/tierColors"; // ─── Helpers ────────────────────────────────────────────────────────────────── const UNIT_TO_DAYS = { minute: 1 / 1440, hour: 1 / 24, day: 1, month: 30, year: 365 }; function formatDuration(days, unit) { if (!days) return null; const multiplier = UNIT_TO_DAYS[unit] ?? 1; const value = Math.round((days / multiplier) * 1000) / 1000; const label = unit ?? "day"; return `${value} ${label}${value !== 1 ? "s" : ""}`; } function formatCourseDuration(seconds = 0) { if (!seconds) return null; const h = Math.floor(seconds / 3600); const m = Math.floor((seconds % 3600) / 60); if (h && m) return `${h}h ${m}m`; if (h) return `${h}h`; return `${m}m`; } // ─── Skeleton ───────────────────────────────────────────────────────────────── const ViewPlanSkeleton = () => (
{plan.description || `Everything you need with the ${tierLabel} plan.`}
What's included
{value}
{label}
{course.title}
Courses coming soon
We're curating the best content for this plan. Subscribe now and get instant access the moment they go live.
{plan.is_active ? "Ready to get started?" : "Coming Soon"}
{plan.is_active ? (plan.description || `Everything you need with the ${tierLabel} plan.`) : "This plan is not available for purchase at the moment. Check back later."}