import React, { useState } from 'react'; import { CheckCircle } from 'lucide-react'; import { Pagination } from '../common/Pagination'; import type { UserProfile, ModuleItem } from '../../types'; interface SubscriptionsViewProps { loggedInUser: UserProfile | null; onOpenAuth: (mode: 'login') => void; onSwitchTab: (tab: 'storefront') => void; curriculumModules: ModuleItem[]; } export const SubscriptionsView: React.FC = ({ loggedInUser, onOpenAuth, onSwitchTab, curriculumModules, }) => { const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(6); const subscriptions = loggedInUser?.active_subscriptions || []; const totalCount = subscriptions.length; const startIndex = (currentPage - 1) * pageSize; const paginatedSubscriptions = subscriptions.slice(startIndex, startIndex + pageSize); return (
Entitlements Ledger

My Active Subscriptions

Track your active learning passes, their validity periods, and remaining countdowns. All active subscriptions synchronize automatically inside the Acupedia iOS/Android mobile apps.

{/* Subscriptions ledger grid */} {!loggedInUser ? (

Please register or log in to view active entitlements.

) : subscriptions.length === 0 ? (

No active subscriptions

You do not currently possess any active course passes. Visit the Storefront catalog to unlock TCM learning modules.

) : (
{paginatedSubscriptions.map((sub: any) => { // Find module metadata matching sub.plan_code const moduleMeta = curriculumModules.find((m) => m.code === sub.plan_code); // Calculate days left let daysLeft = 0; const hasExpiry = !!sub.expires_at; if (hasExpiry) { const expiry = new Date(sub.expires_at); const now = new Date(); const diffTime = expiry.getTime() - now.getTime(); daysLeft = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); } return (
ACTIVE {sub.plan_code === 'LIFETIME_ALL' ? ( 👑 10 Years Pass ) : ( 1 Year Pass )}

{moduleMeta ? moduleMeta.name : sub.plan_code.replace(/_/g, ' ').toUpperCase()}

{moduleMeta ? moduleMeta.desc : 'Unlocked subscription access to module contents.'}

Activated: {sub.started_at ? new Date(sub.started_at).toLocaleDateString(undefined, { dateStyle: 'medium' }) : 'N/A'}
Expires: {hasExpiry ? new Date(sub.expires_at).toLocaleDateString(undefined, { dateStyle: 'medium' }) : 'Lifetime'}
Validity Remaining: {!hasExpiry ? ( Lifetime Access ) : sub.plan_code === 'LIFETIME_ALL' ? ( {daysLeft > 0 ? `${(daysLeft / 365).toFixed(1)} Years Left` : 'Expired'} ) : ( {daysLeft > 0 ? `${daysLeft} Days Left` : 'Expired'} )}
); })}
{/* Pagination Controls */} {totalCount > 6 && (
{ setPageSize(size); setCurrentPage(1); }} pageSizeOptions={[6, 12, 24]} />
)}
)}
); };