"use client"; import React, { useState, useEffect, useCallback } from "react"; import { DevicePhoneMobileIcon, ExclamationTriangleIcon, ArrowPathIcon, } from "@heroicons/react/24/outline"; import { SimDetailsCard, type SimDetails } from "./SimDetailsCard"; import { DataUsageChart, type SimUsage } from "./DataUsageChart"; import { SimActions } from "./SimActions"; import { authenticatedApi } from "@/lib/api"; import { SimFeatureToggles } from "./SimFeatureToggles"; interface SimManagementSectionProps { subscriptionId: number; } interface SimInfo { details: SimDetails; usage: SimUsage; } export function SimManagementSection({ subscriptionId }: SimManagementSectionProps) { const [simInfo, setSimInfo] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchSimInfo = useCallback(async () => { try { setError(null); const data = await authenticatedApi.get<{ details: SimDetails; usage: SimUsage; }>(`/subscriptions/${subscriptionId}/sim`); setSimInfo(data); } catch (err: unknown) { const hasStatus = (v: unknown): v is { status: number } => typeof v === "object" && v !== null && "status" in v && typeof (v as { status: unknown }).status === "number"; if (hasStatus(err) && err.status === 400) { // Not a SIM subscription - this component shouldn't be shown setError("This subscription is not a SIM service"); } else { setError(err instanceof Error ? err.message : "Failed to load SIM information"); } } finally { setLoading(false); } }, [subscriptionId]); useEffect(() => { void fetchSimInfo(); }, [fetchSimInfo]); const handleRefresh = () => { setLoading(true); void fetchSimInfo(); }; const handleActionSuccess = () => { // Refresh SIM info after any successful action void fetchSimInfo(); }; if (loading) { return (

SIM Management

Loading your SIM service details...

); } if (error) { return (

SIM Management

Unable to load SIM information

Unable to Load SIM Information

{error}

); } if (!simInfo) { return null; } return (
{/* SIM Details and Usage - Main Content */}
{/* Main Content Area - Actions and Settings (Left Side) */}

Modify service options

{/* Sidebar - Compact Info (Right Side) */}
{/* Details + Usage combined card for mobile-first */}
{/* Important Information Card */}

Important Information

  • Data usage is updated in real-time and may take a few minutes to reflect recent activity
  • Top-up data will be available immediately after successful processing
  • SIM cancellation is permanent and cannot be undone
  • {simInfo.details.simType === "esim" && (
  • eSIM profile reissue will provide a new QR code for activation
  • )}
{/* (On desktop, details+usage are above; on mobile they appear first since this section is above actions) */}
); }