import { useTranslation } from "react-i18next";

export const minutesToHoursMinutes = (minutes: number): string => {
    const { t } = useTranslation("common");
    const defaultHrStr = "hr"
    const defaultMinStr = "min"

    if (minutes == 0) {
        return `0 ${defaultMinStr}`
    }

    const hrs = Math.floor(minutes / 60)
    const mins = minutes % 60

    let finalHrStr: string = ""
    if (hrs > 1) {
        finalHrStr = `${hrs} ` + t(`${defaultHrStr}s`)
    } else if (hrs == 1) {
        finalHrStr = `1 ` + t(`${defaultHrStr}`)
    }

    let finalMinStr: string = ""
    if (mins > 1) {
        finalMinStr = `${mins} ` + t(`${defaultMinStr}s`)
    } else if (mins == 1) {
        finalMinStr = `1 ` + t(`${defaultMinStr}`)
    }

    const colon = finalHrStr.length > 0 && finalMinStr.length > 0 ? ":" : ""

    return `${finalHrStr} ${colon} ${finalMinStr}`.trim()
}