"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 { SimActions } from "./SimActions"; import { apiClient } from "@/lib/api"; import { SimFeatureToggles } from "./SimFeatureToggles"; interface SimManagementSectionProps { subscriptionId: number; } interface SimInfo { details: SimDetails; } 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 response = await apiClient.GET("/api/subscriptions/{id}/sim", { params: { path: { id: subscriptionId } }, }); const payload = response.data as { details: SimDetails; usage: any } | undefined; if (!payload) { throw new Error("Failed to load SIM information"); } // Only use the details part, ignore usage data setSimInfo({ details: payload.details }); } 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 (
{/* Header Section */}

{simInfo.details.simType === "esim" ? "eSIM" : "Physical SIM"} Service

Subscription ID {subscriptionId}

{simInfo.details.status.charAt(0).toUpperCase() + simInfo.details.status.slice(1)}
{/* Two Column Layout */}
{/* Left Column - Main Actions */}
{/* Subscription Details Card */}

Subscription Details

Monthly Cost

¥3,100

Next Billing

Jul 1, 2024

Registration

Aug 2, 2023

{/* SIM Management Actions Card */}

SIM Management Actions

{/* Voice Status Card */}

Voice Status

{/* Right Column - SIM Details & Usage */}
{/* SIM Details Card */}

SIM Details

); }