package com.tt.honeyDue.ui.utils

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector

/**
 * Helper function to convert icon name string to ImageVector
 */
fun getIconFromName(iconName: String): ImageVector {
    return when (iconName) {
        "CalendarToday" -> Icons.Default.CalendarToday
        "PlayCircle" -> Icons.Default.PlayCircle
        "PlayArrow" -> Icons.Default.PlayArrow
        "CheckCircle" -> Icons.Default.CheckCircle
        "Archive" -> Icons.Default.Archive
        "List" -> Icons.AutoMirrored.Filled.List
        "Unarchive" -> Icons.Default.Unarchive
        else -> Icons.AutoMirrored.Filled.List // Default fallback
    }
}

/**
 * Helper function to convert hex color string to Color
 * Supports formats: #RGB, #RRGGBB, #AARRGGBB
 * Platform-independent implementation
 */
fun hexToColor(hex: String): Color {
    val cleanHex = hex.removePrefix("#")
    return try {
        when (cleanHex.length) {
            3 -> {
                // RGB format - expand to RRGGBB
                val r = cleanHex[0].toString().repeat(2).toInt(16)
                val g = cleanHex[1].toString().repeat(2).toInt(16)
                val b = cleanHex[2].toString().repeat(2).toInt(16)
                Color(red = r / 255f, green = g / 255f, blue = b / 255f)
            }
            6 -> {
                // RRGGBB format
                val r = cleanHex.substring(0, 2).toInt(16)
                val g = cleanHex.substring(2, 4).toInt(16)
                val b = cleanHex.substring(4, 6).toInt(16)
                Color(red = r / 255f, green = g / 255f, blue = b / 255f)
            }
            8 -> {
                // AARRGGBB format
                val a = cleanHex.substring(0, 2).toInt(16)
                val r = cleanHex.substring(2, 4).toInt(16)
                val g = cleanHex.substring(4, 6).toInt(16)
                val b = cleanHex.substring(6, 8).toInt(16)
                Color(red = r / 255f, green = g / 255f, blue = b / 255f, alpha = a / 255f)
            }
            else -> Color.Gray // Default fallback
        }
    } catch (e: Exception) {
        Color.Gray // Fallback on parse error
    }
}
