// components/templates/TemplateDetails.tsx
import React from 'react';
import { View, ScrollView } from 'react-native';
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
import { Text } from '@/components/ui/text';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Separator } from '@/components/ui/separator';
import { Sheet, SheetContent, SheetHeader, SheetTitle } from '@/components/ui/sheet';
import {
Edit2,
Dumbbell,
Target,
Calendar,
Hash,
ClipboardList,
Settings
} from 'lucide-react-native';
import {
WorkoutTemplate,
TemplateSource,
getSourceDisplay
} from '@/types/templates';
import { useTheme } from '@react-navigation/native';
import type { CustomTheme } from '@/lib/theme';
const Tab = createMaterialTopTabNavigator();
interface TemplateDetailsProps {
template: WorkoutTemplate;
open: boolean;
onOpenChange: (open: boolean) => void;
onEdit?: () => void;
}
// Overview Tab Component
function OverviewTab({ template, onEdit }: { template: WorkoutTemplate; onEdit?: () => void }) {
const {
title,
type,
category,
description,
exercises = [],
tags = [],
metadata,
availability // Replace source with availability
} = template;
// Calculate source type from availability
const sourceType = availability.source.includes('nostr')
? 'nostr'
: availability.source.includes('powr')
? 'powr'
: 'local';
return (
{/* Basic Info Section */}
{getSourceDisplay(template)}
{type}
{/* Category Section */}
Category
{category}
{/* Description Section */}
{description && (
Description
{description}
)}
{/* Exercises Section */}
Exercises
{exercises.map((exerciseConfig, index) => (
{exerciseConfig.exercise.title}
{exerciseConfig.targetSets} sets × {exerciseConfig.targetReps} reps
{exerciseConfig.notes && (
{exerciseConfig.notes}
)}
))}
{/* Tags Section */}
{tags.length > 0 && (
Tags
{tags.map(tag => (
{tag}
))}
)}
{/* Usage Stats Section */}
{metadata && (
Usage
{metadata.useCount && (
Used {metadata.useCount} times
)}
{metadata.lastUsed && (
Last used: {new Date(metadata.lastUsed).toLocaleDateString()}
)}
{metadata.averageDuration && (
Average duration: {Math.round(metadata.averageDuration / 60)} minutes
)}
)}
{/* Edit Button */}
{onEdit && (
)}
);
}
// Function to format template source for display
function formatTemplateSource(source: TemplateSource | undefined, templateSource: 'local' | 'powr' | 'nostr'): string {
if (!source) {
return templateSource === 'local' ? 'Local Template' : templateSource.toUpperCase();
}
const author = source.authorName || 'Unknown Author';
if (source.version) {
return `Modified from ${author} (v${source.version})`;
}
return `Original by ${author}`;
}
// History Tab Component
function HistoryTab({ template }: { template: WorkoutTemplate }) {
return (
{/* Performance Stats */}
Performance Summary
Avg. Duration
{template.metadata?.averageDuration
? `${Math.round(template.metadata.averageDuration / 60)}m`
: '--'}
Completion Rate
--
{/* History List */}
Recent Workouts
{/* Placeholder for when no history exists */}
No workout history available yet
);
}
// Settings Tab Component
function SettingsTab({ template }: { template: WorkoutTemplate }) {
const {
type,
rounds,
duration,
interval,
restBetweenRounds,
} = template;
return (
{/* Workout Configuration */}
Workout Settings
Type
{type}
{rounds && (
Rounds
{rounds}
)}
{duration && (
Duration
{Math.floor(duration / 60)}:{(duration % 60).toString().padStart(2, '0')}
)}
{interval && (
Interval
{Math.floor(interval / 60)}:{(interval % 60).toString().padStart(2, '0')}
)}
{restBetweenRounds && (
Rest Between Rounds
{Math.floor(restBetweenRounds / 60)}:{(restBetweenRounds % 60).toString().padStart(2, '0')}
)}
);
}
export function TemplateDetails({
template,
open,
onOpenChange,
onEdit
}: TemplateDetailsProps) {
const theme = useTheme() as CustomTheme;
return (
onOpenChange(false)}>
{template.title}
{() => }
{() => }
{() => }
);
}