import type { DepartureType } from "@/types/departureType";

import styles from "./style.module.css";

export default function TimetableRow({
    departure,
}: {
    departure: DepartureType;
}) {
    const hour = String(departure.dateTime.hour).padStart(2, "0");
    const minute = String(departure.dateTime.minute).padStart(2, "0");
    const dateTimeString = `${hour}:${minute}`;
    const lineNumber = departure.servingLine.number;

    return (
        <tr className={styles.timetableRow}>
            <td className={styles.departureTime}>{dateTimeString}</td>
            <td
                className={`${lineNumberToStyle(lineNumber)} ${styles.lineNumber}`}
            >
                {lineNumber}
            </td>
            <td>{departure.servingLine.direction}</td>
        </tr>
    );
}

const lineNumberToStyle = (number) => {
    switch (number) {
        case "S2":
            return styles.S2;
            break;
        case "S5":
        case "S51":
            return styles.S5;
            break;
        case "S1":
        case "S11":
            return styles.S1;
            break;
        default:
            return styles.lineNumberDefault;
    }
};
