// File: util/DateFormatter.kt
package com.example.notesai.util

import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

object DateFormatter {
    private val shortFormat = SimpleDateFormat("dd MMM, HH:mm", Locale("id", "ID"))
    private val longFormat = SimpleDateFormat("dd MMMM yyyy, HH:mm", Locale("id", "ID"))
    private val timeOnlyFormat = SimpleDateFormat("HH:mm", Locale("id", "ID"))
    private val dateOnlyFormat = SimpleDateFormat("dd MMM yyyy", Locale("id", "ID"))

    fun formatShort(timestamp: Long): String {
        return shortFormat.format(Date(timestamp))
    }

    fun formatLong(timestamp: Long): String {
        return longFormat.format(Date(timestamp))
    }

    fun formatTimeOnly(timestamp: Long): String {
        return timeOnlyFormat.format(Date(timestamp))
    }

    fun formatDateOnly(timestamp: Long): String {
        return dateOnlyFormat.format(Date(timestamp))
    }

    fun formatRelative(timestamp: Long): String {
        val now = System.currentTimeMillis()
        val diff = now - timestamp

        return when {
            diff < 60000 -> "Baru saja"
            diff < 3600000 -> "${diff / 60000} menit yang lalu"
            diff < 86400000 -> "${diff / 3600000} jam yang lalu"
            diff < 604800000 -> "${diff / 86400000} hari yang lalu"
            else -> formatDateOnly(timestamp)
        }
    }
}