diff --git a/src/components/admin/editors/CoasterStatsEditor.tsx b/src/components/admin/editors/CoasterStatsEditor.tsx new file mode 100644 index 00000000..d1c4ccae --- /dev/null +++ b/src/components/admin/editors/CoasterStatsEditor.tsx @@ -0,0 +1,193 @@ +import { Plus, Trash2 } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Textarea } from "@/components/ui/textarea"; +import { Card } from "@/components/ui/card"; + +interface CoasterStat { + stat_name: string; + stat_value: number; + unit?: string; + category?: string; + description?: string; + display_order: number; +} + +interface CoasterStatsEditorProps { + stats: CoasterStat[]; + onChange: (stats: CoasterStat[]) => void; + categories?: string[]; +} + +const DEFAULT_CATEGORIES = ['Speed', 'Height', 'Length', 'Forces', 'Capacity', 'Duration', 'Other']; +const COMMON_STATS = [ + { name: 'Max Speed', unit: 'km/h', category: 'Speed' }, + { name: 'Max Height', unit: 'm', category: 'Height' }, + { name: 'Drop Height', unit: 'm', category: 'Height' }, + { name: 'Track Length', unit: 'm', category: 'Length' }, + { name: 'Max G-Force', unit: 'G', category: 'Forces' }, + { name: 'Max Negative G-Force', unit: 'G', category: 'Forces' }, + { name: 'Ride Duration', unit: 'seconds', category: 'Duration' }, + { name: 'Inversions', unit: 'count', category: 'Other' }, +]; + +export function CoasterStatsEditor({ + stats, + onChange, + categories = DEFAULT_CATEGORIES +}: CoasterStatsEditorProps) { + + const addStat = () => { + onChange([ + ...stats, + { + stat_name: '', + stat_value: 0, + unit: '', + category: categories[0], + description: '', + display_order: stats.length + } + ]); + }; + + const addCommonStat = (commonStat: typeof COMMON_STATS[0]) => { + onChange([ + ...stats, + { + stat_name: commonStat.name, + stat_value: 0, + unit: commonStat.unit, + category: commonStat.category, + description: '', + display_order: stats.length + } + ]); + }; + + const removeStat = (index: number) => { + const newStats = stats.filter((_, i) => i !== index); + onChange(newStats.map((stat, i) => ({ ...stat, display_order: i }))); + }; + + const updateStat = (index: number, field: keyof CoasterStat, value: any) => { + const newStats = [...stats]; + newStats[index] = { ...newStats[index], [field]: value }; + onChange(newStats); + }; + + return ( +
+
+ +
+ + +
+
+ + {stats.length === 0 ? ( + + No statistics added yet. Add a common stat or create a custom one. + + ) : ( +
+ {stats.map((stat, index) => ( + +
+
+ + updateStat(index, 'stat_name', e.target.value)} + placeholder="e.g., Max Speed" + /> +
+ +
+
+ + updateStat(index, 'stat_value', parseFloat(e.target.value) || 0)} + placeholder="0" + /> +
+
+ + updateStat(index, 'unit', e.target.value)} + placeholder="km/h, m, G..." + /> +
+
+ +
+ + +
+ +
+ +
+ +
+ +