"use client"; import { Card, CardContent, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { ColorPicker } from "@/components/ui/color-picker"; import { Separator } from "@/components/ui/separator"; import { Switch } from "@/components/ui/switch"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { BoardData, TrainType } from "@/app/rt-guide/types"; interface MtrBoardFormProps { data: BoardData; setData: (data: BoardData) => void; } export function MtrBoardForm({ data, setData }: MtrBoardFormProps) { const handleStatusBarChange = (field: string, value: string) => { setData({ ...data, statusBar: { ...data.statusBar, [field]: value } }); }; const handleTrainChange = (index: number, field: string, value: any) => { const newTrains = [...data.trains]; const trainToUpdate = { ...newTrains[index] }; if (field === "destination.en" || field === "destination.cn") { const [, subkey] = field.split("."); (trainToUpdate.destination as any)[subkey] = value; } else { (trainToUpdate as any)[field] = value; } newTrains[index] = trainToUpdate; setData({ ...data, trains: newTrains }); }; const handleThemeChange = (field: string, value: any) => { setData({ ...data, theme: { ...data.theme, [field]: value } }); }; const handleLangChange = (checked: boolean) => { setData({ ...data, lang: checked ? "cn" : "en" }); }; return ( Board Configuration Status Bar Train Info Theme {/* Status Bar Tab */}
handleStatusBarChange("temperature", e.target.value) } />
handleStatusBarChange("time", e.target.value)} />
{/* Trains Tab */}
{data.trains.map((train, index) => (
handleTrainChange( index, "destination.en", e.target.value ) } />
handleTrainChange( index, "destination.cn", e.target.value ) } />
handleTrainChange(index, "platform", e.target.value) } />
handleTrainChange(index, "arrival", e.target.value) } />
{index < data.trains.length - 1 && ( )}
))}
{/* Theme Tab */}
handleThemeChange("statusBarColor", value)} /> handleThemeChange("statusBarTextColor", value)} /> handleThemeChange("oddRowColor", value)} /> handleThemeChange("evenRowColor", value)} /> handleThemeChange("textColor", value)} /> handleThemeChange("platformBackgroundColor", value)} /> handleThemeChange("platformTextColor", value)} />
{(Object.keys(data.theme.trainTypeColors) as TrainType[]).map( (type) => ( { const newColors = { ...data.theme.trainTypeColors, [type]: value, }; handleThemeChange("trainTypeColors", newColors); }} /> ) )}
); }